Solved

GetDiBits()  How ?

Posted on 1997-08-19
8
552 Views
Last Modified: 2010-04-06
How do I use GetDiBits() to load a bitmap into a
TImage.Picture.Bitmap so that I can still use the
Canvas, and Canvas tools etc.

I was advised to use GetDiBits() because I need
True Color, and Timage.Picture.Bitmap is usally
only in 256 colors.

John.
0
Comment
Question by:jturpin
  • 7
8 Comments
 
LVL 3

Expert Comment

by:mirek071497
ID: 1341978
When You use  GetDIBits(....BitInfo: BitmapInfo...) then at first you must parse BitmapInfo structure to check how You'r bitmap is retrived. (of course i think so all structures was allocated).
Full example is rather big because there is 5 possible cases but for 24bbp bitmap it is very easy and full described if Help files.

When You use SetDIBits then you must paint Bitmap (for example with BitBlt).

Tell me more what you need then i write simple example.
0
 
LVL 1

Author Comment

by:jturpin
ID: 1341979
I have an application which loads a bitmap into
TImage.TPicture.TBitmap. I then allow the user to do some
processing of this picture using some tools I provide,
PenTool, RectangleTool etc. These changes are recorded
on TImage.Canvas. The user can also select and zoom
parts of the picture, and then edit the zoomed section.
I am using TCanvas.StretchDraw to zoom.

I now have a bigger 24 bit true color picture that I want
to process. However when I load it the colors are off - the
sky is green and the picture is much darker.

This distortion is either the result of Delphi's TBitmap
not being to handle the larger picture, or it is the
result of my video card not being able to handle the picture.
I have heard arguments on both sides.

If it is TCanvas, then I have been told to use GetDiBits.
Therefore I need to know how to load the bitmap using
GetDiBits so I can still use my tools.

If it is the video card I need a new card.

0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1341980
OK but i have not time today. I write for you tommorow, but you probably have graphics.pas where are GetDIBits is used. Try watch at borland source (for example TBitmap.ReadStream) or wait to tomorrow.
0
 
LVL 3

Accepted Solution

by:
mirek071497 earned 100 total points
ID: 1341981
Hi jturpin !

I write simple example of loading 24bbp bitmaps and i found so borland made very big mistake. When bitmap is 24bbp then there are no Palette information. You can use 24bbp bitmaps if you add one line to Graphics.pas

function PaletteFromW3DIB(const BI: TBitmapInfo): HPALETTE;
.....
if Colors <= 2 then Exit;
if Bi.bmiHeader.biBitCount=24 then exit;
....

when you change this and recompile library then all work's fine
you can load bitmap wit 24bbp.

Of course you must have partial source which came with delphi. If You hav'nt this source you can do this in another way :

procedure TForm1.Button1Click(Sender: TObject);
var NewDC : HDC;
  Bmp : HBitmap;
begin
  MyBmp := TBitmap.Create;
  MyBmp.LoadFromFile ('D:\MYPIC.BMP');
  NewDC := CreateCompatibleDC( PaintBox1.Canvas.Handle );
  Bmp := CreateCompatibleBitmap( PaintBox1.Canvas.Handle, MyBmp.Width, MyBmp.Height );
 SelectObject( NewDC, Bmp );
{ here you must do trick !!!!! }
{  SetDIBits from loaded Bitmap }
  BitBlt( PaintBox1.Canvas.Handle, 0, 0, 200, 200, NewDC, 0, 0, SrcCopy );
  DeleteObject( Bmp.Handle );
  DeleteDC( NewDC );
  MyBmp.Free;
end;

I write code for SetDIBits approx after 2 hour.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 3

Expert Comment

by:mirek071497
ID: 1341983
Hi Jturpin

Sorry but if you can't load 24bpp bitmap in design time without mesage Out Of Memory you must made changes in Graphics.pas or increase points becaus in this problem you need read bitmap in you'r own procedures. All call to Bitmap.handle will generate Out Of Memory and you can't use this.

1. Made changes in Graphics.Pas and then try this :
procedure TForm1.Button2Click(Sender: TObject);
var NewDC : HDC;
begin
  MyBmp := TBitmap.Create;
  MyBmp.LoadFromFile ('D:\MYPIC.BMP');
  NewDC := CreateCompatibleDC( PaintBox1.Canvas.Handle );
  SelectObject( NewDC, MyBmp.Handle );
  BitBlt( PaintBox1.Canvas.Handle, 0, 0, MyBmp.Width, MyBmp.Height, NewDC, 0, 0, SrcCopy );
  DeleteObject( MyBmp.Handle );
  DeleteDC( NewDC );
  MyBmp.Free;
end;

2.Increase you'r points and i can write procedure to display 24bbp bitmap but point1 is better because you can use Bitmap.handle.
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1341984
oh ! i just read you'r comment. You must set display for more than 256 colors !
WHen you can load bitmaps and work on them then you have probably better version of delphi (i have old delphi2). If You'r display was cofigured for 256 color's you can't see 24bbp in good colors (of course you can do own procedure to change palette). Try change settings of display to HiColor or True color.
If You can't do this you need new video card.
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1341985
Hi jturpin.
I now buy Delphi3 and i sow so ther is some differences with Delphi2 and Delphi3 with subject :"Bitmaps and Palettes".
Tell me what version of Delphi you have and what you need more.
0
 
LVL 3

Expert Comment

by:mirek071497
ID: 1341982
Hi Jturpin !
I have now Delphi1, 2 and 3 so tell me which version you use.
I write working example for you.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

9 Experts available now in Live!

Get 1:1 Help Now