Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I saw you've commented that you want also to resize the cropped image to a smaller size right?</p> <pre><code>Image resizeImg(Image img, int width) { // 4:3 Aspect Ratio. You can also add it as parameters double aspectRatio_X = 4; double aspectRatio_Y = 3; double targetHeight = Convert.ToDouble(width) / (aspectRatio_X / aspectRatio_Y); img = cropImg(img); Bitmap bmp = new Bitmap(width, (int)targetHeight); Graphics grp = Graphics.FromImage(bmp); grp.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel); return (Image)bmp; } Image cropImg(Image img) { // 4:3 Aspect Ratio. You can also add it as parameters double aspectRatio_X = 4; double aspectRatio_Y = 3; double imgWidth = Convert.ToDouble(img.Width); double imgHeight = Convert.ToDouble(img.Height); if (imgWidth / imgHeight &gt; (aspectRatio_X / aspectRatio_Y)) { double extraWidth = imgWidth - (imgHeight * (aspectRatio_X / aspectRatio_Y)); double cropStartFrom = extraWidth / 2; Bitmap bmp = new Bitmap((int)(img.Width - extraWidth), img.Height); Graphics grp = Graphics.FromImage(bmp); grp.DrawImage(img, new Rectangle(0, 0, (int)(img.Width - extraWidth), img.Height), new Rectangle((int)cropStartFrom, 0, (int)(imgWidth - extraWidth), img.Height), GraphicsUnit.Pixel); return (Image)bmp; } else return null; } private void button1_Click(object sender, EventArgs e) { pictureBox2.Image = resizeImg(pictureBox1.Image, 60); } </code></pre> <p>Use the resize method and provide width as parameter. No need to add height because it is done by the crop method.</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.
    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.
    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