一个二维整型数组代表着位图,每个数组元素表示一个像素,如何把它映射到一个picturebox 或者 bitmap 中去。
(不调用setpixel 和 getpixel 函数 这样太慢了).
或者有什么方法直接调用 bitmap 中的每个象素(不调用setpixel 和 getpixel )
(不调用setpixel 和 getpixel 函数 这样太慢了).
或者有什么方法直接调用 bitmap 中的每个象素(不调用setpixel 和 getpixel )
public Bitmap(
int width,
int height,
int stride,
PixelFormat format,
IntPtr scan0
);something like the following:http://groups.google.com/groups?q=bitmap+C%23++PixelFormat+Intptr+unsafe&hl=en&lr=&ie=UTF-8&selm=c51001c20dba%2417822b00%2439ef2ecf%40TKMSFTNGXA08&rnum=6
>>>有什么方法直接调用 bitmap 中的每个象素2.
look into Accessing the Bitmap Data Directly
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncscol/html/csharp11152001.aspin both cases, you might need to work under unsafe mode
Subject: Color array to Bitmap
This is the only article in this thread
View: Original Format
Newsgroups: microsoft.public.dotnet.framework.windowsforms
Date: 2002-06-06 17:28:12 PST
Greetings. I'm creating largish Color[,] arrays and
converting to a Bitmap for display. To work with the
ptr Bitmap constructor I end up copying the Color[,]
array to an Int32[] array. Is there a way to avoid the copy (or a better way
to do this? [note: array height/width reversed from
bitmap's height/width] Code below (C#)... Thanks, -Yamo-int width = 1024;
int height = 1024;
int bytesPerPixel = 4;
Color[,] colorBuf = new Color[height, width];// add colors to array hereInt32 [] cbuf = new Int32[height * width];
for (int i = 0; i < height; i++)
for (int j = 0; j < width; j++)
cbuf[i*width+j] = colorBuf[i,j].ToArgb();Bitmap mybitmap;
unsafe
{
fixed(void *p = cbuf)
{
IntPtr ptr = new IntPtr(p);
mybitmap = new Bitmap(width, height,
bytesPerPixel * width,
PixelFormat.Format32bppRgb,
ptr);
}
}