2016-07-22 16 views
0

私のウェブサイトには、クライアント側から画像をアップロードするための部分があります。画像の表示に問題があります。画像のサイズはbollixです。アップロード時に画像のサイズを変更できますか?MVC.NETで画像をどのようにサイズ変更するのですか?

この私のコード:

[HttpPost] 
    public ActionResult Create(int id,HttpPostedFileBase photoFile) 
    { 
     if (photoFile != null) 
     { 
      Photo photo = new Photo(); 
      photo.Part = db.Parts.Find(id); 
      photo.PhotoContent = photoFile.ContentType; 
      photo.PhotoByte = new byte[photoFile.ContentLength]; 
      photoFile.InputStream.Read(photo.PhotoByte, 0, photoFile.ContentLength); 
      db.Photos.Add(photo); 
      db.SaveChanges(); 
      return RedirectToAction("Index", new { id = photo.Part.Id }); 
     } 
     return View(); 
    } 
+4

の可能性のある重複(http://stackoverflow.com/questions/1922040/resize-an-image-c-sharp)[画像のC#のサイズを変更します] –

答えて

0
 Stream str = new MemoryStream((Byte[])photo);   
     Bitmap loBMP = new Bitmap(str); 
     Bitmap bmpOut = new Bitmap(100, 100); 
     Graphics g = Graphics.FromImage(bmpOut); 
     g.InterpolationMode =System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; 
     g.FillRectangle(Brushes.White, 0, 0, 100, 100); 
     g.DrawImage(loBMP, 0, 0, 100, 100); 
     MemoryStream ms = new MemoryStream(); 
     bmpOut.Save(ms, System.Drawing.Imaging.ImageFormat.Png); 
     byte[] bmpBytes = ms.GetBuffer(); 
     bmpOut.Dispose(); 
     ms.Close(); 
     Response.BinaryWrite(bmpBytes);   
     Response.End(); 
関連する問題