简体   繁体   English

C#中如何将Intptr转换为ImageSharp Image?

[英]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) 中,利用图像的widthheightstride ,我们可以将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.BitmapLinux上不再可用,我们必须使用SixLabors.ImageSharp.Image How do I convert an Intptr to an image using ImageSharp ?如何使用ImageSharpIntptr转换为图像?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM