c# - RGB 24 to BitMap Resulting in Black Image -


I can not wrap my brain around the images and byte [] one Raw RGB colors in Bitmap . I found a solution that enables me to use a code in RGB 24 BPP byte [] in the bitmap to setPixel , but I I've read that lockbits is very fast, so I'm trying to explain how to do it. Using the SetPixel method, I am getting an inverted image: Create a Public Static BitmapBitcom 24BPRGB (Byte [] BMPData, Int width, intensity height) {var BMP = new bitmap (width, height, pixel format.form 24 bpRGB); Var pos = 0; For (var y = 0; y & lt; height; y ++) {for (var x = 0; x

I do not understand this how to reverse it. But when I try to use LockBits , the image is black only, and I'm sure what I am doing, it comes quite straight forward. Public static bitmap CreateBitmap24bppRgb (byte [] data, integer width, height of intensity) {var bmp = new bitmap (width, height, pixel format.form 24bpprbb); // Create a bitmap data and write to launch all the pixels var bmpData = bmp.LockBits (new rectangle (0, 0, BMP wide, BMP.), Image lock mode.WitoneLolly, BMP pixel format); Scan the data with bitmap data from the // byte array. For scan (int y = 0; y and lt; bmp; hete-1; y ++) {Marshal.Copy (data, Y * BMP with, BMPDITA scan BMPData.); } // unlock the pixel BMP. Unlockbits (BMPDT); Return BMP; }

I'm just curious what's going wrong here?

If you are creating a new bitmap instead of modifying an existing bit, then There is no reason to use LockBits or Marshal.Copy .

Go with the bus. Public static bitmap CreateBitmap24bppRgb (byte [] data, integer width, height of intensity) {GCHandle pin = GCHandle.Alloc (data, GCHandleType.Pinned); Var BMP = new bitmap (width, height, (width * 3 + 3) / 4 * 4, pixel format. Format 24 bpRGB, martial. Unified fore piaanurereelment (data, 0)); BMP = (bitmap) BMP. Clone (); // Resolve the requirement so that the memory address becomes valid / clone phase can also change the crop and / or pixel format, if desired GCandDale Free (pin); Return BMP; }

(or unsecured block, pinned keyword and use an indicator)

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -