在mobile开发中,如果界面上使用 PictureBox,速度太慢,如果只想简单的显示一下图片,可以这样:
一、在项目属性中,添加一个图片资源,例如添加一个 Sample.JPG 文件,资源里面会显示一个 Sample;
二、打开项目文件夹下面的 /Properties/Resources.Designer.cs文件,找到下面这段:
/// <summary>
/// 为使用此强类型资源类的所有资源查找
/// 重写当前线程的 CurrentUICulture 属性。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
public static System.Drawing.Bitmap Sample{
get {
object obj = ResourceManager.GetObject("Sec", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
这里 C# 已经给你声明了一个 public 类型的变量 Sample
三、好了,现在可以直接在程序里面引用这个变量了:
pictureBox1.Image = VagueRecall.Properties.Resources.Sec;
或者自己绘制:
private void MainForm_Paint(object sender, PaintEventArgs e)
{
Graphics graphics = e.Graphics;
using (Brush brush = new SolidBrush(Color.White))
{
//开始进行渲染窗口的背景
using (Image backGroupImage = VagueRecall.Properties.Resources.Sec)
{
//清空当前的背景
e.Graphics.Clear(Color.Black);
//绘制图片并缩放.
Rectangle srcRect = new Rectangle(0, 0, backGroupImage.Width, backGroupImage.Height);
//设置目标区域
//Rectangle desRect = new Rectangle(0, 0, e.ClipRectangle.Width, e.ClipRectangle.Height);
Rectangle desRect = new Rectangle(0, 0, 480, 122);
desRect.Location = new Point(0, 0);
//绘制背景图片.
e.Graphics.DrawImage(backGroupImage, desRect, srcRect, GraphicsUnit.Pixel);
}
}
}