DerMike
DerMike

Reputation: 16200

Create IntPtr for specified image data

(I'm not even sure how to ask this in an correct way, sorry. My image processing skills are basically non existent.)

I have a function in a library (namely bool CLNUIDevice.GetCameraColorFrameRGB32(...) from CL.NUI to read Kinect data) that I have to pass an IntPtr data as an argument. The resulting image data will end up in this data.

I want to do some image processing with that data and display it on screen (in a PictureBox, I guess).

When I pass a variable set to IntPtr.Zero it stays 0. As I understand it, I have to initialize the data correctly. My image is 640x480 pixels and judging from the examples it should have PixelFormat.Format32bppPArgb

How do I have to initialize the IntPtr for a 640x480 pixel bitmap that seems to have 32 bits per pixel?

Upvotes: 2

Views: 1900

Answers (3)

Hans Passant
Hans Passant

Reputation: 942237

        var bmp = new Bitmap(640, 480, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
        System.Drawing.Imaging.BitmapData bd = null;
        try {
            bd = bmp.LockBits(new Rectangle(Point.Empty, bmp.Size), System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);
            var pointer = bd.Scan0;
            // Make the call, passing *pointer*
            //...
        }
        finally {
            if (bd != null) bmp.UnlockBits(bd);
        }
        // Do something with <bmp>
        //...

Upvotes: 1

Brandon Moretz
Brandon Moretz

Reputation: 7641

Create a new Bitmap object, using your width/height/bpp and the image data pointer passed in through the constructor.

You can then display that bitmap anyway you choose.

Upvotes: 1

Glory Raj
Glory Raj

Reputation: 17701

I am hoping this link will helps you Using WritePixels when using a writeable bitmap from a intptr to create a bitmap

you can change this depends upon your requirement...

Upvotes: 0

Related Questions