系統架構設計師輔導:處理影象
來源:文萃谷 2.69W
如果您的'應用程式顯示大量影象檔案(例如,.jpg 和 .gif 檔案),則您可以通過以點陣圖格式預先呈現影象來顯著改善顯示效能。要使用該技術,請首先從檔案中載入影象,然後使用 PARGB 格式將其呈現為點陣圖。下面的程式碼示例從磁碟中載入檔案,然後使用該類將影象呈現為預乘的、Alpha 混合 RGB 格式。例如:
[C#]
if ( image != null && image is Bitmap )
{
Bitmap bm = (Bitmap)image;
Bitmap newImage = new Bitmap( h, bm.Height,
System.Drawing.Imaging.PixelFormat.Format32bppPArgb );
using ( Graphics g = Image( newImage ) )
{
Image( bm, new Rectangle( 0,0, h, ht ) );
}
image = newImage;
}
[Visual Basic ]
If Not(image Is Nothing) AndAlso (TypeOf image Is Bitmap) Then
Dim bm As Bitmap = CType(image, Bitmap)
Dim newImage As New Bitmap(h, ht, _
System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
Using g As Graphics = Image(newImage)
Image(bm, New Rectangle(0, 0, h, ht))
End Using
image = newImage
End If