Link to home
Start Free TrialLog in
Avatar of RonMexico
RonMexico

asked on

DrawImage without interpolation

So, I'm working on a sort-of image manipulation program in .NET, and I'm trying to draw an image to the screen, and when you mouse wheel you zoom into the image to view individual pixels (similar to microsoft paint, etc).

I'm using the code

pe.Graphics.DrawImage(m_Bitmap, draw_rect)

in the form OnPaint method to do this.

However, I noticed I was getting smoothing when I zoomed in, and the pixels were looking blurry.  I found on another topic that I could set the "InterpolationMode" and adjust the smoothing method to get the "blocky" pixels I wanted, the other article said "NearestNeighbor" would do it.

However this isn't quite right... it is shifting the first pixel for some reason.  See the attached image.  Also see the original bitmap in microsoft paint,  Each row is supposed to be two pixels wide, and the "Nearestneighbor" interpolation seems to halve the first row and column of pixels.

Is there a way to turn interpolation off altogether?   I'm trying to find a way to not iterate through each pixel and draw the individual squares...

Thanks for any thoughts.
shifted.png
paint.png
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi RonMexico;

Using NearestNeighbor Will produce an image of lower quality. To get the best image quality use HighQualityBicubic. InterpolationMode must be set to a value. Be advised that the higher the quality, InterpolationMode, the longer it takes to process the image.
Avatar of RonMexico
RonMexico

ASKER

Sorry, probably wasn't clear:

I actually don't want smoothing/interpolation at all.  I want to zoom in and examine pixels and have them look like perfect squares that can be clicked on.  (I'm creating an image manipulation program.)

When I use NearestNeighbor my first row and columns are halved, as shown in the first attached picture.  What I want is behavior like in MS Paint, such as in the second attached picture.
SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Seems to me at this point that this is design behavior, although it *ought* to behave like I suggest.  Awarding Fernando the points for the insight but the answer ought to lead to my comment I think.