2010-02-19 5 views
1

나는 데이터베이스에 이미지를 업로드합니다. 데이터베이스에 저장하기 전에 크기를 줄이고 높이와 너비를 줄이는 것과 같은 이미지 관리를하고 싶습니다. 나를 도와 주실 수있으세요. 거기에 어떤 소스 코드 또는 참조하시기 바랍니다.이미지 관리? 내 응용 프로그램에서

답변

0

당신은 썸네일 이미지를 만드는 같은 것을 얘기하는 경우. Image() 클래스를 사용하면 기존 이미지를 위 또는 아래로 스케일 할 수 있습니다. YMMV.

+0

예 정확히 Mr. No Refunds No Returns –

0

System.Drawing ASP.NET에서 이미지를 조작하기위한 이름 공간을보고 싶습니다. Image.FromFile(), Image.FromStream() 등을 사용하여 지원되는 이미지 파일 유형 (예 : jpg, gif, png 등)을로드 할 수 있습니다. 거기에서 그리기 그래픽 컨텍스트를 사용하여 이미지를 조작 할 수 있습니다.

// Creates a re-sized image from the SourceFile provided that retails the same aspect ratio of the SourceImage. 
// - If either the width or height dimensions is not provided then the resized image will use the 
//  proportion of the provided dimension to calculate the missing one. 
// - If both the width and height are provided then the resized image will have the dimensions provided 
//  with the sides of the excess portions clipped from the center of the image. 
public static Image ResizeImage(Image sourceImage, int? newWidth, int? newHeight) 
{ 
    bool doNotScale = newWidth == null || newHeight == null; ; 

    if (newWidth == null) 
    { 
     newWidth = (int)(sourceImage.Width * ((float)newHeight/sourceImage.Height)); 
    } 
    else if (newHeight == null) 
    { 
     newHeight = (int)(sourceImage.Height * ((float)newWidth)/sourceImage.Width); 
    } 

    var targetImage = new Bitmap(newWidth.Value, newHeight.Value); 

    Rectangle srcRect; 
    var desRect = new Rectangle(0, 0, newWidth.Value, newHeight.Value); 

    if (doNotScale) 
    { 
     srcRect = new Rectangle(0, 0, sourceImage.Width, sourceImage.Height); 
    } 
    else 
    { 
     if (sourceImage.Height > sourceImage.Width) 
     { 
      // clip the height 
      int delta = sourceImage.Height - sourceImage.Width; 
      srcRect = new Rectangle(0, delta/2, sourceImage.Width, sourceImage.Width); 
     } 
     else 
     { 
      // clip the width 
      int delta = sourceImage.Width - sourceImage.Height; 
      srcRect = new Rectangle(delta/2, 0, sourceImage.Height, sourceImage.Height); 
     } 
    } 

    using (var g = Graphics.FromImage(targetImage)) 
    { 
     g.SmoothingMode = SmoothingMode.HighQuality; 
     g.InterpolationMode = InterpolationMode.HighQualityBicubic; 

     g.DrawImage(sourceImage, desRect, srcRect, GraphicsUnit.Pixel); 
    } 

    return targetImage; 
} 
0

당신은 ASPJPEG로 이미지 클래스 또는 제 3 자 DLL을 사용할 수 있습니다 : 여기 당신에게 맛을 제공하기 위해 나의 크기 조정 이미지 기능입니다. 몇 가지 ASPJPEG 샘플은 here입니다. 나는 많은 이미지 처리를하고 내 호스트는 reliablesite이 서버에서이 dll을 지원합니다.

관련 문제