Ta bort den här raden skulle jag tro: g.FillRectangle(Brushes.White, 0, 0, mg.Width, mg.Height);
jag har en kod som laddar upp en bild samt ändrar storlek på bilden. Men den lämnar en vit ramlinje antingen upptill eller på sidorna (beroende på om det är en stående eller liggande bild. Någo som vet hur man kan greja till det. Här kommer koden:
//Function For Image
private Bitmap ResizeImage(Bitmap mg, Size newSize)
{
double ratio = 0d;
double myThumbWidth = 0d;
double myThumbHeight = 0d;
int x = 0;
int y = 0;
Bitmap bp;
if ((mg.Width / Convert.ToDouble(newSize.Width)) > (mg.Height /
Convert.ToDouble(newSize.Height)))
ratio = Convert.ToDouble(mg.Width) / Convert.ToDouble(newSize.Width);
else
ratio = Convert.ToDouble(mg.Height) / Convert.ToDouble(newSize.Height);
myThumbHeight = Math.Ceiling(mg.Height / ratio);
myThumbWidth = Math.Ceiling(mg.Width / ratio);
Size thumbSize = new Size((int)myThumbWidth, (int)myThumbHeight);
bp = new Bitmap(newSize.Width, newSize.Height);
x = (newSize.Width - thumbSize.Width) / 2;
y = (newSize.Height - thumbSize.Height);
// Had to add System.Drawing class in front of Graphics ---
System.Drawing.Graphics g = Graphics.FromImage(bp);
g.SmoothingMode = SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMod
Rectangle rect = new Rectangle(x, y, thumbSize.Width, thumbSize.Height);
g.FillRectangle(Brushes.White, 0, 0, mg.Width, mg.Height);
g.DrawImage(mg, rect, 0, 0, mg.Width, mg.Height, GraphicsUnit.Pixel);
return bp;
}
//End Function For Image
Calling code:
Size newSize = new Size(imageWidth, imageHeight);
Bitmap bp = ResizeImage(mg, newSize);
bp.Save(Server.MapPath(".\\images\\Thumb\\" + StrFileName), System.Drawing.Imaging.ImageFormat.Jpeg);
bp.Dispose();