ForumKalbi.Com

ForumKalbi.Com (https://www.forumkalbi.com/index.php)
-   Bilgisayar (https://www.forumkalbi.com/forumdisplay.php?f=220)
-   -   C# Resmi yeniden boyutlandırma (https://www.forumkalbi.com/showthread.php?t=4656)

Candres 27 Ocak 2024 18:58

C# Resmi yeniden boyutlandırma
 
C# Resmi yeniden boyutlandırma
Thumbnail oluşturma, resimlerin boyutlarıı eşitleme vs. işlemler için, resimlerin boyutlarını otomatik olarak değiştiren örnek program kodu


Kod:

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) ;
}
}


Forum saati; Türkiye'ye göre ayarlanmış olup, şu an saat: 21:32.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Navbar with Avatar by Motorradforum