Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » DBISAM Technical Support » Support Forums » DBISAM General » View Thread |
Messages 1 to 10 of 10 total |
Loading a .JPG into a Blob field ... again |
Thu, Jul 26 2007 8:28 PM | Permanent Link |
"Jeff Cook" | Hi
I've trolled around looking for an answer to this one and concluded that I must be missing something basic. I'm trying to load a JPEG into a field, plus a thumbnail in another field. It is failing on the marked statement with the message "Bitmap image is not valid." regardless of which JPEG file I select - and why is the thing worried about bitmap when I'm working with JPEG? The code is below:- procedure TfrmMain.btnLoadPhotoClick(Sender: TObject); const MaxHeight: integer = 50; var oJPG: TJPEGImage; oBmp: TBitmap; iHeight, iWidth: integer; Stream: TMemoryStream; iniFile: TInifile; begin oJPG := TJPEGImage.Create; oBmp := TBitmap.Create; Stream := TMemoryStream.Create; iniFile := TInifile.Create('JvDBUltimGrid.ini'); try OpenPictureDlg.InitialDir := iniFile.ReadString('Images', 'Folder', ''); if (OpenPictureDlg.Execute) then begin try begin iniFile.WriteString('Images', 'Folder', ExtractFilePath(OpenPictureDlg.FileName)); oJPG.LoadFromFile(OpenPictureDlg.FileName); tblPhotosOriginalFileLocation.AsString := OpenPictureDlg.FileName; end except MessageDlg('Error while trying to open ' + OpenPictureDlg.FileName + '.', mtError, [mbOK], 0); exit; end; Stream.Position := 0; oJPG.SaveToStream(Stream); tblPhotosImage.LoadFromStream(Stream); <<< ERROR HERE!!!!<<<<<<<<< oBmp.Width := (oJPG.Width * MaxHeight) div oJPG.Height; oBmp.Height := MaxHeight; oBmp.Canvas.StretchDraw(Rect(0, 0, oBmp.Width - 1, oBmp.Height - 1), oJPG); oJPG.Assign(oBmp); oJPG.Compress; Stream.Clear; Stream.Position := 0; oJPG.SaveToStream(Stream); tblPhotosThumbNail.LoadFromStream(Stream); end; finally oBmp.Free; oJPG.Free; Stream.Free; iniFile.Free; end; end; =============================== Cheers Jeff -- Jeff Cook Aspect Systems Ltd www.aspect.co.nz + Joan and Jeff Cook The Cooks Oasis www.cookislandsoasis.com |
Thu, Jul 26 2007 9:08 PM | Permanent Link |
"Jeff Cook" | Oops, forgot ...
DBISAM v3.30, Delphi 6 -- Jeff Cook Aspect Systems Ltd www.aspect.co.nz + Joan and Jeff Cook The Cooks Oasis www.cookislandsoasis.com |
Thu, Jul 26 2007 9:58 PM | Permanent Link |
"Jeff Cook" | Further info. If I comment out the offending line, it goes ahead and succesfully loads the other blob field with the resized image. I can export the resulting field with DBSYS and the exported file opens successfully as a smaller .jpg. Very weird! -- Jeff Cook Aspect Systems Ltd www.aspect.co.nz + Joan and Jeff Cook The Cooks Oasis www.cookislandsoasis.com |
Thu, Jul 26 2007 10:17 PM | Permanent Link |
"Jeff Cook" | Jeff Cook wrote:
> > Further info. > > If I comment out the offending line, it goes ahead and succesfully > loads the other blob field with the resized image. I can export the > resulting field with DBSYS and the exported file opens successfully as > a smaller .jpg. > > Very weird! Yet more info ... I have workaround the problem by simply using a LoadFromFile for blob field. It means I load it twice, once for the field and once for resizing but ... -- Jeff Cook Aspect Systems Ltd www.aspect.co.nz + Joan and Jeff Cook The Cooks Oasis www.cookislandsoasis.com |
Fri, Jul 27 2007 5:02 AM | Permanent Link |
"Frans van Daalen" | "Jeff Cook" <jeffc@aspect.co.nz> wrote in message news:3834E25C-C1A2-43B8-9E65-539F1F1DF8C3@news.elevatesoft.com... > Jeff Cook wrote: > >> >> Further info. >> >> If I comment out the offending line, it goes ahead and succesfully >> loads the other blob field with the resized image. I can export the >> resulting field with DBSYS and the exported file opens successfully as >> a smaller .jpg. >> >> Very weird! > > Yet more info ... I have workaround the problem by simply using a > LoadFromFile for blob field. It means I load it twice, once for the > field and once for resizing but ... > > -- what happens if you reset the stream position just before the "tblPhotosImage.LoadFromStream(Stream); <<< ERROR HERE!!!!<<<<<<<<<" |
Fri, Jul 27 2007 2:48 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Jeff,
<< It is failing on the marked statement with the message "Bitmap image is not valid." regardless of which JPEG file I select - and why is the thing worried about bitmap when I'm working with JPEG? >> Is there a TDBImage control attached to the tblPhotosImage TField ? What data type is that TField defined as ? -- Tim Young Elevate Software www.elevatesoft.com |
Fri, Jul 27 2007 2:48 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Frans,
<< what happens if you reset the stream position just before the >> The stream position should be set to 0 automatically by the LoadFromStream method - it calls the TStream.CopyFrom method with a 0 parameter. -- Tim Young Elevate Software www.elevatesoft.com |
Fri, Jul 27 2007 3:23 PM | Permanent Link |
"Jeff Cook" | Frans van Daalen wrote:
> > > what happens if you reset the stream position just before the > > "tblPhotosImage.LoadFromStream(Stream); <<< ERROR HERE!!!!<<<<<<<<<" That's it. Perfect! Meitaki maata Jeff -- Jeff Cook Aspect Systems Ltd www.aspect.co.nz + Joan and Jeff Cook The Cooks Oasis www.cookislandsoasis.com |
Fri, Jul 27 2007 3:57 PM | Permanent Link |
"Jeff Cook" | Tim Young [Elevate Software] wrote:
> Jeff, > > << It is failing on the marked statement with the message "Bitmap > image is not valid." regardless of which JPEG file I select - and why > is the thing worried about bitmap when I'm working with JPEG? >> > > Is there a TDBImage control attached to the tblPhotosImage TField ? > What data type is that TField defined as ? There is a TJvDBImage connected to the field and it is defined as a blob. As per my reply to Frans - setting the stream position to zero seems to have so solved the problem. Code now looks like:- if (OpenPictureDlg.Execute) then begin try begin iniFile.WriteString('Images', 'Folder', ExtractFilePath(OpenPictureDlg.FileName)); oJPG.LoadFromFile(OpenPictureDlg.FileName); tblPhotosOriginalFileLocation.AsString := OpenPictureDlg.FileName; end except MessageDlg('Error while trying to open ' + OpenPictureDlg.FileName + '.', mtError, [mbOK], 0); exit; end; oJPG.SaveToStream(Stream); Stream.Position := 0; tblPhotosImage.LoadFromStream(Stream); .. .. .. Cheers Jeff -- Jeff Cook Aspect Systems Ltd www.aspect.co.nz + Joan and Jeff Cook The Cooks Oasis www.cookislandsoasis.com |
Mon, Jul 30 2007 8:06 PM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Jeff,
<< There is a TJvDBImage connected to the field and it is defined as a blob. As per my reply to Frans - setting the stream position to zero seems to have so solved the problem. >> That's really weird - the LoadFromStream method should set the position to 0 before loading. -- Tim Young Elevate Software www.elevatesoft.com |
This web page was last updated on Sunday, May 19, 2024 at 08:46 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |