哪个参数在WINCODEC_ERR_INVALIDPARAMETER上无效(System.ArgumentException)

时间:2012-03-03 22:16:49

标签: .net debugging wic

我正在调试一个使用here的WIC包装器的.NET应用程序,有时会收到ArgumentException。我环顾四周,这表明实际的HRESULT是WINCODEC_ERR_INVALIDPARAMETER。我在调试器中检查过,这些值似乎合理,所以如何确定哪个是问题?这是我的代码:

    Public Function CreateThumbnail(ByVal Height As UInteger, ByVal Width As UInteger, Optional ByVal Format As Format = Format.JPG) As Byte()
        'Calculate target dimensions
        Dim TargetDimensions As ThumbnailDimensions = GetThumbnailDimensions(Width, Height)

        'Output stream for the thumbnail to be created on
        Dim OutputStream As New MemoryIStream()

        'Get an appropriate encoder
        Dim Encoder As IWICBitmapEncoder = EncoderByFormat(Format)
        Encoder.Initialize(OutputStream, WICBitmapEncoderCacheOption.WICBitmapEncoderNoCache)

        'Create the output frame with but keep reference to the PropertyBag to add settings later
        Dim OutputFrame As IWICBitmapFrameEncode = Nothing
        Dim arguments As IPropertyBag2() = {Nothing}
        Encoder.CreateNewFrame(OutputFrame, arguments)

        'Add format specific option
        Dim PropertyBag As IPropertyBag2 = arguments(0)

        Select Case Format
            Case Format.JPG
                'Add the 85% quality setting
                Dim ImageQuality As PROPBAG2() = {Nothing}
                ImageQuality(0).pstrName = "ImageQuality"
                PropertyBag.Write(1, ImageQuality, New Object() {0.85F})
        End Select

        'Initialize the OutputFrame with the format specific properties.
        OutputFrame.Initialize(PropertyBag)

        'Set resolution
        OutputFrame.SetResolution(96, 96)

        'Set size
        OutputFrame.SetSize(TargetDimensions.Width, TargetDimensions.Height)

        'Create scaler to actually resize the image
        Dim Scaler = WICFactory.CreateBitmapScaler()
        Scaler.Initialize(InputDecoder.GetFrame(0), TargetDimensions.Width, TargetDimensions.Height, WICBitmapInterpolationMode.WICBitmapInterpolationModeFant)

        'Write the new image to the frame
        Dim Positioner As New WICRect
        Positioner.X = 0 : Positioner.Y = 0 : Positioner.Width = TargetDimensions.Width : Positioner.Height = TargetDimensions.Height


        '''''''''''' EXCEPTION ON THIS LINE!!! '''''''''
        OutputFrame.WriteSource(Scaler, Positioner)
        ''''''''''''''''''''''''''''''''''''''''''''''''

        'Commit the edits
        OutputFrame.Commit()
        Encoder.Commit()
        Dim OutputBytes As Byte() = OutputStream.ToArray()
        OutputStream.Close()

        'Return the bytes of the thumbnail
        Return OutputBytes
End Function

0 个答案:

没有答案