转换位图图像格式的字符串超过网络(LAN),反之亦然发 [英] Convert Bitmap image to String format to send over network(LAN) and vice-versa
问题描述
我基本上开发Visual Studio 2010中.NET 4.0软件在那里我从PC捕捉屏幕截图,并把它通过网络到另一个。
既然不能直接发送一个位图,我已经把它转换为字符串。
我做了很多的互联网搜索,但找不到任何解决方案。 (
我发现计算器本身这个代码
但是它不工作,我试图打印(从影像转换)的字符串,但该程序的行为。这样的线犯规存在
我用了一个MessageBox.Show(字符串)。!?!
,而不是连味精框弹出
任何人都可以请帮我卡
Thankx提前:)(Y)
bitmapString = NULL; //转换从图像串
的MemoryStream MemoryStream的=新的MemoryStream();
bmpScreenshot.Save(MemoryStream的,ImageFormat.Png);
字节[] = bitmapBytes memoryStream.GetBuffer();
bitmapString = Convert.ToBase64String(bitmapBytes,Base64FormattingOptions.InsertLineBreaks); //转换,从形象到字符串末尾
图片IMG = NULL; //从字符串转换到图像
字节[] = bitmapBytes Convert.FromBase64String(抢);
的MemoryStream MemoryStream的=新的MemoryStream(bitmapBytes);
IMG = Image.FromStream(MemoryStream的); //从字符串转换到图像结束
尝试转换它为一个字节数组:
公共静态的byte [] ImageToByteArray(图像IMG)
{
字节[]的字节数组=新的字节[0];
使用(MemoryStream的流=新的MemoryStream())
{
img.Save(流System.Drawing.Imaging.ImageFormat.Png);
stream.Close();
的字节数组= stream.ToArray();
}
返回的字节数组;
}
我相信你可以简单地把一个位图对象的Image对象。因此,图像IMG =(图)MYBITMAP;
- 然后传递到上述方法
I am basically developing a software in Visual Studio 2010 .NET 4.0 where in I capture the screenshot from a pc and send it over a network to another. Since I cannot directly send a Bitmap, I have to convert it to String. I did a lot of internet search but cant find any solution. :(
I found this code on stackoverflow itself. But it it doesnt work. I tried to print the string (converted from image) but the program behaves like that line doesnt exist. I used a MessageBox.Show(String); But not even a msg box pops up! Can anyone please help? I'm stuck! Thankx in advance :) (Y)
bitmapString = null; // Conversion from image to string
MemoryStream memoryStream = new MemoryStream();
bmpScreenshot.Save(memoryStream, ImageFormat.Png);
byte[] bitmapBytes = memoryStream.GetBuffer();
bitmapString = Convert.ToBase64String(bitmapBytes,Base64FormattingOptions.InsertLineBreaks); // Conversion from image to string end
Image img = null; //Conversion from string to image
byte[] bitmapBytes = Convert.FromBase64String(rob);
MemoryStream memoryStream = new MemoryStream(bitmapBytes);
img = Image.FromStream(memoryStream); //Conversion from string to image end
Try to convert it to a byte array:
public static byte[] ImageToByteArray(Image img)
{
byte[] byteArray = new byte[0];
using (MemoryStream stream = new MemoryStream())
{
img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
stream.Close();
byteArray = stream.ToArray();
}
return byteArray;
}
I believe you can simply cast a Bitmap object to an Image object. So Image img = (Image)myBitmap;
- then pass that into the method above.
这篇关于转换位图图像格式的字符串超过网络(LAN),反之亦然发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!