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 ?
精彩评论