I wrote this code
我写了这段代码
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Now I want to check ms text. How can I do that?
现在我要查看ms文本。我怎样才能做到这一点?
3 个解决方案
#1
1
With this code, you can encode the image Bytes into an hexadecimal string representation:
使用此代码,您可以将图像字节编码为十六进制字符串表示形式:
Byte[] a = ms.ToArray();
String text = BitConverter.ToString(a);
#2
0
You can try with this code....
您可以尝试使用此代码....
var url = HostingEnvironment.MapPath("~/Images/" + name);
byte[] myByte = System.IO.File.ReadAllBytes(url);
using (MemoryStream ms = new MemoryStream())
{
ms.Write(myByte, 0, myByte.Length);
i = System.Drawing.Image.FromStream(ms);
System.Drawing.Image imageIn = i.GetThumbnailImage(100, 100,()=> false, IntPtr.Zero);
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
var storedUrl = "data:image;base64," + Convert.ToBase64String(ms.ToArray());
return storedUrl;
}
#3
0
I use this to send the image as string:
我用它来将图像作为字符串发送:
string path = @"C:\Users\user6\Pictures\wp\tinypotato.jpg";
string myString = Convert.ToBase64String(File.ReadAllBytes(path))
Debug.WriteLine(myString);
...
BR!
BR!
#1
1
With this code, you can encode the image Bytes into an hexadecimal string representation:
使用此代码,您可以将图像字节编码为十六进制字符串表示形式:
Byte[] a = ms.ToArray();
String text = BitConverter.ToString(a);
#2
0
You can try with this code....
您可以尝试使用此代码....
var url = HostingEnvironment.MapPath("~/Images/" + name);
byte[] myByte = System.IO.File.ReadAllBytes(url);
using (MemoryStream ms = new MemoryStream())
{
ms.Write(myByte, 0, myByte.Length);
i = System.Drawing.Image.FromStream(ms);
System.Drawing.Image imageIn = i.GetThumbnailImage(100, 100,()=> false, IntPtr.Zero);
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
var storedUrl = "data:image;base64," + Convert.ToBase64String(ms.ToArray());
return storedUrl;
}
#3
0
I use this to send the image as string:
我用它来将图像作为字符串发送:
string path = @"C:\Users\user6\Pictures\wp\tinypotato.jpg";
string myString = Convert.ToBase64String(File.ReadAllBytes(path))
Debug.WriteLine(myString);
...
BR!
BR!