This is weird, but, first of all, eliminate
new Bitmap(Image)
. Use
Bitmap bmp = new Bitmap(fileName);
And if you really wanted to initialize a bitmap from some abstract
Image
instance when a file is not accessible, and if you also wanted to change the size and
PixelFormat
, you would need to initialize an empty bitmap with required properties, and then open an instance of
Image
separately, and draw in on your bitmap, using the
Graphics
instance you would obtain exactly the way you already did (called
gr
in your code). In this particular case, you just don't need it, because you can open a bitmap directly from a file, which should preserver the pixel format, size and all other properties. Please see:
https://msdn.microsoft.com/en-us/library/system.drawing.bitmap%28v=vs.110%29.aspx[
^],
https://msdn.microsoft.com/en-us/library/0cbhe98f(v=vs.110).aspx[
^],
https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage%28v=vs.110%29.aspx[
^].
—SA