CSharp examples for System.Drawing:Image Operation
Set Pixels to Bitmap
using System.Drawing.Imaging; using System.Drawing; using System.Collections; using System;/*from ww w. j a va2 s. c om*/ public class Main{ public static unsafe void SetPixels(Bitmap bmp, int[,] pixels) { BitmapData bmpData=bmp.LockBits(new Rectangle(0,0,bmp.Width,bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); System.IntPtr Scan0 = bmpData.Scan0; byte* scan0=(byte*)(void*)Scan0; int* ptr = (int*)scan0; int strideDiff = bmpData.Stride - bmp.Width*4; // TODO: bytesPerPixel for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { *ptr = pixels[x,y]; ptr++; } ptr+=strideDiff; } bmp.UnlockBits(bmpData); } }