1

In c# (Windows), with the width, height and stride of an image, we can convert an Intptr to Bitmap as follows:

var bitmap = new Bitmap(width, height, stride, PixelFormat.Format24bppRgb, intptrImage);

But System.Drawing.Bitmap is no longer available on Linux and we have to use SixLabors.ImageSharp.Image. How do I convert an Intptr to an image using ImageSharp?

1 Answers1

1

I found this solution:

// copy data to byte array
var size = height * stride;
var managedArray = new byte[size];
Marshal.Copy(intptrImage, managedArray, 0, size);

var image = SixLabors.ImageSharp.Image.LoadPixelData<Bgr24>(managedArray,width, height);

This solution works fine.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 18 '22 at 11:41