Solved

GetDiBits()  How ?

Posted on 1997-08-19
8
570 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi IDE crash without error message ... 7 99
TEMBEDDEDWB how can i change its user agent ? 8 70
Adoquery sql  left join does not work 25 99
Delphi...Split view - idea? 1 90
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

820 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