Do a Bitmap from a Direct3D Surface.

Started by
0 comments, last by NeoAsimov 20 years, 3 months ago
Hello, I have a problem and I wish that you''ll be able to answer me. Im trying to do a Bitmap with a Direct3D Surface. I think im able to retreive it but the there is a little bug: check at this picture: http://www.decatomb.com/screenshots/screenshot.bmp The background of the device is Blue. After, I put a 600x600 black bitmap on the surface, after I put another 300x300 red bitmap on the surface. Theorically, the bitmap that I created previously with the blue background is supposed to be full blue, but as we can see, he is not when I draw it on the surface. Any idea? Is this a device property problem? The code: // Create a PresentParameters object PresentParameters presentParams = new PresentParameters(); // Don''t run full screen presentParams.Windowed = true; // Discard the frames presentParams.SwapEffect = SwapEffect.Discard; presentParams.PresentFlag = Microsoft.DirectX.Direct3D.PresentFlag.LockableBackBuffer; // Instantiate a device Device device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); while(this.Created) { if (device == null) break; //Clear the backbuffer to a blue color (ARGB = 000000ff) device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0); //Begin the scene device.BeginScene(); // Rendering of scene objects can happen here /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// Bitmap b2 = new Bitmap("test300x300Red.bmp"); Bitmap b3 = new Bitmap("test600x600.bmp"); // Surface s = device.GetRenderTarget(0); Surface s = device.GetBackBuffer(0, 0, Microsoft.DirectX.Direct3D.BackBufferType.Mono); GraphicsStream gstream = s.LockRectangle(LockFlags.None); Bitmap b = new Bitmap(350, 350, 350*/*BYTES_PER_PIXEL*/4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, gstream.InternalData); s.UnlockRectangle(); Graphics g = s.GetGraphics(); g.DrawImage(b3, 0, 0); // Draw the 600x600 black bitmap on the surface g.DrawImage(b2, 0, 0); // Draw the 300x300 red bitmap on the surface g.DrawImage(b, 50, 20); // Draw the blue bitmap created with the surface''s background s.ReleaseGraphics(); /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// //End the scene device.EndScene(); device.Present(); Application.DoEvents(); } Thank alot for your help, Salutations,
Advertisement
here

350*/*BYTES_PER_PIXEL*/4

350 should be the surface width OR the locked area width, not the desired bitmap width.

no surface would have a width of 350 in d3d, since it''s not a power of 2, that''s why ur getting the garbage... because 350 isn''t the real stride of the locked surface area.

This topic is closed to new replies.

Advertisement