[英]How to convert Intptr to ImageSharp Image in C#?
In c# (Windows), with the width
, height
and stride
of an image, we can convert an Intptr
to Bitmap
as follows:在 c# (Windows) 中,利用图像的
width
、 height
和stride
,我们可以将Intptr
转换为Bitmap
,如下所示:
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
.但是
System.Drawing.Bitmap
在Linux
上不再可用,我们必须使用SixLabors.ImageSharp.Image
。 How do I convert an Intptr
to an image using ImageSharp
?如何使用
ImageSharp
将Intptr
转换为图像?
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.该解决方案工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.