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
Solved

BLOB fields and bitmaps

Posted on 1998-07-16
6
292 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
  • 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
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

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help on VBSCript Font and color 1 112
select query - oracle 16 100
how can i search if string exist in array ? 3 63
Firemonkey android show image from resource ? 1 46
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…
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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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