Windows移动应用程序背景问题

时间:2009-08-05 12:27:37

标签: windows compact-framework mobile pocketpc

我是新的移动开发,我正在开发Windows Mobile 6.0 Os和CF 2.0上的概念验证应用程序

我尝试使用Adobe Photoshop为我的应用程序设计新的backgorund,我根据Dr.Luiji的{{3}在codeproject.com上找到了关于使用Pinvoke api解决windows mobile全屏问题和app图像背景问题的教程}

当我尝试添加一些渐变图像的表单背景时。 iPhone UI in Windows Mobile article

图像质量似乎很差。但我试图在我的表格背景中添加另一个背景图片,看起来不错。

alt text http://img268.imageshack.us/img268/8482/ppc2.jpg

我不明白问题在哪里,我试图将我的backgorund图像改为bmp,png,jpg等,但它仍然很差。我用photoshop做错了什么? (注意:另一方面,我还没有在真正的pocketpc上试过这个设计。不是吗?)

然而, 我的另一个真正的问题是移动表单上的OnPaintBackground方法。 正如我上面所写,我使用Pinvoke api绘制全屏表格。以下是示例代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Microsoft.WindowsMobile.Status;

namespace My_Mobile
{
    public partial class MainForm : Form
    {

        Globals _globals = new Globals();
        Graphics _gxBuffer;
        Bitmap _offsetBitmap;  

        Bitmap backgroundVertical = null;
        public MainForm()
        {
            InitializeComponent();
            backgroundVertical = new Bitmap(_globals.ApplicationPath + @"\Resources\wallpaper.bmp");
            _offsetBitmap = new Bitmap(this.Width, this.Height);

        }

        private void MainForm_Load(object sender, EventArgs e)
        {

        }


        protected override void OnPaintBackground(PaintEventArgs e)
        {
            //base.OnPaintBackground(e);
        }


        protected override void OnPaint(PaintEventArgs e)
        {
                _gxBuffer = Graphics.FromImage(_offsetBitmap);

                _gxBuffer.Clear(this.BackColor);

                _gxBuffer.DrawImage(backgroundVertical, 0, 0);
                this.Invalidate();

                e.Graphics.DrawImage(_offsetBitmap, 0, 0);

        }

    }
}

我正在尝试在表单上添加一些控件,然后当应用程序第一次运行时控件显示为透明。如果您尝试将光标移动到这些控件上,则这些控件将正常转换。

我可以做些什么来解决这个问题?

谢谢。

alt text http://img199.imageshack.us/img199/9812/ppc3.jpg

1 个答案:

答案 0 :(得分:0)

首先,您的代码需要进行一些清理:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Microsoft.WindowsMobile.Status;

namespace My_Mobile
{
    public partial class MainForm : Form
    {

        Globals _globals = new Globals();

        Bitmap backgroundVertical = null;
        public MainForm()
        {
            InitializeComponent();
            backgroundVertical = new Bitmap(_globals.ApplicationPath + @"\Resources\wallpaper.bmp");
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
        }


        protected override void OnPaintBackground(PaintEventArgs e)
        {
            //base.OnPaintBackground(e);
        }


        protected override void OnPaint(PaintEventArgs e)
        {
             using (Bitmap buffer = new Bitmap(this.Width, this.Height))
             using (Graphics gfx = Graphics.FromImage(buffer))
             {
                gfx.Clear(this.BackColor);
                gfx.DrawImage(backgroundVertical, 0, 0);
                //this.Invalidate();  Don't call Invalidate here, it shouldn't be needed
                e.Graphics.DrawImage(buffer, 0, 0);
             }
        }
    }
}

Chris Tacke的经典博客谈论CF中的位图。你需要小心:

http://blog.opennetcf.com/ctacke/PermaLink,guid,987041fc-2e13-4bab-930a-f79021225b74.aspx

毕竟,我不确定你的问题是什么。你可以再详细一点吗?例如,我没有看到任何P / Invokes,但是你说你用了一些。他们在哪儿?