C# 将位图转换为 FFmediaToolkits ImageData
C# Convert Bitmap to FFmediaToolkits ImageData
我有标准 System.Drawing.Bitmap
,我需要将其转换为 FFMediaToolkit.Graphics.ImageData
。我怎样才能做到这一点?
我试过了:
ImageData.FromArray((byte[]) converter.ConvertTo(frame, typeof(byte[])),
ImagePixelFormat.Argb32, frame.Width,frame.Height)
但它确实给了我这个错误:
Unhandled exception. System.ArgumentException: Pixel buffer size doesn't match size required by this image format.
感谢您的帮助
解决方法是:
private static ImageData FrameToImageData(Bitmap bitmap)
{
Rectangle rect = new Rectangle(System.Drawing.Point.Empty, bitmap.Size);
BitmapData bitLock = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
ImageData bitmapImageData = ImageData.FromPointer(bitLock.Scan0, ImagePixelFormat.Bgr24, bitmap.Size);
bitmap.UnlockBits(bitLock);
return bitmapImageData;
}
我有标准 System.Drawing.Bitmap
,我需要将其转换为 FFMediaToolkit.Graphics.ImageData
。我怎样才能做到这一点?
我试过了:
ImageData.FromArray((byte[]) converter.ConvertTo(frame, typeof(byte[])),
ImagePixelFormat.Argb32, frame.Width,frame.Height)
但它确实给了我这个错误:
Unhandled exception. System.ArgumentException: Pixel buffer size doesn't match size required by this image format.
感谢您的帮助
解决方法是:
private static ImageData FrameToImageData(Bitmap bitmap)
{
Rectangle rect = new Rectangle(System.Drawing.Point.Empty, bitmap.Size);
BitmapData bitLock = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
ImageData bitmapImageData = ImageData.FromPointer(bitLock.Scan0, ImagePixelFormat.Bgr24, bitmap.Size);
bitmap.UnlockBits(bitLock);
return bitmapImageData;
}