다음을 통해 공유


방법: 썸네일 이미지 만들기

썸네일 이미지는 이미지의 작은 버전입니다. GetThumbnailImage 개체의 Image 메서드를 호출하여 썸네일 이미지를 만들 수 있습니다.

예시

다음 예제에서는 JPG 파일에서 Image 개체를 생성합니다. 원본 이미지의 너비는 640픽셀이고 높이는 479픽셀입니다. 이 코드는 너비가 100픽셀이고 높이가 100픽셀인 썸네일 이미지를 만듭니다.

다음 그림은 썸네일 이미지를 보여 줍니다.

출력 썸네일을 보여주는 스크린샷.

비고

이 예제에서는 콜백 메서드가 선언되지만 사용되지 않습니다. 이 기능은 모든 버전의 GDI+를 지원합니다.

public bool ThumbnailCallback()
{
    return true;
}

private void GetThumbnail(PaintEventArgs e)
{
    Image.GetThumbnailImageAbort callback =
        new Image.GetThumbnailImageAbort(ThumbnailCallback);
    Image image = new Bitmap(@"c:\FakePhoto.jpg");
    Image pThumbnail = image.GetThumbnailImage(100, 100, callback, new
       IntPtr());
    e.Graphics.DrawImage(
       pThumbnail,
       10,
       10,
       pThumbnail.Width,
       pThumbnail.Height);
}
Public Function ThumbnailCallback() As Boolean 
        Return True 
End Function 

Private Sub GetThumbnail(ByVal e As PaintEventArgs) 

        Dim callback As New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback) 
        Dim image As Image = New Bitmap("c:\FakePhoto.jpg") 
        Dim pThumbnail As Image = image.GetThumbnailImage(100, 100, callback, New IntPtr()) 
        e.Graphics.DrawImage(pThumbnail, 10, 10, pThumbnail.Width, pThumbnail.Height) 
End Sub 

코드 컴파일

앞의 예는 Windows Forms에서 사용하도록 설계되었으며 PaintEventArgs 이벤트 처리기의 매개 변수인 ePaint가 필요합니다. 이 예제를 실행하려면 다음 단계를 수행합니다.

  1. 새 Windows Forms 애플리케이션을 만듭니다.

  2. 예제 코드를 양식에 추가합니다.

  3. 양식의 Paint 이벤트에 대한 처리기 만들기

  4. Paint 처리기에서 GetThumbnail 메서드를 호출하고 e에 대해 PaintEventArgs를 전달합니다.

  5. 썸네일을 만들 이미지 파일을 찾습니다.

  6. GetThumbnail 메서드에서 이미지의 경로 및 파일 이름을 지정합니다.

  7. F5를 눌러 예제를 실행합니다.

    양식에 100x100의 썸네일 이미지가 나타납니다.

참고하십시오