Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>in <a href="https://stackoverflow.com/questions/1582499/resize-image-gdi-graphics-net/1587486#1587486">this question</a>, you'll have some answers, including mine:</p> <pre><code>public Image resizeImage(int newWidth, int newHeight, string stPhotoPath) { Image imgPhoto = Image.FromFile(stPhotoPath); int sourceWidth = imgPhoto.Width; int sourceHeight = imgPhoto.Height; //Consider vertical pics if (sourceWidth &lt; sourceHeight) { int buff = newWidth; newWidth = newHeight; newHeight = buff; } int sourceX = 0, sourceY = 0, destX = 0, destY = 0; float nPercent = 0, nPercentW = 0, nPercentH = 0; nPercentW = ((float)newWidth / (float)sourceWidth); nPercentH = ((float)newHeight / (float)sourceHeight); if (nPercentH &lt; nPercentW) { nPercent = nPercentH; destX = System.Convert.ToInt16((newWidth - (sourceWidth * nPercent)) / 2); } else { nPercent = nPercentW; destY = System.Convert.ToInt16((newHeight - (sourceHeight * nPercent)) / 2); } int destWidth = (int)(sourceWidth * nPercent); int destHeight = (int)(sourceHeight * nPercent); Bitmap bmPhoto = new Bitmap(newWidth, newHeight, PixelFormat.Format24bppRgb); bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution); Graphics grPhoto = Graphics.FromImage(bmPhoto); grPhoto.Clear(Color.Black); grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel); grPhoto.Dispose(); imgPhoto.Dispose(); return bmPhoto; } </code></pre>
    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.
    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