开发者

Unexpected error in example using example from MSDN Image Encoding - GetEncoderParameterList

开发者 https://www.devze.com 2023-04-05 08:07 出处:网络
This code was inserted in a button handler. It gives different errors if I compile the project for x64 or x86

This code was inserted in a button handler.

It gives different errors if I compile the project for x64 or x86

x64 : Gives the Overflow Exception unhandled

Explanation: Arithmetic operation resulted in an overflow.

x86 : Gives Bitmap region is already locked.

Suggestion : If you are using a Graphics object after the GetHdc Method, call the ReleaseHdc Method

Code:

Bitmap bitmap1 = new Bitmap(10, 10);
        ImageCodecInfo jpgEncoder = GetEncoder(ImageFormat.Jpeg);
        EncoderParameters paramList = bitmap1.GetEncoderParameterList(jpgEncoder.Clsid);
        EncoderParameter[] encParams = paramList.Param;
        StringBuilder paramInfo = new StringBuilder();

        for (int i = 0; i < encParams.Length; i++)
        {
            paramInfo.Append("Param " + i + " holds " + encParams[i].NumberOfValues +
                " items of type " +
                encParams[i].ValueType + "\r\n" + "Guid category: " + encParams[i].Encoder.Guid + "\r\n");

        }

Line giving error is:

EncoderParameters paramList = bitmap1.GetEncoderParam开发者_如何学编程eterList(jpgEncoder.Clsid);

Any idea ?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号