none
c#在PDA上用directx方式顯示影像的問題 RRS feed

  • 問題

  •  

    大家好…想請問一下有關directX的方法…我有去看官網的一個簡單範例…

     

    它只是將背景清除為藍色…現在我想要在它的背景貼上一張圖…發生了問題…

     

    簡單來講就是device.CopyRects(mysurface, myrect, dessurface, dispoint);這個方法不會用…

     

    我的想法是這樣的…開啟一個device…再創建一個顯示圖surface…再將這個surface覆蓋在device

     

    的特定位置…便可以顯示圖…下面的code…寫的有問題…麻煩有這樣經驗的人…指導我一下…謝謝^^

     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.WindowsMobile.DirectX;
    using Microsoft.WindowsMobile.DirectX.Direct3D;

    using System.IO;
    using System.Reflection;
    //using Microsoft.Samples.MD3DM;

    namespace DeviceApplication5
    {
        public partial class Form1 : Form
        {
            private Device device;
            private Device srcdevice;
            private PresentParameters pres;
            Bitmap mybitmap;
            Surface mysurface;
            Surface dessurface=null;
            Rectangle myrect;
            Point dispoint;
            public Form1()
            {
                InitializeComponent();
                // Set the initial size of our form
                this.ClientSize = new System.Drawing.Size(400, 300);
                // And it's caption
                this.Text = "D3D Tutorial 01: CreateDevice";
                InitializeGraphics();

            }       
            public bool InitializeGraphics()
            {
                try
                {            
                    mybitmap = new Bitmap("Program Files\\live.bmp");
                    // Now let's setup our D3D stuff
                    PresentParameters presentParams = new PresentParameters();
                    presentParams.Windowed = true;
                    presentParams.SwapEffect = SwapEffect.Discard;
                    device = new Device(0, DeviceType.Default, this, CreateFlags.None, presentParams);

     

                    PresentParameters srcpresentParams = new PresentParameters();
                    srcpresentParams.Windowed = true;
                    srcpresentParams.SwapEffect = SwapEffect.Discard;
                    srcdevice = new Device(0, DeviceType.Default, this, CreateFlags.None, srcpresentParams);


                    mysurface = new Surface(srcdevice, mybitmap, Pool.SystemMemory);      

                    dessurface = device.CreateImageSurface(176, 144, Format.R8G8B8);                
                    return true; 

                }
                catch (DirectXException)
                {
                    return false;
                }
            }
            private void Render()
            {
                if (device == null)
                    return;

                //Clear the backbuffer to a blue color
                device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);
                //Begin the scene
                device.BeginScene();   

                myrect = new Rectangle(0, 0, 176, 144);
                dispoint = new Point(10, 10);        

                device.CopyRects(mysurface, myrect, dessurface, dispoint);
                // Rendering of scene objects can happen here
                //End the scene
                device.EndScene();
                device.Present();
            }
            protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
            {
                this.Render(); // Render on painting
            }
        }
    }

    2008年8月2日 上午 07:38

所有回覆

  •  

    沒有人在PDA上…用Directx的方式來顯示影像哦!!

     

    如果有的人…麻煩指導我一下…大力感謝^^

    2008年8月5日 下午 12:13