Solved

Bitbln

Posted on 1997-04-12
16
191 Views
Last Modified: 2012-05-04
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 !!!
0
Comment
Question by:cobian
  • 11
  • 5
16 Comments
 
LVL 3

Expert Comment

by:mheacock
Comment Utility
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
 
LVL 3

Expert Comment

by:mheacock
Comment Utility
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
 

Author Comment

by:cobian
Comment Utility
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
 
LVL 3

Expert Comment

by:mheacock
Comment Utility
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
 

Author Comment

by:cobian
Comment Utility
Here are my points (and a little more...)
0
 
LVL 3

Accepted Solution

by:
mheacock earned 120 total points
Comment Utility
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
 
LVL 3

Expert Comment

by:mheacock
Comment Utility
If you have comments, please ask.
0
 
LVL 3

Expert Comment

by:mheacock
Comment Utility
You also stated you want to move the bitmap?  Do you mean around the form??  Or within a TImage (like a sprite)??
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:cobian
Comment Utility
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
 
LVL 3

Expert Comment

by:mheacock
Comment Utility
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
 
LVL 3

Expert Comment

by:mheacock
Comment Utility
If you have questions when you begin implementing all this, feel free to ask them.
0
 

Author Comment

by:cobian
Comment Utility
OK TBitmap is not a component,but TImage is it,right?...
Then I can use this stuff in my OnMouseMove event...
0
 
LVL 3

Expert Comment

by:mheacock
Comment Utility
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
 

Author Comment

by:cobian
Comment Utility
Thanx!!!!
0
 
LVL 3

Expert Comment

by:mheacock
Comment Utility
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
 
LVL 3

Expert Comment

by:mheacock
Comment Utility
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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now