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 !!!
cobianAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mheacockCommented:
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.
0
mheacockCommented:
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.
0
cobianAuthor Commented:
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
0
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

mheacockCommented:
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.
0
cobianAuthor Commented:
Here are my points (and a little more...)
0
mheacockCommented:
This code is from a component I am currently writing.

// here's the declarations
  bmpBG:         TBitmap;
  bmpBuff:       TBitmap;

// here's one of the drawing functions.
procedure CSimGaugeDevice.DrawGauge(const i_ggGauge: CGauge; const i_fData, i_fMin, i_fMax: Single);
var
  rectGauge: TRect;
  fPercent:  Single;
begin
  if ((i_ggGauge.Enabled <> True) or (Width = 0) or (Height = 0)) then
    Exit;
  bmpBuff.Canvas.Brush.Color := i_ggGauge.Color;
  rectGauge.TopLeft.X := i_ggGauge.Left;
  rectGauge.TopLeft.Y := i_ggGauge.Top;
  rectGauge.BottomRight.X := (rectGauge.TopLeft.X + i_ggGauge.Width) - 1;
  rectGauge.BottomRight.Y := (rectGauge.TopLeft.Y + i_ggGauge.Height) - 1;
  try
    if (i_fData <= i_fMin) then
      fPercent := 0
    else
      fPercent := (i_fData - i_fMin) / (i_fMax - i_fMin);
  except on EZeroDivide do
    fPercent := 0;
  end;
  if (i_ggGauge.GaugeType = gt_Vertical) then
    rectGauge.TopLeft.Y := rectGauge.TopLeft.Y +
                          (Round((1 - fPercent) * (rectGauge.BottomRight.Y - rectGauge.TopLeft.Y  + 1)))
  else
    rectGauge.BottomRight.X := rectGauge.BottomRight.X -
                              (Round((1 - fPercent) * (rectGauge.BottomRight.X - rectGauge.TopLeft.X + 1)));
  bmpBuff.Canvas.FillRect(rectGauge);
end; {procedure CSimGaugeDevice.DrawGauge}

//here are the calls.
  bmpBG.LoadFromFile('background.bmp'); //load background bitmap, you only need to do this once
  bmpBuff.Width := bmpBG.Width; //set width and height, you only need to do this once per loadfromfile
  bmpBuff.Height := bmpBG.Height;
  bmpBuff.Canvas.Draw(0, 0, bmpBG); //copy background to drawing buffer
  DrawGauge(ggsGauges.UserGauge1, KWDData.UserData1, KWDData.EngineerMin, KWDData.EngineerMax); //here we will draw a gauge on the buffer
// the following statements are identical.
  Image1.Canvas.Draw(0, 0, bmpBuff);  //use only one of these statements, both are identical.  Draw is siply a wrapper for BitBlt
  BitBlt(Image1.Canvas.Handle,
         0, 0,
         bmpBuff.Width - 1, bmpBuff.Height - 1,
         bmpBuff.Canvas.Handle,
         0, 0,
         SRCCOPY);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mheacockCommented:
If you have comments, please ask.
0
mheacockCommented:
You also stated you want to move the bitmap?  Do you mean around the form??  Or within a TImage (like a sprite)??
0
cobianAuthor Commented:
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.


0
mheacockCommented:
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.
0
mheacockCommented:
If you have questions when you begin implementing all this, feel free to ask them.
0
cobianAuthor Commented:
OK TBitmap is not a component,but TImage is it,right?...
Then I can use this stuff in my OnMouseMove event...
0
mheacockCommented:
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.


0
cobianAuthor Commented:
Thanx!!!!
0
mheacockCommented:
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.
0
mheacockCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.