Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用带c#包装器的windows imaging components(wic)对隔行扫描的png进行编码时,使用哪个过滤器?_C#_Wic - Fatal编程技术网

使用带c#包装器的windows imaging components(wic)对隔行扫描的png进行编码时,使用哪个过滤器?

使用带c#包装器的windows imaging components(wic)对隔行扫描的png进行编码时,使用哪个过滤器?,c#,wic,C#,Wic,我正在尝试使用WIC将图像编码为交错png。我可以保存图像为png没有任何问题,并设置隔行扫描模式。但如果我尝试设置filtermode(任何筛选器),则会出现以下错误: [System.Runtime.InteropServices.COMException] = {"The bitmap property type is unexpected. (Exception from HRESULT: 0x88982F8E)"} 我是否以错误的方式设置属性包的值?这是代码,异常在propBag

我正在尝试使用WIC将图像编码为交错png。我可以保存图像为png没有任何问题,并设置隔行扫描模式。但如果我尝试设置filtermode(任何筛选器),则会出现以下错误:

[System.Runtime.InteropServices.COMException] = {"The bitmap property type is unexpected.   (Exception from HRESULT: 0x88982F8E)"}
我是否以错误的方式设置属性包的值?这是代码,异常在propBag.Write抛出

[...]
var arg = new IPropertyBag2[1];
encoder.CreateNewFrame(out outputFrame, arg);
var propBag = arg[0];
var propertyBagOptions = new PROPBAG2[2];

propertyBagOptions[0].pstrName = "InterlaceOption";
propertyBagOptions[1].pstrName = "FilterOption";
propBag.Write(2, propertyBagOption1, new object[] { true, WICPngFilterOption.WICPngFilterAdaptive});
[...]
谢谢你的帮助,
斯蒂芬妮

我认为这是因为:

底层的
Write
方法被标记为将
作为
变量
(即
UnmanagedType.Struct
)进行马歇尔处理,这是正确的:

void Write(
   uint cProperties, 
   [MarshalAs(UnmanagedType.LPArray)] PROPBAG2[] pPropBag, 
   [MarshalAs(UnmanagedType.Struct)] ref object pvarValue
);
我不打算测试它;因为我不能,但我认为修复方法是将PNG过滤器选项转换为C#等效的无符号字节

我认为这是因为从我的本机代码中,我将属性值作为变量提供。但是这个变体实际上是一个有符号的32位(aka
Int32
)。这导致了错误:

0x88982F8E
当您查看
WinCodec.h
(这是.NET imaging使用的本机代码)时,它对应于错误:

  WINCODEC_ERR_PROPERTYUNEXPECTEDTYPE = HRESULT($88982f8E);
我必须确保强制变体包含VT_UI1:

propertyBagHelper.Write('FilterOption', VarAsType(WICPngFilterAdaptive, VT_UI1));
然后它成功了

当您知道发生了什么时,从本机代码中可以看到这一切。.NET/CLR/C#wrapper世界喜欢混淆一切;因此,当您传递参数时,您并不真正知道参数包含什么

注意:发布到公共域的任何代码。无需归因

  WINCODEC_ERR_PROPERTYUNEXPECTEDTYPE = HRESULT($88982f8E);
propertyBagHelper.Write('FilterOption', VarAsType(WICPngFilterAdaptive, VT_UI1));