Hi I want to put products to a catalog, How i can crop the picture to small and save the small and the orginal?
Asked
Active
Viewed 563 times
1 Answers
0
Try look here:
C# Thumbnail Image With GetThumbnailImage
or here:
Create thumbnail and reduce image size
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
-
Can I reduce the image immediately or only after I've saved? – mnaftal Jun 30 '11 at 21:30
-
can i cut the image proportionately without knowing the original image size ? – mnaftal Jun 30 '11 at 22:05