如何从图形对象创建位图对象吗? [英] How to create Bitmap object from a Graphics object?
问题描述
如何从图形对象创建位图对象吗?我想读我的Graphics对象像素。例如,像,System.Drawing.BitMap.GetPixel()。
How to create Bitmap object from a Graphics object ? I would like to read pixels from my Graphics object. for example, like, System.Drawing.BitMap.GetPixel().
我试图找出空白区域(全白,或任何颜色的),PDF文档里面,写一些图形/图像。我已经试过这样,但它不工作。为什么以下code不能按预期工作?
I am trying to find out empty area (all white, or of any colour) inside a pdf document, to write some graphics / image. I have tried like this, but it is not working. why the following code is not working as expected ?
//
// System.Drawing.Bitmap
// System.Drawing.Graphics
//
Bitmap b = new Bitmap(width, height, graphics);
//
// In this case, for any (i, j) values, Bitmap.GetPixel returns 0
//
int rgb = b.GetPixel(i, j).ToArgb();
(在.NET中,只有背景下再次发布了这个问题,删除其他库的依赖)
( posting this question again in .net-only context, removing other library dependencies )
推荐答案
(很晚了,但是......)
(very late, but...)
您是否尝试过
var bmp = System.Drawing.Bitmap.FromHbitmap(gr.GetHdc());
然后你可以阅读 BMP
像素。
这篇关于如何从图形对象创建位图对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!