Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 11 total
Thread Displaying picture on form
Tue, Dec 23 2008 12:37 AMPermanent Link

Pat
Hi all,

I wish to display a picture on my Asset form. I located some code from

http://delphi.about.com/od/database/l/aa030601d.htm

and tried to modify it for DBISAM v4 (Delphi 6).
- The table name is tblAsset and
- the field name (a blob) is Picture
- DBISAMImage is a TImage

I get an error on compile: Too many actual parameters  on the line
bS.Seek(JpegStartsInBlob(tblAssetPicture), soFromBeginning);

I have added the function line after the Public (the website demo did
not mention to add this). If I remove this line, I get errror
Undeclared identifier 'JpegStartsInBlob'.

I have added "jpeg" to the Uses (after the Implementation)

Any help appreciated (its probably not a DBISAM problem, but I'll
start here).


Regards,
Pat

//---------------------------------------------------
 public
   { Public declarations }

   function JpegStartsInBlob:integer;
..
..

implementation

uses jpeg;

procedure TfrmAsset.btnShowImageClick(Sender: TObject);
var
 bS  : TDBISAMBlobStream;
 Pic : TJpegImage;
begin
 bS := TDBISAMBlobStream.Create(tblAssetPicture, bmRead);
 try
   bS.Seek(JpegStartsInBlob(tblAssetPicture), soFromBeginning);
   Pic:=TJpegImage.Create;
   try
    Pic.LoadFromStream(bS);
    DBISAMImage.Picture.Graphic:=Pic;
   finally
    Pic.Free;
   end;
 finally
   bS.Free
 end;

end;

function JpegStartsInBlob(PicField:TBlobField):integer;
var
bS     : TADOBlobStream;
buffer : Word;
hx     : string;
begin
Result := -1;
bS := TADOBlobStream.Create(PicField, bmRead);
try
 while (Result = -1) and (bS.Position + 1 < bS.Size) do begin
  bS.ReadBuffer(buffer, 1);
  hx:=IntToHex(buffer,2);
  if hx = 'FF' then begin
    bS.ReadBuffer(buffer, 1);
    hx:=IntToHex(buffer,2);
    if hx = 'D8' then Result := bS.Position - 2
    else if hx = 'FF' then bS.Position := bS.Position-1;
  end;//if
 end;//while
finally
 bS.Free
end; //try

end;
//---------------------------------------------------
Tue, Dec 23 2008 4:51 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Pat


If what you've posted is what you have then

1) you need to add TfrmAsset. to function JpegStartsInBlob(PicField:TBlobField):integer;
2) you're still referencing ADOBlobstream in the functon

3) It all seems a bit over ornate to me. If you've stuffed a jpeg into a blob field then why do you have to go hunting around for where it starts. I don't know about ADO (and its a long time since I tried it with DBISAM) but I'd try assuming that what you put in is what you get out.

Roy Lambert [Team Elevate]
Tue, Dec 23 2008 7:23 AMPermanent Link

Pat
Hi Roy,

>2) you're still referencing ADOBlobstream in the functon
yeah I have since changed that

>3) It all seems a bit over ornate to me. If you've stuffed a jpeg into a blob field then why do you have to go hunting around for where it starts. I don't know about ADO (and its a long time since I tried it with DBISAM) but I'd try assuming that what you put in is what you get out.
I am just following the tutorial, its the only code I have found as
yet that handles images. I would like to find some other examples if
they are out there.

I did get it to compile by placing the Function before the Procedure,
but I am still trying to get it to run.

Pat
Tue, Dec 23 2008 8:20 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Pat


I just did a quick search of these newsgroups and found

var
TempBlobStream: TDBISAMBlobStream;
TempJPEGImage: TJPEGImage;
begin
  { Assume a TDBISAMTable component called MyDBISAMTable
  and a BLOB field in that table called MyBlobField,
  and a TImage component called MyImage }
  with MyDBISAMTable do
   begin

TempBlobStream:=TDBISAMBlobStream.Create(TBlobField(FieldByName('MyBlobField
')),bmRead);
   try
  TempJPEGImage:=TJPEGImage.Create;
  try
     TempJPEGImage.LoadFromStream(TempBlobStream);
   MyImage.Picture.Assign(TempJPEGImage);
  finally
   TempJPEGImage.Free;
  end;
   finally
    TempBlobStream.Free;
   end;
 end;

There are probably more examples in there somewhere.

Roy Lambert [Team Elevate]
Tue, Dec 23 2008 2:22 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Pat,

<< If I remove this line, I get errror Undeclared identifier
'JpegStartsInBlob'. >>

Get rid of that function reference, it isn't needed.  DBISAM stores JPEGs as
straight-up binary storage with no headers, etc.  ADO/Access and the BDE use
headers for graphic storage in BLOB fields.

Roy's code will do what you need.

--
Tim Young
Elevate Software
www.elevatesoft.com

Fri, Dec 26 2008 7:45 PMPermanent Link

Pat
..... just going on a bit further, I have the image displaying on the
form OK now.

What I would like to do is be able to CLICK the image on the form and
have this image open up in Windows' default image viewer i.e. Windows
Picture and Fax Viewer. This just shows a bigger view of it.

To accomplish this I guess I:
a) stream the blob field into a jpeg file and save it in a folder
b) find what is the default image viewer
c) open up the viewer showing my stored jpeg

On the DBISAM side, is saving the image to a disk jpeg file the way to
go? or is there another way?

Regards,
Pat

PS hope there are not too many hangovers out there
Sat, Dec 27 2008 4:12 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Pat


1. Since you're reading the image into a stream to start with keep that stream available and use its savetofile method

2. Make a note of the file name you use

3. Use ShellExecute to open in the default viewer

Alternatively simply allow users to resize the image you're displaying, or show it in a dedicated form which can be resized and have the TImage (or whatever you use) set Align := alClient.

Roy Lambert [Team Elevate]
Sat, Dec 27 2008 5:49 PMPermanent Link

Pat
Roy,

>1. Since you're reading the image into a stream to start with keep that stream available and use its savetofile method
>
>2. Make a note of the file name you use
>
>3. Use ShellExecute to open in the default viewer
>
>Alternatively simply allow users to resize the image you're displaying, or show it in a dedicated form which can be resized and have the TImage (or whatever you use) set Align := alClient.

thanks for the ideas (didn't even think about the dedicated form)

Pat
Sun, Dec 28 2008 4:25 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Pat


A dedicated form is a lot easier when you have users who's default jpeg app is different eg Irfanview, Corel Photo-Paint Adobe Photoshop etc. ShellExecute will get up whatever is the default but get ready for "why does it look different on his/hers". Also with a dedicated form the users have only the ability you give them to alter the image - think "I changed this but "yourapp" altered it back" type of question.

Roy Lambert [Team Elevate]
Sun, Dec 28 2008 6:32 PMPermanent Link

Pat
..... just going on a bit further, again, when I reverse engineer the
table (with the image in a blob field) the blob data does not appear
to be generated.

If this is the case, how can I create the blob data (the file
MyTable.blb)? I have a procedure that generates 'sample' data and a
pic in the sample data would be nice.

Regards,
Pat
Page 1 of 2Next Page »
Jump to Page:  1 2
Image