0

Hi I want to put products to a catalog, How i can crop the picture to small and save the small and the orginal?

mnaftal
  • 5
  • 1

1 Answers1

0

Try look here:

C# Thumbnail Image With GetThumbnailImage

or here:

Convert Bitmap to Thumbnail

Create thumbnail and reduce image size

Create thumbnail image

update

For example you can save the image to a folder and then you can do something like this:

var filename = "sourceImage.png";

using(var image = Image.FromFile(filename))
{
    using(var thumbnail = image.GetThumbnailImage(20/*width*/, 40/*height*/, null, IntPtr.Zero))
    {
        thumbnail.Save("thumb.png");
    }
}

update

to resize proportionally try something like this:

public Bitmap ProportionallyResizeBitmap (Bitmap src, int maxWidth, int maxHeight)
{

// original dimensions
int w = src.Width;
int h = src.Height;

// Longest and shortest dimension
int longestDimension = (w>h)?w: h;
int shortestDimension = (w<h)?w: h;

// propotionality
float factor = ((float)longestDimension) / shortestDimension;

// default width is greater than height
double newWidth = maxWidth;
double newHeight = maxWidth/factor;

// if height greater than width recalculate
if ( w < h )
{
    newWidth = maxHeight / factor;
    newHeight = maxHeight;
}

// Create new Bitmap at new dimensions
Bitmap result = new Bitmap((int)newWidth, (int)newHeight);
using ( Graphics g = Graphics.FromImage((System.Drawing.Image)result) )
g.DrawImage(src, 0, 0, (int)newWidth, (int)newHeight);

return result;
}
Community
  • 1
  • 1
danyolgiax
  • 12,798
  • 10
  • 65
  • 116