C# picturebox显示不出来图像

charles27823349 2009-09-29 09:49:54
byte[] inum = new byte[32];
revSocket.Receive(inum);
int aa = BitConverter.ToInt32(inum, 0);
byte[] ib = new byte[aa];
revSocket.Receive(ib);
MemoryStream ms = new MemoryStream(ib);
Image image = Image.FromStream(ms);
//image.Save(@"c:\aa\j.gif", ImageFormat.Gif);

pictureBox1.Image = image;
没有显示,form底下一片白,程序能正常运行,如果用save保存下来可以打开,换成别的格式也不行
...全文
1333 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
CHN_smallfox 2009-09-29
  • 打赏
  • 举报
回复
这样可以,接收端代码

int rcv;
byte[] msgsize = new byte[4];
rcv = socket.Receive(msgsize, 0, 4, SocketFlags.None);
int size = BitConverter.ToInt32(msgsize, 0);

byte[] file = new byte[10000000];
int longer = file.Length;
int start = 0;
int mid = 0;
int count = socket.Receive(file, start, longer, SocketFlags.None);
mid += count;
longer -= mid;
while (count != 0)
{
count = socket.Receive(file, mid, longer, SocketFlags.None);
mid += count;
longer -= mid;
}
MemoryStream ms = new MemoryStream(file, 0, size, true);
pictureBox1.Image = Image.FromStream(ms);
ms.Close();
socket.Close();
zhangguofang1129 2009-09-29
  • 打赏
  • 举报
回复
顶一下
charles27823349 2009-09-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 chansmile 的回复:]
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
[/Quote]
加上了也没用啊
SimpleM 2009-09-29
  • 打赏
  • 举报
回复
学习~!
南山五味子 2009-09-29
  • 打赏
  • 举报
回复
pictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
xuenzhen123 2009-09-29
  • 打赏
  • 举报
回复

//Byte[] result;

System.IO.MemoryStream ms =new MemoryStream(result, 0, result.Length)
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());

//或者添加一个处理图片的Handler,内容如下:
<%@ WebHandler Language="C#" Class="Handler" %>

using System.Web;
using System.IO;


public class Handler : IHttpHandler {

public void ProcessRequest (HttpContext context) {

int CategoryID = int.Parse(context.Request.QueryString["CategoryID"]);
//调用Categories.GetPicture取得图片stream
Stream stream = CategoriesPicture.GetPicture(CategoryID);

if (stream !=null) {
//取得图片stream大小
int buffersize = (int)stream.Length;
//建立buffer
System.Byte[] buffer = new System.Byte[buffersize ] ;
//调用stream.Read,从stream读取到buffer,并返回count
int count = stream.Read(buffer, 0, buffersize);
//返回图片字段buffer
if (count!=0)
context.Response.OutputStream.Write(buffer, 0, count);
}

}

public bool IsReusable {
get {
return false;
}
}

}
twilightgod 2009-09-29
  • 打赏
  • 举报
回复
刷新的问题?写在重绘里看看?
Hywin1020 2009-09-29
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 dylike 的回复:]
据说C#中要 \\ 路径
[/Quote]
前面有@了……
charles27823349 2009-09-29
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 dylike 的回复:]
据说C#中要 \\ 路径
[/Quote]
没听懂您说的意思
dylike 2009-09-29
  • 打赏
  • 举报
回复
据说C#中要 \\ 路径
charles27823349 2009-09-29
  • 打赏
  • 举报
回复
顶一下

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧