?
Solved

Bitbln

Posted on 1997-04-12
16
Medium Priority
?
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 5
16 Comments
 
LVL 3

Expert Comment

by:mheacock
ID: 1335355
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
ID: 1335356
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
ID: 1335357
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:mheacock
ID: 1335358
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
ID: 1335359
Here are my points (and a little more...)
0
 
LVL 3

Accepted Solution

by:
mheacock earned 240 total points
ID: 1335360
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
ID: 1335361
If you have comments, please ask.
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335362
You also stated you want to move the bitmap?  Do you mean around the form??  Or within a TImage (like a sprite)??
0
 

Author Comment

by:cobian
ID: 1335363
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
ID: 1335364
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
ID: 1335365
If you have questions when you begin implementing all this, feel free to ask them.
0
 

Author Comment

by:cobian
ID: 1335366
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
ID: 1335367
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
ID: 1335368
Thanx!!!!
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335369
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
ID: 1335370
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month10 days, 17 hours left to enroll

770 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