Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

GetDiBits()  How ?

Posted on 1997-08-19
8
Medium Priority
?
606 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
[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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 3

Accepted Solution

by:
mirek071497 earned 200 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

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.

Question has a verified solution.

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

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…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

719 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