ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Save Multiple Images to One Database Blob Field
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

DelphiLover

USA
7 Posts

Posted - Sep 13 2018 :  10:06:36  Show Profile  Reply
Hello,
I have a table as below
Table Name: Documents
Fields: DOCUMENT_ID, DOCUMENT_PHOTO

DOCUMENT_PHOTO should keep up to 100 Images

Is it possible to save multiple images to one database blob field?
I had looked into Demos but I can't find any example

What I do now


procedure TfrmDocumentInfo.FormCreate(Sender: TObject);
begin
  DM.PhotoIEDBMultiBitmab := TIEDBMultiBitmap.Create(DM.dsDocuments,
    'DOCUMENT_PHOTO', '');
  DM.PhotoIEDBMultiBitmab.FollowDBCursor := True;
  PhotoMView.SetExternalMBitmap(DM.PhotoIEDBMultiBitmab);
end;


procedure TfrmDocumentInfo.FormDestroy(Sender: TObject);
begin
  PhotoMView.SetExternalMBitmap(nil);
  FreeAndNil(DM.PhotoIEDBMultiBitmab);
end;


procedure TfrmDocumentInfo.PhotoMViewImageSelect(Sender: TObject; idx: Integer);
var
  MemStream: TMemoryStream;
begin
  if PhotoMView.SelectedImage = -1 then
    Exit;

  PhotoView.ClearAll();
  PhotoMView.CopyToIEBitmap(idx, PhotoView.IEBitmap);
  PhotoView.Update;
  PhotoView.Fit;

  // Get File Size
  MemStream := TMemoryStream.Create;
  PhotoView.IO.SaveToStreamJpeg(MemStream);
  lblSize.Caption := 'File Size: ' + ConvertBytes(MemStream.Size);
  FreeAndNil(MemStream);
end;


and another side problem With above code I get error "NULL BLOB"

and I don't know if it's the right way to do it. I hope to find help here
Thank you

xequte

39141 Posts

Posted - Sep 13 2018 :  22:21:32  Show Profile  Reply
Hi

Firstly, why store all the photos in the same blob? For performance reasons, you would be much better to have a sub-table that stored each image in its own blob (as reading a single blob to access one image out of a hundred would be taxing).

If you do have good reason to store them all the in same blob, then your options are:

- Save in a multi-frame format, such as TIFF (with the appropriate compression for the image type). Use a TIEMultiBitmap and save it to your blob stream:

https://www.imageen.com/help/TIEMultiBitmap.Write.html


- Save in an ImageEn format. You can use SaveSnapshot to output all images in a TIEMultiBitmap to a stream

https://www.imageen.com/help/TIEMultiBitmap.SaveSnapshot.html


- Build the stream yourself. You can use TIEDBBitmap.Write to output a series of images to a stream, and Read to load from the current stream position. Naturally you will some method to move to the correct position in the stream to load a specific image

https://www.imageen.com/help/TIEDBBitmap.Read.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

39141 Posts

Posted - Sep 13 2018 :  22:23:19  Show Profile  Reply
A "Null Blobk" exception means the blob field it is reading at the current cursor position has a size of zero. So check your database.



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

DelphiLover

USA
7 Posts

Posted - Sep 14 2018 :  05:06:19  Show Profile  Reply
Hi
I wanted to use sub-tables but I Have many tables with blob field so using sub-tables will lead to have too many tables for blobs, some of blobs contains only 2-10 images,
However I will try your solution and If I have performance issues I will use sub-tables for blob more than 10 Images, Thank you very much.
Go to Top of Page

DelphiLover

USA
7 Posts

Posted - Sep 14 2018 :  05:34:04  Show Profile  Reply
I get "NULL BLOB" error when I try to set external Bitmab

PhotoMView.SetExternalMBitmap(DM.PhotoIEDBMultiBitmab);


How can I avoid it?
Go to Top of Page

xequte

39141 Posts

Posted - Sep 14 2018 :  19:47:21  Show Profile  Reply
Hi

I don't know your requirements, so you might have your reasons, but if you have too many tables that only store blob info, you could just use a single table that stores blobs, the blob type (i.e. what table it is related too) and the index.

If you want don't want the Null Blob exception to surface, handle it with a try-except block.





Nigel
Xequte Software
www.imageen.com
Go to Top of Page

DelphiLover

USA
7 Posts

Posted - Sep 14 2018 :  20:11:28  Show Profile  Reply
Hi

I'm still thinking to find new best table structure that will fit my needs, Thank you for your suggestion.

If I handle it with a try-except block the error still there but it will not appear
and the ImageEnMView will not be linked to IEDBMultiBitmab

So it's not the right solution, also I had used it before with other applications with same way I had never faced this exception
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: