Soran
Resim upload sorunu, upoad ediyor ama resimdeboşluk bırakıyor

Genel Tartışma
-
resim upload kodlarında oranda bir sıkıntı var
mesela resim 800x600 px olsun 800e 800 beyaz çerceveye oturtuyor ustten alttan boşluk kalıyor. örneğin 600 pixel. yüklediğimde altta üstte beyaz boşluk bırakıyor. 800 indexliyor oranu değiştirebiliyorum ama boyu ene orantilamıyor 800 se 800 ustten altan boşluk veriyor ben en boy orantılasın beyaz boşluk olmasın istiyorum
Degerler.resimyukle(new System.Drawing.Bitmap(postedFile.InputStream), dosyaismi, "150/", 150);
Degerler.resimyukle(new System.Drawing.Bitmap(postedFile.InputStream), dosyaismi, "800/", 800);
resim upload kodları
<%@ WebHandler Language="C#" Class="Upload" %> using System; using System.Web; using System.IO; using System.Data.SqlClient; public class Upload : IHttpHandler { Fonksiyon fn=new Fonksiyon (); Fonksiyon system1 = new Fonksiyon(); public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Expires = -1; try { HttpPostedFile postedFile = context.Request.Files["Filedata"]; // dosyamızı alıyoruz //string dosya = context.Request["folder"]; // dosyanın yükleneceğin klasör //postedFile.SaveAs(HttpContext.Current.Server.MapPath(dosya + postedFile.FileName)); // dosyalar yüklenir string dosyaismi = postedFile.FileName; bool resvermi = true; do { if (File.Exists(Degerler.HaberresimyuklemeYolu + "800/" + dosyaismi)|| File.Exists(Degerler.HaberresimyuklemeYolu + "150/" + dosyaismi)) { dosyaismi = Degerler.Sayim()+dosyaismi ; resvermi = true; } else { resvermi = false; } } while (resvermi); Degerler.resimyukle(new System.Drawing.Bitmap(postedFile.InputStream), dosyaismi, "150/", 150); Degerler.resimyukle(new System.Drawing.Bitmap(postedFile.InputStream), dosyaismi, "800/", 800); SqlCommand cmd = new SqlCommand("insert into sayfageciciresim(resim,SayfaId) values('" + dosyaismi + "','" + context.Request["GelenID"] + "')", fn.baglan()); cmd.ExecuteNonQuery(); } catch { } finally { context.Response.Write("Dosya yüklendi"); context.Response.StatusCode = 200; } // baglanti.Close(); } public bool IsReusable { get { return false; } } }
Bude Deger. class oranların olduğu kod.
public class Degerler { public Degerler() { } public static string HaberresimyuklemeYolu = @"E:\travel\HaberResimleri\"; public static string Sayim() { int hane; string sonuc, sayi; Random rasgele = new Random(); sonuc = rasgele.Next(1, 9).ToString();// 0 dan baÅŸlayamaz hane = 8; while (hane > 1) { sayi = rasgele.Next(0, 9).ToString(); if (sonuc.IndexOf(sayi) == -1) { sonuc += sayi; hane -= 1; } } return sonuc; } public static void resimyukle(Bitmap resim, string resimad, string kopyalanacakyer, int boyut) { // Get the Bitmaps and a Graphics object // for the destination Bitmap. Bitmap fr_bm = resim; double ResimYukseklik = fr_bm.Height; double ResimUzunluk = fr_bm.Width; int sabit = boyut; double oran = 0; if (ResimUzunluk >= ResimYukseklik && ResimUzunluk >= sabit) { oran = ResimUzunluk / ResimYukseklik; ResimUzunluk = sabit; ResimYukseklik = sabit / oran; } else if (ResimYukseklik >= ResimUzunluk && ResimYukseklik >= sabit) { oran = ResimYukseklik / ResimUzunluk; ResimYukseklik = sabit; ResimUzunluk = sabit / oran; } int height = Convert.ToInt32(ResimYukseklik); int width = Convert.ToInt32(ResimUzunluk); Size newSize = new Size(width, height); fr_bm = new Bitmap(fr_bm, newSize); Bitmap to_bm = new Bitmap(sabit, sabit); Graphics gr = Graphics.FromImage(to_bm); int x = (width - sabit) / 2; int Y = (height - sabit) / 2; SolidBrush firca = new SolidBrush(Color.FromArgb(255, 255, 255, 255)); gr.FillRectangle(firca, 0, 0, sabit, sabit); // Get source and destination rectangles. Rectangle fr_rect = new Rectangle(x, Y, sabit, sabit); Rectangle to_rect = new Rectangle(0, 0, sabit, sabit); // Draw from the source to the destination. gr.DrawImage(fr_bm, to_rect, fr_rect, GraphicsUnit.Pixel); // gr.DrawRectangle(Pens.DimGray, 0, 0, sabit - 1, sabit - 1); gr.SmoothingMode = SmoothingMode.HighQuality; to_bm.Save(Degerler.HaberresimyuklemeYolu + kopyalanacakyer + resimad); } }
- Değiştirilmiş Tür Kyamuran SalibryamMicrosoft contingent staff, Moderator 13 Temmuz 2016 Çarşamba 21:55
- Değiştirilmiş Tür Cihan YakarMVP, Moderator 27 Temmuz 2016 Çarşamba 11:09 soru sormuş çünkü
- Değiştirilmiş Tür Kyamuran SalibryamMicrosoft contingent staff, Moderator 28 Temmuz 2016 Perşembe 07:47