本文介绍了DrawToBitmap()由指定的矩形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个面板,我可以通过使用方法panel.DrawToBitmap()将其所有表面复制/捕获到位图但我只想将该面板上的指定矩形复制/捕获到位图,你能不能请给我一些解决方案来实现这个目标吗?



我们非常感谢您的帮助!

谢谢!

I have a panel, I can copy/capture all its surface to a bitmap by using the method panel.DrawToBitmap() but I just want to copy/capture only a specified rectangle on that panel to a bitmap, could you please give me some solution to achieve this?

Your help would be highly appreciated!
Thanks!

推荐答案

Bitmap bp=new Bitmap(dataGridView1.Width,dataGridView1.Height);
dataGridView1.DrawToBitmap(bp,new Rectangle(0,0,dataGridView1.Width,dataGridView1.Height));
Bitmap bp1 = bp.Clone(new Rectangle(50, 50, 100, 100),  System.Drawing.Imaging.PixelFormat.DontCare);
 bp1.Save("test2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);



在第二个位图中传递的矩形线将裁剪出所需大小的完整图像,并且只需要裁剪部分。


the cords of rectangle passed in second bitmap will crop the complete image to ur required size and u will have only cropped portion u needed.


这篇关于DrawToBitmap()由指定的矩形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 16:42