|
|
#11 (permalink) |
|
Üyelik Tarihi: 01.11.2000
Yer: İstanbul - Ortaköy
Yaş: 25
Mesaj: 1,094
|
Re: ASP.NET ve C# ile Image Resize
Alttaki şekilde yapınca oldu. Teşekkürler yardımınız için.
Kod:
<%@ Page Language="C#" %> <%@ Import Namespace="System.Drawing"%> <%@ Import Namespace="System.IO"%> <script runat="server"> void Page_Load(){ int yeniW = Convert.ToInt16(Request.QueryString["gen"]); int yeniH = Convert.ToInt16(Request.QueryString["yuk"]); string adres = Convert.ToString(Request.QueryString["adres"]); Response.ContentType="image/jpg"; string URI = server.MapPath("images/resim/"+adres); using (Bitmap uploadedimage = new Bitmap(URI)) { decimal genislik = uploadedimage.Width; decimal yukseklik = uploadedimage.Height; decimal gen_oran = (decimal) genislik / yeniW; decimal yuk_oran = (decimal)yukseklik / yeniH; int olacak_gen, olacak_yuk; if (gen_oran > yuk_oran) { olacak_gen = (int)(genislik / yuk_oran); olacak_yuk = yeniH; } else { olacak_gen = yeniW; olacak_yuk = (int)(yukseklik / gen_oran); } System.IO.Stream wClient = new System.Net.WebClient().OpenRead(URI); System.Drawing.Bitmap DestImage = new System.Drawing.Bitmap(uploadedimage.Width, uploadedimage.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Graphics.FromImage(DestImage).DrawImage(System.Drawing.image.FromStream(wClient), new System.Drawing.Rectangle(0, 0, uploadedimage.Width, uploadedimage.Height), new System.Drawing.Rectangle(0, 0, uploadedimage.Width, uploadedimage.Height), System.Drawing.GraphicsUnit.Pixel); using (System.Drawing.Bitmap imgOutput = new System.Drawing.Bitmap(DestImage, olacak_gen, olacak_yuk)) { Graphics myresizer; myresizer = Graphics.FromImage(imgOutput); myresizer.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; myresizer.DrawImage(DestImage, 0, 0, olacak_gen, olacak_yuk); imgOutput.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); imgOutput.Dispose(); wClient.Close(); wClient.Dispose(); } } } </script> |
|
|
|
Zoque'a hoşgeldiniz!