Note that there are some explanatory texts on larger screens.

plurals
  1. POPreserving Bitmap values when creating a new Bitmap from System.Drawing.Image
    primarykey
    data
    text
    <p>I'm trying to create a resized image from a bitmap, set a new height/width and a new resolution and save it to PNG. I can do this either from directly A) <code>Image.FromFile(filename)</code> or B) <code>New Bitmap(imageSource)</code> to create the the <strong><em>A</em></strong> Bitmap to be passed to <strong><em>B</em></strong>. Both work okay schmokay, but <strong><em>A</em></strong> does not allow me to set a new width/height on creation (but it does allow me to preserve values with <code>useIcm=True</code>) and <strong><em>B</em></strong> does not allow me to preseve values.</p> <p>Okay, now on to some code and examples:</p> <ol> <li><p><code>Dim sourceBitmap As New Bitmap(imagePath &amp; myImage1Name)</code> &lt;-not good at all (#1 overload). Doesn't preserve things like <code>HorizontalResolution</code> or <code>PixelFormat</code> on <code>.Save</code></p></li> <li><p><code>Dim sourceBitmap2 As Bitmap = Image.FromFile(imagePath &amp; myImage1Name, True)</code> &lt;-not good (#5 overload). it <em>does</em> preserve things like <code>HorizontalResolution</code> or <code>PixelFormat</code> on <code>.Save</code>, but it <strong><em>doesn't</em></strong> allow me to initialize image at a new size.</p></li> <li><code>Dim targetBitmap As New Bitmap(sourceBitmap2, newWidth, newHeight)</code> &lt;-not good. Even though <code>sourceBitmap2</code> (see #2 above) was initialized with <code>useIcm=True</code>, it doesn't matter once I've passed it in as the source in <code>targetBitmap</code>.</li> </ol> <p>Basically, I'm looking for a way to contruct a New Bitmap with both something like <code>useIcm=True</code> <em>and</em> set the width/height at the same time (<code>Width</code>/<code>Height</code> are read-only properties once it's created).</p> <p>I've gone down the <code>Graphics.DrawImage</code> route as well and it's the same - <code>Graphics.FromImage(sourceBitmap)</code> does not preserve values.</p> <p>Why do I need these values to be preserved? Because I need to convert these pictures to PNG (for file size) with a new resolution and keep the same physical dimensions (w/h in inches) for printing. I know the new pixel width/height needed based on the resolution values I'll pass in with <code>.SetResolution(xDpi,yDpi)</code> to preserve physical dimensions, so that's not the problem. The issue is things like the <code>PixelFormatSize</code> need to remain unchanged (yes, I've tried <code>EncoderParameters</code> - they don't work. I can give you the gory details if you like, but suffice it to say for now, they just don't work).</p> <p>Whew, got that off my chest! Okay, anyone who really knows how all this works can help?</p> <p><strong>EDIT</strong>: Files types needed to pull in to convert to PNG: BMP, TIF, GIF, WMF, EMF.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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