Solved

GetDiBits()  How ?

Posted on 1997-08-19
8
565 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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