mvc2 웹 응용 프로그램에 사용자 이미지를 업로드합니다. 사용자는 모든 크기의 이미지를 업로드 할 수 있습니다. 10MB 이상. 업로드 된 이미지는 데이터베이스 AS IMAGE
데이터 유형에 저장됩니다. 그러나 데이터베이스에 저장되기 전에 나는 크기를 4MB으로 줄이고 싶습니다. 어떻게해야합니까?데이터베이스 mvc2에 저장하는 동안 이미지 크기를 바이트 단위로 줄입니다. C# 4.0
나는 크기를 다음 코드로 이미지의 바이트를 감소 : 이미지를 표시하는 동안
if (file.ContentLength > 0)
{
//Create byte Array with file len
var imgByte = new Byte[file.ContentLength];
//force the control to load data in array
file.InputStream.Read(imgByte, 0, file.ContentLength);
System.IO.MemoryStream newImageStream =
new System.IO.MemoryStream(imgByte, 0, imgByte.Length);
Image image = Image.FromStream(newImageStream, true);
Bitmap resized = new Bitmap(image, new Size(800,600));
System.IO.MemoryStream stream = new System.IO.MemoryStream();
resized.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
var imgBytes = new Byte[stream.Length];
customParentalHealthUser.ImageBytes = imgBytes;
stream.Close();
stream.Dispose();
resized.Dispose();
}
그러나
는 이미지가 축소 된 크기가 DB에 저장하기 경우에도 표시되지 않습니다. 크기를 줄이면 이미지가 손상 될 것입니다.친절히 제안 하시겠습니까?
감사
당신이 그 FOT 코드를 제공하시기 바랍니다 수 있습니까? 다음은 내 코드입니다. if (Request! = null) { HttpPostedFileBase file = Request.Files [ "uploadimage"]; 경우 (파일 = NULL!) 경우 (file.ContentLength> 0) { VAR의 imgByte = 새로운 바이트 [file.ContentLength]; file.InputStream.Read (imgByte, 0, file.ContentLength); customParentalHealthUser.ImageBytes = imgByte; }} – Tarun
@Tarun 이미 약 [실시 예 100] (http://stackoverflow.com/search?q=%5Bc%23%5D+resize+image) C#에서의 이미지의 크기를 조정하는 방법이있다. –
하지만 바이트 배열로 이미지를 데이터베이스에 저장할 때 이미지의 바이트 크기를 줄여야합니까? – Tarun