调用 IWICComponentFactory.CreateBitmapFromMemory 时出现 WINCODEC_ERR_WIN32ERROR 0x88982F94

发布于 2024-12-15 05:55:09 字数 1579 浏览 3 评论 0原文

Scan0 的指针时,我收到以下错误

WINCODEC_ERR_WIN32ERROR
0x88982F94
Windows Codecs received an error from the Win32 system.

当调用 IWICComponentFactory.CreateBitmapFromMemory 并将其传递给 32bppArgb GDI+ 位图IWICComponentFactory 接口 decl 的

    new IWICBitmap CreateBitmapFromMemory(
        uint uiWidth,
        uint uiHeight,
        [MarshalAs(UnmanagedType.LPStruct)] 
        Guid pixelFormat,
        uint cbStride,
        uint cbBufferSize,
        [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)] 
        byte[] pbBuffer
        );

    new IWICBitmap CreateBitmapFromMemory(
        uint uiWidth,
        uint uiHeight,
        [MarshalAs(UnmanagedType.LPStruct)] 
        Guid pixelFormat,
        uint cbStride,
        uint cbBufferSize,
        IntPtr pbBuffer
        );

:完整代码:

    public static IWICBitmap ToWic(IWICComponentFactory factory, Bitmap bit) {
        BitmapData bd = bit.LockBits(new Rectangle(0, 0, bit.Width, bit.Height),
                    ImageLockMode.ReadOnly, bit.PixelFormat);
        IWICBitmap b = null;
        try {
            //Create WIC bitmap directly from unmanaged memory
            b = factory.CreateBitmapFromMemory((uint)bit.Width, (uint)bit.Height, 
             ConversionUtils.FromPixelFormat(bit.PixelFormat), (uint)bd.Stride, 
             (uint)(bd.Stride * bd.Height), bd.Scan0);
            return b;
        } finally {
            bit.UnlockBits(bd);
        }
    }

宽度、高度、缓冲区大小、格式 GUID 和扫描大小似乎都正确。我不明白为什么会发生这种情况(没有错误代码或消息的谷歌结果

I'm getting the following error when calling IWICComponentFactory.CreateBitmapFromMemory and passing it a pointer to Scan0 of a 32bppArgb GDI+ bitmap

WINCODEC_ERR_WIN32ERROR
0x88982F94
Windows Codecs received an error from the Win32 system.

IWICComponentFactory interface decl:

    new IWICBitmap CreateBitmapFromMemory(
        uint uiWidth,
        uint uiHeight,
        [MarshalAs(UnmanagedType.LPStruct)] 
        Guid pixelFormat,
        uint cbStride,
        uint cbBufferSize,
        [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)] 
        byte[] pbBuffer
        );

    new IWICBitmap CreateBitmapFromMemory(
        uint uiWidth,
        uint uiHeight,
        [MarshalAs(UnmanagedType.LPStruct)] 
        Guid pixelFormat,
        uint cbStride,
        uint cbBufferSize,
        IntPtr pbBuffer
        );

Full code:

    public static IWICBitmap ToWic(IWICComponentFactory factory, Bitmap bit) {
        BitmapData bd = bit.LockBits(new Rectangle(0, 0, bit.Width, bit.Height),
                    ImageLockMode.ReadOnly, bit.PixelFormat);
        IWICBitmap b = null;
        try {
            //Create WIC bitmap directly from unmanaged memory
            b = factory.CreateBitmapFromMemory((uint)bit.Width, (uint)bit.Height, 
             ConversionUtils.FromPixelFormat(bit.PixelFormat), (uint)bd.Stride, 
             (uint)(bd.Stride * bd.Height), bd.Scan0);
            return b;
        } finally {
            bit.UnlockBits(bd);
        }
    }

Width, Height, buffer size, format GUID, and scan size all seem correct. I can't figure out why this is happening (there are no google results for the error code or message

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

碍人泪离人颜 2024-12-22 05:55:09

这并不是原始代码不起作用的答案 - 但它是一种解决方法。使用 IWICImagingFactory_CreateBitmapFromMemory_Proxy ,一切正常。但为什么原来的作品没有达到预期的效果呢?为什么 _Proxy 方法具有几乎相同的签名?

[DllImport("WindowsCodecs.dll", EntryPoint = "IWICImagingFactory_CreateBitmapFromMemory_Proxy")]
internal static extern int CreateBitmapFromMemory(IWICComponentFactory factory, uint width, uint height, ref Guid pixelFormatGuid, uint stride, uint cbBufferSize, IntPtr pvPixels, out IWICBitmap ppIBitmap);


public static IWICBitmap ToWic(IWICComponentFactory factory, Bitmap bit) {
    Guid pixelFormat = ConversionUtils.FromPixelFormat(bit.PixelFormat);
    if (pixelFormat == Guid.Empty) throw new NotSupportedException("PixelFormat " + bit.PixelFormat.ToString() + " not supported.");
    BitmapData bd = bit.LockBits(new Rectangle(0, 0, bit.Width, bit.Height), ImageLockMode.ReadOnly, bit.PixelFormat);
    IWICBitmap b = null;
    try {
            //Create WIC bitmap directly from unmanaged memory
        long result = CreateBitmapFromMemory(factory, (uint)bit.Width, 
 (uint)bit.Height,  ref pixelFormat, (uint)bd.Stride, 
 (uint)(bd.Stride * bd.Height), bd.Scan0, out b);

        if (result == 0x80070057) throw new ArgumentException();
        if (result < 0) throw new Exception("HRESULT " + result);
        return b;
    } finally {
        bit.UnlockBits(bd);
    }
}

作为参考,这里是 COM方法这里是代理方法 。两者都使用 [IN] BYTE *pbBuffer。

This isn't an answer as to why the original code doesn't work - but it's a workaround. Using IWICImagingFactory_CreateBitmapFromMemory_Proxy , everything works fine. But why didn't the original work as it's supposed to? And why the _Proxy methods with near-identical signatures?

[DllImport("WindowsCodecs.dll", EntryPoint = "IWICImagingFactory_CreateBitmapFromMemory_Proxy")]
internal static extern int CreateBitmapFromMemory(IWICComponentFactory factory, uint width, uint height, ref Guid pixelFormatGuid, uint stride, uint cbBufferSize, IntPtr pvPixels, out IWICBitmap ppIBitmap);


public static IWICBitmap ToWic(IWICComponentFactory factory, Bitmap bit) {
    Guid pixelFormat = ConversionUtils.FromPixelFormat(bit.PixelFormat);
    if (pixelFormat == Guid.Empty) throw new NotSupportedException("PixelFormat " + bit.PixelFormat.ToString() + " not supported.");
    BitmapData bd = bit.LockBits(new Rectangle(0, 0, bit.Width, bit.Height), ImageLockMode.ReadOnly, bit.PixelFormat);
    IWICBitmap b = null;
    try {
            //Create WIC bitmap directly from unmanaged memory
        long result = CreateBitmapFromMemory(factory, (uint)bit.Width, 
 (uint)bit.Height,  ref pixelFormat, (uint)bd.Stride, 
 (uint)(bd.Stride * bd.Height), bd.Scan0, out b);

        if (result == 0x80070057) throw new ArgumentException();
        if (result < 0) throw new Exception("HRESULT " + result);
        return b;
    } finally {
        bit.UnlockBits(bd);
    }
}

For reference, here is the COM method and here is the proxy method. Both use [IN] BYTE *pbBuffer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文