当前所在位置:珠峰网资料 >> 计算机 >> 软件水平 >> 正文
计算机高级软考:系统架构设计师处理图像
发布时间:2009/11/22 14:24:12 来源:城市学习网 编辑:admin
  处理图像
  如果您的应用程序显示大量图像文件(例如,.jpg 和 .gif 文件),则您可以通过以位图格式预先呈现图像来显著改善显示性能。要使用该技术,请首先从文件中加载图像,然后使用 PARGB 格式将其呈现为位图。下面的代码示例从磁盘中加载文件,然后使用该类将图像呈现为预乘的、Alpha 混合 RGB 格式。例如:
  [C#]
  if ( image != null && image is Bitmap )
  {
  Bitmap bm = (Bitmap)image;
  Bitmap newImage = new Bitmap( bm.Width, bm.Height,
  System.Drawing.Imaging.PixelFormat.Format32bppPArgb );
  using ( Graphics g = Graphics.FromImage( newImage ) )
  {
  g.DrawImage( bm, new Rectangle( 0,0, bm.Width, bm.Height ) );
  }
  image = newImage;
  }
  [Visual Basic .NET]
  If Not(image Is Nothing) AndAlso (TypeOf image Is Bitmap) Then
  Dim bm As Bitmap = CType(image, Bitmap)
  Dim newImage As New Bitmap(bm.Width, bm.Height, _
  System.Drawing.Imaging.PixelFormat.Format32bppPArgb)
  Using g As Graphics = Graphics.FromImage(newImage)
  g.DrawImage(bm, New Rectangle(0, 0, bm.Width, bm.Height))
  End Using
  image = newImage
  End If
广告合作:400-664-0084 全国热线:400-664-0084
Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号
珠峰网 版权所有 All Rights Reserved