Solved

DrawImage without interpolation

Posted on 2014-02-15
5
370 Views
Last Modified: 2014-03-03
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
0
Comment
Question by:RonMexico
  • 3
  • 2
5 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 39862247
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.
0
 

Author Comment

by:RonMexico
ID: 39862266
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.
0
 
LVL 62

Assisted Solution

by:Fernando Soto
Fernando Soto earned 500 total points
ID: 39862751
Hi RonMexico;

The InterpolationMode enumeration specifies the algorithm that is used when images are scaled or rotated.. It must be set to one of the enumeration values. The only enumeration that may not do any interpolation may be the Default setting, it does not say specifically what it does.

There is another property that handles smoothing and that is SmoothingMode. If you do not what smoothing set the SmoothingMode property to Drawing2D.SmoothingMode.None
0
 

Accepted Solution

by:
RonMexico earned 0 total points
ID: 39863040
Default performs interpolation, unfortunately.

And the SmoothingMode doesn't seem to affect DrawImage (it seems to only affect GDI drawing commands such as DrawLine).

This is starting to appear like a bug, or at least an oversight in .NET.
0
 

Author Closing Comment

by:RonMexico
ID: 39900012
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.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
C# Reverse int in fast ways 6 29
Form design in vb.net 7 21
getting id from database 5 24
VB.NET HttpWebRequest 12 34
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now