Graphics.DrawImage half pixel clip and shift?
-
I'm having a problem with a graphics control I'm working on. It seems that the Graphics.DrawImage method is clipping a half pixel off of the image, and then shifting it up and left by that half pixel. This can usually only be seen when zoomed in 2-4x or more, but now that I know what to look for, I'm seeing it happen even close to 1x with certain images. The following image shows the extent of the issue when zoomed in significantly - the green lines you see are where the bounds of the bitmap should be: odd_image.jpg[^] The graphics object that gets drawn to is from a bitmap that gets created on the fly depending on the size of the control and the objects in it. All graphics properties are set to the default except for the following: g.InterpolationMode = InterpolationMode.NearestNeighbor g.PageUnit = GraphicsUnit.Millimeter and there is a translation applied (though removing it did not affect the problem). I tried changing to the PageUnit to various values with no change, I also messed with PixelOffsetMode, CompositingMode, CompositingQuality and SmoothingMode, trying various values to no effect. I've done several searches in here and MSDN and found nothing that fixed the problem, or even hints that there is one. Has anyone seen anything similar to this, or have any ideas to try? ----- In the land of the blind, the one eyed man is king.
-
I'm having a problem with a graphics control I'm working on. It seems that the Graphics.DrawImage method is clipping a half pixel off of the image, and then shifting it up and left by that half pixel. This can usually only be seen when zoomed in 2-4x or more, but now that I know what to look for, I'm seeing it happen even close to 1x with certain images. The following image shows the extent of the issue when zoomed in significantly - the green lines you see are where the bounds of the bitmap should be: odd_image.jpg[^] The graphics object that gets drawn to is from a bitmap that gets created on the fly depending on the size of the control and the objects in it. All graphics properties are set to the default except for the following: g.InterpolationMode = InterpolationMode.NearestNeighbor g.PageUnit = GraphicsUnit.Millimeter and there is a translation applied (though removing it did not affect the problem). I tried changing to the PageUnit to various values with no change, I also messed with PixelOffsetMode, CompositingMode, CompositingQuality and SmoothingMode, trying various values to no effect. I've done several searches in here and MSDN and found nothing that fixed the problem, or even hints that there is one. Has anyone seen anything similar to this, or have any ideas to try? ----- In the land of the blind, the one eyed man is king.
-
That did it alright. I swore I tried that yesterday - but I tried a million combinations before giving up and posting, that one must have slipped through, or maybe it didn't work with some other setting I had at the time. Whatever, works now - Thanks! ----- In the land of the blind, the one eyed man is king.