Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm tryin to do some Aplha blending with directdraw surfaces. I could not figure out how to do it using DirectDraw so I thought maybe I can do it manually.

 

I tried to copy a portion of the suface into a bitmap object but it does not seem to work.

 

Here is some code, btw it's in c#

//Bitmap to hold the copied data
Image _bitmap = new Bitmap(mPortion.Width, mPortion.Height);
Graphics _g1 = Graphics.FromImage(_bitmap);
IntPtr _dc1 = _g1.GetHdc();

//Get the surface's dc
IntPtr _surfacedc = _surface.GetDc();
IntPtr _dc2 = CreateCompatibleDC(_surfacedc);

//Copy the portion rectangle
BitBlt(_dc1, mPortion.X, mPortion.Y, mPortion.Width, mPortion.Height, _dc2, 0, 0, 0x00CC0020);

//Save the bitmap to test whether anything was copied
_bitmap.Save("bah.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

//Clean			
_g1.ReleaseHdc(_dc1);
_surface.ReleaseDc(_surfacedc);
DeleteDC(_dc2);

 

Nothing is being copied to the bitmap, can anyone help?

Is there an easier way of doing this?

Posted

Your code seems to be GDI+ not DirectDraw

What do you mean by alpha blending (sorry - i'm fairly new to this myself)

 

From what i can tell from what limited GDI knowledge i have your code is trying to...

  • Open an image and copy it to a surface
  • Then create another surface of equal proportions to the previous surface.
  • Then copy a select part of your orignial image onto the new surface and save as a new file (bah.bmp)

I don't know where the alpha blending comes in as i don't know what you mean - could you give a description?.

But i do see one small problem....

At no point in your code do i see you opening an image and storing it as bitmap....

I see you creating a bitmap object but only defining it's size - not it's content

 

As i said previously i have no knowledge of GDI really so all this "getHdc" & "dc" stuff doesn't mean anything to me.

Posted

There definitely is *no* alpha-blending in DD. I spent a loooong time investigating the matter.

 

The closest I came was this, which is pretty darned similar to what you're doing. It does, in fact, sidestep to GDI+ rather than doing it in DirectDraw:

http://www.xtremedotnettalk.com/showthread.php?t=80726

 

The big downside of that approach is that it resulted in a ~93% performance degridation when run once on every frame. Unless you can cache the resulting blended image for multiple uses, you will not want to do that.

 

In order to get alpha blending working, we had to rewrite our graphics engine in Direct3D (from DirectDraw), and this has set us back weeks.

 

Hope that helps.

 

-Hiro_Antagonist

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...