Note that there are some explanatory texts on larger screens.

plurals
  1. POGDI+ resizing for Pixel zoom
    text
    copied!<p>I want to resize an image with the GDI library so that when I resize it to be larger than before there is no blending. (Like when you zoom in on an image in a paint program)</p> <p>EG: If my image is 2px wide, and 2px tall<br> (white, white,<br> white, black)<br> , and I resize it to be 100% larger, it is 4px by 4px tall<br> (white, white, white, white,<br> white, white, white, white,<br> white, white, black, black,<br> white, white, black, black) </p> <p>What InterpolationMode or Smoothing mode (or other properties) of a graphics object can I use to achieve this? The combinations that I have tried so far all cause grey to appear in the test image.</p> <p>Here is the code that I'm using </p> <pre><code> /// &lt;summary&gt; /// Do the resize using GDI+ /// Credit to the original author /// http://www.bryanrobson.net/dnn/Code/Imageresizing/tabid/69/Default.aspx /// &lt;/summary&gt; /// &lt;param name="srcBitmap"&gt;The source bitmap to be resized&lt;/param&gt; /// &lt;param name="width"&gt;The target width&lt;/param&gt; /// &lt;param name="height"&gt;The target height&lt;/param&gt; /// &lt;param name="isHighQuality"&gt;Shoule the resize be done at high quality?&lt;/param&gt; /// &lt;returns&gt;The resized Bitmap&lt;/returns&gt; public static Bitmap Resize(Bitmap srcBitmap, int width, int height, bool isHighQuality) { // Create the destination Bitmap, and set its resolution Bitmap destBitmap = new Bitmap((int)Convert.ToInt32(width), (int)Convert.ToInt32(height), PixelFormat.Format24bppRgb); destBitmap.SetResolution(srcBitmap.HorizontalResolution, srcBitmap.VerticalResolution); // Create a Graphics object from the destination Bitmap, and set the quality Graphics grPhoto = Graphics.FromImage(destBitmap); if (isHighQuality) { grPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic; } else { grPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None; //? this doesn't work grPhoto.InterpolationMode = InterpolationMode.NearestNeighbor; //? this doesn't work } // Do the resize grPhoto.DrawImage(srcBitmap, new Rectangle(0, 0, width, height), new Rectangle(0, 0, srcBitmap.Width, srcBitmap.Height), GraphicsUnit.Pixel); grPhoto.Dispose(); return destBitmap; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload