Üye Kayıt Üye Giriş

Resmi yeniden boyutlandırma


Resmi yeniden boyutlandırma

 
System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(byteArray);
System.Drawing.Image image = System.Drawing.Image.FromStream(memoryStream);
System.Drawing.Image thumbnail = new Bitmap(newWidth, newHeight);
System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(thumbnail);

graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphic.SmoothingMode = SmoothingMode.HighQuality;
graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphic.CompositingQuality = CompositingQuality.HighQuality;

graphic.DrawImage(image, 0, 0, newWidth, newHeight);

if(contentType == "image/jpeg")
{
info = ImageCodecInfo.GetImageEncoders();
EncoderParameters encoderParameters;
encoderParameters = new EncoderParameters(1);
encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
Response.ContentType = "image/jpeg";
thumbnail.Save(Response.OutputStream, info[1], encoderParameters);
}

if(contentType == "image/gif")
{
using (thumbnail)
{
OctreeQuantizer quantizer = new OctreeQuantizer (255 , 8) ;
using (Bitmap quantized = quantizer.Quantize (bitmap))
{
Response.ContentType = "image/gif";
quantized.Save (Response.OutputStream , ImageFormat.Gif) ;
}
}
}

Bilgisayar Dershanesi Ders Sahibi;
Bilgisayar Dershanesi

Yorumlar

Yorum Yapabilmek İçin Üye Girişi Yapmanız Gerekmektedir.

ETİKETLER