Link to home
Start Free TrialLog in
Avatar of cobian
cobian

asked on

Bitbln

Hi! I'm a beginer in Delphi.
Can somebody send me an exemple of how I can use the function BitBln to move a simple TBitmap
(without flickers)? Can I do that in any other way?
Thanx !!!
Avatar of mheacock
mheacock

In Delphi you don't need to use the explicit API call, you can use the Copy method of TBitmaps.

You know about double buffering?  This is what will eliminate your flickers.

You need a TBitmap buffer where all your drawing will happen.  After all drawing is done on this buffer, you will copy it to  your screen buffer (a Canvas, either of the form or a TImage).

If this isn't enough, please comment.  But it should get you started.
If you bump the points up to 100, I will send you some sample code.  Not much I can do beyond what I've already told you for only 25 pts.
Avatar of cobian

ASKER

OK I bump the points up to 100.Send me the code,but I can only evaluate your answer as Poor.If I like your code and it is good explicative I´ll evaluate it as Good (And maybe excellent if you tell me about Btnbln too)
Thanks
BtnBln??  BitBln??  You are talking about BitBlt, right?

You can grade my answer as poor, as you did, but you aren't going to get much more for 25 points.  From anyone.  It isn't worth our time.

Your points are still at 25.  No code until it is increased to 100.  I've done what you are asking many many times. I can give you code for the Copy method and sample code for BitBlt.
Avatar of cobian

ASKER

Here are my points (and a little more...)
ASKER CERTIFIED SOLUTION
Avatar of mheacock
mheacock

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you have comments, please ask.
You also stated you want to move the bitmap?  Do you mean around the form??  Or within a TImage (like a sprite)??
Avatar of cobian

ASKER

I want to move the TBitmap with the mouse,using the events OnMouseDown,OnMouseMove and OnMouseUp around the form.I guess all this stuff must be placed into the OnMouseMove event.Is there something special I must do to make it works?
+10 points + excellent for a good answer.


Unfortunately, TBitmap is not a component, so you cannot capture MouseEvents for it.

But...if you draw the bitmap on the form's canvas, you can capture mouse events for the form.  Therefore for MouseDown events, you would check to see if the mouse coords are within the coords of the bitmap on the form (top, left, width, height).  When the user releases the mouse button, you simply redraw (bitblt) the bitmap on the form's canvas at the apprpriate point.  To make your moves more accurate, you'll even have to calculate the offset of the mouse click from the bitmaps (0, 0) coordinates and then redraw the bitmap based on this offset where the mouse button is released.

Whew!  Happy programming.
If you have questions when you begin implementing all this, feel free to ask them.
Avatar of cobian

ASKER

OK TBitmap is not a component,but TImage is it,right?...
Then I can use this stuff in my OnMouseMove event...
If you move (drag) a TImage, there's no guarantee that it won't flicker.

Actually it will flicker...but this is kind of out of our control, since this is Borland code.

I will experiment and get back to you.


Avatar of cobian

ASKER

Thanx!!!!
Still no luck...you may have to resort to drawing the bitmap on the form's canvas and calculating mouse coordinates to for the dragging/dropping like I detailed above.  The code is not overly complex and the results would exaclty what you are after.

Not that you want to spend more points...but if you have fifty to spare, you can ask a specific question on how to move a TImage around a form (perhaps in a for...loop) without it flickering.
I'd ask it for you (because now I'm curious of the answer), but I'm flat out of points.

I suspect it is either impossible without rewriting the TImage source or very simple...perhaps setting a single proprty.  Either way, it should be an easy question.
Wait a day or two on the new question thing as I will try and get an answer for you myself.  I feel a little guilty that my answer did not solve your exact problem...of course you didn't state it as a TImage problem...but I feel a little guilty nonetheless.