Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Managed DirectX Simply (But Fast) BMP Display and update....

Status
Not open for further replies.

Insider1984

Technical User
Feb 15, 2002
132
0
0
US
Hi there. I've been using GDI to display a bitmap that I update line by line for a certain application as the lines come in. The problem is that GDI is slow when the image gets big and of course GDI is becoming emulation in Vista.

I'm looking at Managed DirectX to do this. I have some knowledge and examples of setting up a primary surface which has a secondary surface on it which is assigned to a bitmap.

Now, I'm trying to do exactly what I do in GDI where I'll lock the area of the bitmap I want to modify, I write to the memory location I want to change then release the bitmap and expect to see an update.

I do not see the update and I have also tried a number of "Redraw" and other commands into the Direct X to display it.

Here are some snips of code for testing only, excuse the messy, bad programming styles.


update function
Code:
        BitmapData display = graphics.z.LockBits(new Rectangle(0, a,400, 1), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
        BitmapData imageIn = b.LockBits(new Rectangle(0, a, 400, 1), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
        unsafe
        {
            byte* imgPtr = (byte*)(display.Scan0);
            byte* imgPtr1 = (byte*)(imageIn.Scan0);
            //for (int i = 0; i < display.Height; i++)
            //{
                for (int j = 0; j < display.Width; j++)
                {
                    *imgPtr = *imgPtr1;
                    imgPtr += 1;
                    imgPtr1 += 1;
                }
                imgPtr += display.Stride - display.Width * 3;
                imgPtr1 += display.Stride - display.Width * 3;
            //}
        }

        b.UnlockBits(display);
        graphics.z.UnlockBits(imageIn);
        a++;

creation of surfaces:
Code:
        SurfaceDescription desc = new SurfaceDescription();
        SurfaceCaps caps = new SurfaceCaps(); 

        localClipper = new Clipper(localDevice);
        localClipper.Window = owner;

        desc.SurfaceCaps.PrimarySurface = true;
        surfacePrimary = new Surface(desc, localDevice);
        //surfacePrimary = new Surface(@"C:\c.bmp", desc, localDevice);
        surfacePrimary.Clipper = localClipper;
        
        desc.Clear();
        desc.SurfaceCaps.OffScreenPlain = true;
        desc.Width = surfacePrimary.SurfaceDescription.Width;
        desc.Height = surfacePrimary.SurfaceDescription.Height;

        surfaceSecondary = new Surface(z, desc, localDevice);
        surfaceSecondary.FillStyle = 0;
        desc.Width = 100;
        desc.Height = 50;
        surfaceText = new Surface(desc, localDevice);
        surfaceText.ForeColor = Color.Red;

=====================
Insider
4 year 'on the fly' programmer
C, C++, C#, MFC, Basic, Java ASP.NET
 
I'm in no way a DirectX developer but I did look at it a while ago. I believe that when you modify a surface you have to redraw the entire object again. So you would modify your surface as needed and then do a full redraw.

It's the same as minimizing a DirectX application and then maximizing it again - you apparently have to start the redraw from scratch.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top