ABA


"הורדת משקל לתמונה"
גירסת הדפסה        
קבוצות דיון פיתוח, תיכנות ובניית אתרים נושא #21036 מנהל    סגן המנהל    מפקח   Winner    צל"ש   מומחה  
אשכול מספר 21036
fly
חבר מתאריך 23.7.13
668 הודעות, 1 פידבק, -1 נקודות
   13:51   21.12.14   
אל הפורום  
  הורדת משקל לתמונה  
 
   השתמשתי ברעיון הזה, יש משהו יותר מקטין


public static Image ResizeImage(Image img, int minsize)
{
var size = img.Size;
if (size.Width >= size.Height)
{
// Could be: if (size.Height < minsize) size.Height = minsize;
size.Height = minsize;
size.Width = (size.Height * img.Width + img.Height - 1) / img.Height;
}
else
{
size.Width = minsize;
size.Height = (size.Width * img.Height + img.Width - 1) / img.Width;
}
return new Bitmap(img, size);
}



                                שתף        
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד

  האשכול     מחבר     תאריך כתיבה     מספר  
  מכתב Dimona 21.12.14 16:01 1

       
Dimona לחץ כאן להצגת דירוג המשתמש
חבר מתאריך 28.11.10
1910 הודעות, 1 פידבק, 1 נקודות
   16:01   21.12.14   
אל הפורום  
  1. מכתב  
בתגובה להודעה מספר 0
 
   אני משתמש בזה :

public static byte ResizeImageFile(byte imageFile,int select)
{
int width=200, hight=200;
switch(select)
{
case 1:{ width = 200; hight = 200;}break;
case 2: { width = 410; hight = 200; } break;
case 3: { width = 410; hight = 410; } break;
}
using (System.Drawing.Image oldImage = System.Drawing.Image.FromStream(new MemoryStream(imageFile)))
{
Size newSize = CalculateDimensions(oldImage.Size, width,hight);
using (Bitmap newImage = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format24bppRgb))
{
using (Graphics canvas = Graphics.FromImage(newImage))
{
canvas.SmoothingMode = SmoothingMode.AntiAlias;
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.PixelOffsetMode = PixelOffsetMode.HighQuality;
canvas.DrawImage(oldImage, new Rectangle(new Point(0, 0), newSize));
MemoryStream m = new MemoryStream();
newImage.Save(m, ImageFormat.Jpeg);
return m.GetBuffer();
}
}
}
}

public static Size CalculateDimensions(Size oldSize, int width, int hight)
{
Size newSize = new Size();
if (oldSize.Height > oldSize.Width)
{
newSize.Width = width;
newSize.Height = hight;
}
else
{
newSize.Width = width;
newSize.Height = hight;
}
return newSize;
}



                                                         (ניהול: מחק תגובה)
מכתב זה והנלווה אליו, על אחריות ועל דעת הכותב בלבד

תגובה מהירה  למכתב מספר: 
 
___________________________________________________________________

___________________________________________________________________
למנהלים:  נעל | תייק בארכיון | מחק | העבר לפורום אחר | מחק תגובות | עגן אשכול
       



© כל הזכויות שמורות ל-רוטר.נט בע"מ rotter.net