2009-10-01 7 views

답변

1

은 다음 링크 :

snippets.dzone.com/posts/show/4336

업데이트를 당신을 도울 수 있습니다 : 링크의 코드를 물리적으로 크기를 조정하고 당신의 의도는 공간을 절약하기 위해 이미지 파일의 크기를 조정하는 경우 이미지를 저장 위 그렇지 않으면 이미지 컨트롤의 높이/너비를 수동으로 설정할 수 있습니다.

0

이미지를로드하면 너비/높이 속성을 설정할 수 있습니다.

Bitmap bmp = new Bitmap(@"c:\myfile.bmp"); 
bmp.Width = (int)(bmp.Width/2); 
bmp.Height = (int)(bmp.Height/2); 
0

gdi + (system.drawing) 및 비율로로드 하시겠습니까?

-2

. 어쨌든 조금 오래된. additiona에서

protected Image FixedSize(Image imgPhoto, int Width, int Height) 
{ 
    int width = imgPhoto.Width; 
    int height = imgPhoto.Height; 
    int x = 0; 
    int y = 0; 
    int num5 = 0; 
    int num6 = 0; 
    float num7 = 0f; 
    float num8 = 0f; 
    float num9 = 0f; 
    num8 = ((float) Width)/((float) width); 
    num9 = ((float) Height)/((float) height); 
    if (num9 < num8) 
    { 
     num7 = num9; 
     num5 = Convert.ToInt16((float) ((Width - (width * num7))/2f)); 
    } 
    else 
    { 
     num7 = num8; 
     num6 = Convert.ToInt16((float) ((Height - (height * num7))/2f)); 
    } 
    int num10 = (int) (width * num7); 
    int num11 = (int) (height * num7); 
    Bitmap image = new Bitmap(Width, Height, PixelFormat.Format24bppRgb); 
    image.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution); 
    Graphics graphics = Graphics.FromImage(image); 
    graphics.Clear(ColorTranslator.FromHtml("#ffffff")); 
    graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; 
    graphics.DrawImage(imgPhoto, new Rectangle(num5, num6, num10, num11), new Rectangle(x, y, width, height), GraphicsUnit.Pixel); 
    graphics.Dispose(); 
    return image; 
} 
+1

-1 : num1, num2, num3, ... num11. 불쾌감을 느끼지 않지만, 코드가 의도적으로 난독 화 된 것처럼 변수 이름을 선택하는 것은 어렵습니다. – Juliet

+0

이것은 심각한 WTF 코드입니다 : 변수 이름, Convert.ToInt16, ColorTranslators.FromHtml. 최소한 InterpolationMode 권한이 있기 때문에 다운 투표를하지 않을 것입니다. – MusiGenesis

+0

Kidooosss ...이 코드는 .NET Reflector에서 가져 왔습니다. 복사 - 붙여 넣기에 대한 아이디어가 있습니다. 의도는 논리 만 표시하는 것입니다. 평가 ... 선택. :-) – NinethSense

0

어떤 다른 사람은 최대 300x300보다 작은 이미지, Image.GetThumbnailImage이 매우 편리하다, 말했다하기 : WPF를 시도 :

static void Main(string[] args) 
{ 
    Bitmap b = new Bitmap(@"C:\Documents and Settings\juliet\My Documents\My Pictures\julietawesome.bmp"); 
    Image image = b.GetThumbnailImage(100, 100, null, IntPtr.Zero); 
    image.Save(@"C:\Documents and Settings\juliet\My Documents\My Pictures\thumbnail.bmp", ImageFormat.Bmp); 
} 
0
Public Function ScaleByPercent(ByVal imgPhoto As Image, ByVal Percent As Integer) As Image 

     Dim nPercent As Single = (CType(Percent, Single)/100) 
     Dim sourceWidth As Integer = imgPhoto.Width 
     Dim sourceHeight As Integer = imgPhoto.Height 
     Dim sourceX As Integer = 0 
     Dim sourceY As Integer = 0 

     Dim destX As Integer = 0 
     Dim destY As Integer = 0 
     Dim destWidth As Integer = CType((sourceWidth * nPercent), Integer) 
     Dim destHeight As Integer = CType((sourceHeight * nPercent), Integer) 

     Dim bmPhoto As New Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb) 
     bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution) 

     Dim grPhoto As Graphics = Graphics.FromImage(bmPhoto) 
     grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic 
     grPhoto.DrawImage(imgPhoto, New Rectangle(destX, destY, destWidth, destHeight), New Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel) 
     grPhoto.Dispose() 
     Return bmPhoto 

    End Function 
+0

GDI 크기 조정 알고리즘은 이미지 크기를 크게 변경할 때 평범한 결과를 생성합니다. 과거에 비슷한 코드를 작성한 다음 제 3 자 라이브러리로 전환하여 더 좋은 품질의 크기 조정 알고리즘을 얻었습니다. – ScottS