panel1.DrawToBitmap 截取panel 下半部分图片的问题

u012193498 2013-12-03 10:49:55
如题:

这是取得整个Panel1的内容 :
Bitmap memoryImageSamSung;
panel1.DrawToBitmap(memoryImageSamSung, new Rectangle(0,0, panel1.Width, panel1.Height));



我用:
panel1.DrawToBitmap(memoryImageSamSung, new Rectangle(0,0, panel1.Width, panel1.Height/2));
总得得到的是panel1 上面的那一部分内容!!!!!

请问,如何截取panel 下半部分内容呢?
...全文
568 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyr987503101 2013-12-15
  • 打赏
  • 举报
回复
Bitmap bit = new Bitmap(plPMT.Width, plPMT.Height);//实例化一个和窗体一样大的bitmap Graphics g = Graphics.FromImage(bit); g.CompositingQuality = CompositingQuality.HighQuality;//质量设为最高 //g.CopyFromScreen(this.Left ,this.Top,0,0,new Size(this.Width,this.Height));//保存全部窗体为图片 g.CopyFromScreen(plPMT.PointToScreen(System.Drawing.Point.Empty), System.Drawing.Point.Empty, plPMT.Size);//只保存某个控件(这里是panel游戏区) bit.Save(@"f:\bbb.jpg");//默认保存格局为PNG,保存成jpg格局质量不是很好 我测试通过了,无论是是panel的背景图片还是自己在panel里绘制的图形都可以截图保存下来!
智商余额不足 2013-12-03
  • 打赏
  • 举报
回复
引用 14 楼 u012193498 的回复:
智商余额不足/分不够用啊 你们的代码可以通过, 为啥我的代码就不行呢!!!
DrawToBitmap 第二个参数是目标区域表示的矩形,上面的都搞错了(当作源矩形了)
智商余额不足 2013-12-03
  • 打赏
  • 举报
回复
方法很多的,你仔细调试下就知道原因出在哪里了~
智商余额不足 2013-12-03
  • 打赏
  • 举报
回复
方法三

Bitmap newBitmap = new Bitmap(panel1.Width, panel1.Height);
panel1.DrawToBitmap(newBitmap, panel1.ClientRectangle);
Bitmap halfBitmap = new Bitmap(newBitmap.Width, newBitmap.Height >> 1);
Graphics g = Graphics.FromImage(halfBitmap);
g.DrawImage(newBitmap, 0, -halfBitmap.Height);
g.Dispose();
halfBitmap.Save("d:\\2222.png", System.Drawing.Imaging.ImageFormat.Png);
halfBitmap.Dispose();
u012193498 2013-12-03
  • 打赏
  • 举报
回复
智商余额不足/分不够用啊 你们的代码可以通过, 为啥我的代码就不行呢!!!
智商余额不足 2013-12-03
  • 打赏
  • 举报
回复
方法二:

Bitmap newBitmap = new Bitmap(panel1.Width, panel1.Height);
panel1.DrawToBitmap(newBitmap,panel1.ClientRectangle);
Bitmap halfBitmap = newBitmap.Clone(new Rectangle(0,newBitmap.Height>>1,newBitmap.Width,newBitmap.Height>>1),newBitmap.PixelFormat);
newBitmap.Dispose();
halfBitmap.Save("d:\\2222.png", System.Drawing.Imaging.ImageFormat.Png);
halfBitmap.Dispose();
bu_ge 2013-12-03
  • 打赏
  • 举报
回复

memoryImageSamSung = new Bitmap(panel1.Width, panel1.Height);
panel1.DrawToBitmap(memoryImageSamSung, new Rectangle(0, 0, this.Width, this.Height));

Bitmap newBitmap = new Bitmap(panel1.Width, panel1.Height);
Graphics mygraphics = Graphics.FromImage(newBitmap);

Rectangle rectangle = new Rectangle(0, this.panel1.Height / 2, panel1.Width, panel1.Height / 2);
Rectangle newRectangle = new Rectangle(0, 0, panel1.Width, panel1.Height);

mygraphics.DrawImage(memoryImageSamSung, newRectangle, rectangle, GraphicsUnit.Pixel);

newBitmap.Save(@"f:\aaa.jpg");
智商余额不足 2013-12-03
  • 打赏
  • 举报
回复
方法一

private void button1_Click(object sender, EventArgs e)
{
     Bitmap newBitmap = new Bitmap(panel1.Width, panel1.Height / 2);
     Graphics g = Graphics.FromImage(newBitmap);
     Point src = PointToScreen(new Point(panel1.Location.X, panel1.Location.Y + panel1.Height / 2));
     Point dest = new Point(0, 0);
     g.CopyFromScreen(src, dest, new Size(newBitmap.Width, newBitmap.Height), CopyPixelOperation.SourceCopy);
     g.Dispose();
     newBitmap.Save("d:\\2222.png", System.Drawing.Imaging.ImageFormat.Png);
     newBitmap.Dispose();
}
u012193498 2013-12-03
  • 打赏
  • 举报
回复
大哥们,急解!!!
u012193498 2013-12-03
  • 打赏
  • 举报
回复
楼上的仍旧 不成, 我的代码很简单的一测试: Graphics mygraphics = panel1.CreateGraphics();//创建的是整个panel Size s = panel1.Size;//取panel大小 memoryImageSamSung = new Bitmap(s.Width, s.Height); panel1.DrawToBitmap(memoryImageSamSung, new Rectangle(0, 150 这个地方设置啥数都没有作用, panel1.Width, panel1.Height / 2)); memoryImageSamSung.Save("f:\\aaa.jpg");
feiyun0112 2013-12-03
  • 打赏
  • 举报
回复
Rectangle sourceRect = panel1.ClientRectangle;
Size targetSize = new Size(memoryImageSamSung.Width, memoryImageSamSung.Height);
using (Bitmap tmp = new Bitmap(sourceRect.Width, sourceRect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
panel1.DrawToBitmap(tmp, sourceRect);
using (Graphics g = Graphics.FromImage(memoryImageSamSung))
{
g.DrawImage(tmp, 0,0, new Rectangle(0, panel1.Height / 2, panel1.Width, panel1.Height / 2), GraphicsUnit.Pixel);
}
}
智商余额不足 2013-12-03
  • 打赏
  • 举报
回复
那就发你相对完整点的代码上来
u012193498 2013-12-03
  • 打赏
  • 举报
回复
lable7 以下的部分,怎么取,都取不着呀,!!!! 要不,我给代码你们试试看看!!!
u012193498 2013-12-03
  • 打赏
  • 举报
回复
每次取得都是 lable6 以上的部分!!!
智商余额不足 2013-12-03
  • 打赏
  • 举报
回复
怎么不可以呢,楼主再仔细测试下代码
u012193498 2013-12-03
  • 打赏
  • 举报
回复

以下代码仍旧是只能取得上半部分!!!
panel1.DrawToBitmap(memoryImageSamSung, new Rectangle(0,panel1.Height/2, panel1.Width, panel1.Height/2));
u012193498 2013-12-03
  • 打赏
  • 举报
回复
请楼上试试,根本就不行,总是上部分内容!!
feiyun0112 2013-12-03
  • 打赏
  • 举报
回复
panel1.DrawToBitmap(memoryImageSamSung, new Rectangle(0,panel1.Height/2, panel1.Width, panel1.Height/2));


*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/

110,545

社区成员

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

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

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