用pictureBox显示图片的问题?!

nice000 2011-06-17 10:23:51
我想用pictureBox显示图片,为什么图片显示不出来呢?下面是我的程序,
...全文
150 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
nice000 2011-06-17
  • 打赏
  • 举报
回复
如何设置图片显示时的宽高呢?我也想设置啊
libo0952 2011-06-17
  • 打赏
  • 举报
回复
为 什么 你一按去 计算 图片的大小捏。 你 设置一下 图片显示时的 宽高 就行
tmd456 2011-06-17
  • 打赏
  • 举报
回复
//g.Dispose();
注释掉这一行
ghost5216 2011-06-17
  • 打赏
  • 举报
回复

private Bitmap ZoomPicture(Bitmap bmp, int newWidth, int newHight)
{

Bitmap b = new Bitmap(newWidth, newHight, System.Drawing.Imaging.PixelFormat.Format16bppRgb565);
Graphics g = this.CreateGraphics();
g.DrawImage(bmp, new Rectangle(0, 0, newWidth, newHight), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);

g.Dispose();
return b;
}

b自始至终没有用到它 return b有什么意思
nice000 2011-06-17
  • 打赏
  • 举报
回复
“return bmp;” ?不对。是不是这句this.pictureBox1.Image = ZoomPicture(Myimage, (int)(PicWidth / ZoomW), (int)(PicHeight / ZoomH));不对呢,是不是pictureBox不能这么用?之前发现图片闪一角就没了是把 pictureBox1.Visible =false;,改成 pictureBox1.Visible =true;后直接就是全黑了,一点东西都没,好像pictureBox把东西全盖住了一样
ghost5216 2011-06-17
  • 打赏
  • 举报
回复
return bmp;
nice000 2011-06-17
  • 打赏
  • 举报
回复
我的pictureBox就是240*320的啊,应该没错啊
nice000 2011-06-17
  • 打赏
  • 举报
回复
什么意思呢?计算错误是怎么说?
  • 打赏
  • 举报
回复
跟一下,图片的高度、宽度、显示位置,估计是计算错误了。
nice000 2011-06-17
  • 打赏
  • 举报
回复
运行的时候只能闪出图片的一角然后就没了
nice000 2011-06-17
  • 打赏
  • 举报
回复

//显示获取的图片
private void ShowImage(int index)
{
if (picList.Count > 0)
{

Bitmap Myimage = new Bitmap(picList[index].ToString());
//取得图片信息
int PicHeight = Myimage.Height;
int PicWidth = Myimage.Width;

//计算图片缩放比例

double ZoomH = ((Double)PicHeight) / ((Double)320);
double ZoomW = ((Double)PicWidth) / ((Double)240);

this.pictureBox1.Image = ZoomPicture(Myimage, (int)(PicWidth / ZoomW), (int)(PicHeight / ZoomH));

}
else
{
DialogResult result;
result = MessageBox.Show("没有图片", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (result == DialogResult.OK||result==DialogResult.Cancel)
{
this.Close();
}

}
}
private Bitmap ZoomPicture(Bitmap bmp, int newWidth, int newHight)
{

Bitmap b = new Bitmap(newWidth, newHight, System.Drawing.Imaging.PixelFormat.Format16bppRgb565);
Graphics g = this.CreateGraphics();
g.DrawImage(bmp, new Rectangle(0, 0, newWidth, newHight), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);

g.Dispose();
return b;
}

JadeDaydayup 2011-06-17
  • 打赏
  • 举报
回复
程序何在?

110,533

社区成员

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

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

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