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

x
?
Solved

BLOB fields and bitmaps

Posted on 1998-07-16
6
Medium Priority
?
299 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 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
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…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

730 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