如何:建立縮圖影像
縮圖影像是映射的小型版本。 您可以呼叫 GetThumbnailImage 物件的 方法 Image 來建立縮圖影像。
範例
下列範例會 Image 從 JPG 檔案建構 物件。 原始影像的寬度為 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 Form 使用而設計,且其需要 PaintEventArgse
,這是 Paint 事件處理常式的參數。 若要執行範例,請遵循下列步驟:
建立新的 Windows Form 應用程式。
將範例程式碼新增至表單。
建立表單 Paint 事件的處理常式
在 處理常式中 Paint ,呼叫
GetThumbnail
方法並傳遞e
。 PaintEventArgs尋找您想要建立縮圖的影像檔。
在 方法中
GetThumbnail
,指定映射的路徑和檔案名。按 F5 執行範例。
表單上會出現 100 到 100 個縮圖影像。
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應