Solved

BLOB fields and bitmaps

Posted on 1998-07-16
6
295 Views
Last Modified: 2013-12-03
Hi,

I am trying to copy a bitmap from a Blob field into a BitMap variable and then display it in an image control. Why does the following not work?

var
  BitImage : TBitmap;
  PicStream : TMemoryStream;


begin
  PicStream := TMemoryStream.Create;
  BitImage := Tbitmap.Create;
  try
    TBlobField(Table1.FieldByName('Graphic')).SaveToStream(PicStream);
    BitImage.LoadFromStream(PicStream);
    //Process bitmap image here........

    //Display processed image
    Image1.Picture.Bitmap := BitImage;
  finally
    PicStream.Free;
    BitImage.Free;
  end;
end;

I does not crash, just does not do anything!

I think I am missing something fundamental here.

Thanks

Chris
0
Comment
Question by:ChrisBerry
[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
  • 3
  • 3
6 Comments
 
LVL 3

Accepted Solution

by:
vladika earned 50 total points
ID: 1357961
I think you forget update PicStream.Position
before BitImage.LoadFromStream(PicStream);

so try such
............
TBlobField(Table1.FieldByName('Graphic')).SaveToStream(PicStream);
PicStream.Position := 0;
BitImage.LoadFromStream(PicStream);
...........

0
 
LVL 3

Expert Comment

by:vladika
ID: 1357962
Or you can use Assign method

Image1.Picture.Bitmap.Assign(TBlobField(Table1.FieldByName('Graphic')));

It call TBlobField.AssignTo method and
AssignTo call SaveToBitmap private method
(see in source)

0
 

Author Comment

by:ChrisBerry
ID: 1357963
You are quite right, however this leads me on to a supplemetary question.

I am using the DBDEMOS database BIOLIFE table for the graphic and when I made the change to the program as suggested it then told me that it was an invalid bitmap.

What type of graphic is in this database and how is it handled in the above code?

Regards

Chris
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ChrisBerry
ID: 1357964
Thanks

Regards

Chris

0
 
LVL 3

Expert Comment

by:vladika
ID: 1357965
You are right.
There is small error/bug.

Sometimes TGraphicHeader can appears before image
So modify procedure as

{ Paradox graphic BLOB header }

type
  TGraphicHeader = record
    Count: Word;                { Fixed at 1 }
    HType: Word;                { Fixed at $0100 }
    Size: Longint;              { Size not including header }
  end;

procedure TForm1.Button1Click(Sender: TObject);
var
  BitImage : TBitmap;
  PicStream : TMemoryStream;
  Header: TGraphicHeader;
  Size: Integer;
begin
  PicStream := TMemoryStream.Create;
  BitImage := Tbitmap.Create;
  try
    TBlobField(Table1.FieldByName('Graphic')).SaveToStream(PicStream);

    PicStream.Position := 0;
    Size := PicStream.Size;
    if Size >= SizeOf(TGraphicHeader) then
    begin
      PicStream.Read(Header, SizeOf(Header));
      if (Header.Count <> 1) or (Header.HType <> $0100) or
        (Header.Size <> Size - SizeOf(Header)) then
        PicStream.Position := 0;
    end;

    BitImage.LoadFromStream(PicStream);
    Image1.Picture.Bitmap := BitImage;
  finally
    PicStream.Free;
    BitImage.Free;
  end;
end;

I found its algorithm in the TBlobField.SaveToBitmap private method (db.pas)

0
 

Author Comment

by:ChrisBerry
ID: 1357966
Thanks again,

Regards

Chris

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

739 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