windows Mobile 开发中使用嵌入的图片等资源

在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);
                }
            }

        }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值