DCSIMG
Change dimensions of a picture from byte array - שלמה גולדברג (הרב דוטנט)

שלמה גולדברג (הרב דוטנט)

מרצה בסלע ויועץ בעולם ה - net.

Change dimensions of a picture from byte array

כיצד לשנות גודל של תמונה המתקבלת כמערך של בתים

נניח שיש לכם HttpHandler שמציג תמונה ממערך בתים, כדי לשנות את גודלו תוכלו בדרך כלל לכתוב קוד כזה

 

<img src="myhandler.ashx?id=5" width="150" />

אבל לפעמים יש מקרים שצריכים לספק את כתובת ה – handler כפרמטר לפונקצייה שאמורה לקבל כתובת של תמונה, במקרים האלו אנחנו צריכים את היכולת לשנות את גודל התמונה בתוך ה – handler.

הקוד הבא יהיה שימושי.

byte[] image = GetImage();

int size;

if (int.TryParse(context.Request["size"], out size))

{

    using (MemoryStream msToRead = new MemoryStream(image))

    {

        Bitmap newImage = new Bitmap(Image.FromStream(msToRead), new Size(size, size));

        using (MemoryStream msToWrite = new MemoryStream())

        {

            newImage.Save(msToWrite, ImageFormat.Jpeg);

            image = new Byte[msToWrite.Length];

            msToWrite.Seek(0, SeekOrigin.Begin);

            msToWrite.Read(image, 0, image.Length);

        }

    }

}

 

 

 

תוכן התגובה

Change dimensions of a picture from byte array - ???????? ?????????????? (?????? ??????????) כתב/ה:

Pingback from  Change dimensions of a picture from byte array - ???????? ?????????????? (?????? ??????????)

# October 10, 2010 3:58 PM
שלח תגובה

(שדה חובה)  

(שדה חובה)  

(אופציונלי)

(שדה חובה) 

Please add 3 and 3 and type the answer here:


Enter the numbers above: