Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a snippet of code I quickly knocked up for resizing it based on the width. I'm sure you could figure out how to add a background color to the Bitmap. It's not complete code but just an idea of how to do things.</p> <pre><code>public static void ResizeLogo(string originalFilename, string resizeFilename) { Image imgOriginal = Image.FromFile(originalFilename); //pass in whatever value you want for the width (180) Image imgActual = ScaleBySize(imgOriginal, 180); imgActual.Save(resizeFilename); imgActual.Dispose(); } public static Image ScaleBySize(Image imgPhoto, int size) { int logoSize = size; float sourceWidth = imgPhoto.Width; float sourceHeight = imgPhoto.Height; float destHeight = 0; float destWidth = 0; int sourceX = 0; int sourceY = 0; int destX = 0; int destY = 0; // Resize Image to have the height = logoSize/2 or width = logoSize. // Height is greater than width, set Height = logoSize and resize width accordingly if (sourceWidth &gt; (2 * sourceHeight)) { destWidth = logoSize; destHeight = (float)(sourceHeight * logoSize / sourceWidth); } else { int h = logoSize / 2; destHeight = h; destWidth = (float)(sourceWidth * h / sourceHeight); } // Width is greater than height, set Width = logoSize and resize height accordingly Bitmap bmPhoto = new Bitmap((int)destWidth, (int)destHeight, PixelFormat.Format32bppPArgb); bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution); Graphics grPhoto = Graphics.FromImage(bmPhoto); grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic; grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, (int)destWidth, (int)destHeight), new Rectangle(sourceX, sourceY, (int)sourceWidth, (int)sourceHeight), GraphicsUnit.Pixel); grPhoto.Dispose(); return bmPhoto; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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