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
 Copy Image from one ImageEnDBView to another
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Patrick Quinn

United Kingdom
81 Posts

Posted - May 23 2012 :  15:11:26  Show Profile  Reply
Hi Nigel and Fabrizio

I am using two ImageEnDBView controls, one to store a full size image in one field in a table, the other to store a thumbnail (to later populate an ImageEnMview).

I am trying to copy the image from the first to the second (and after that resize it) but cannot make it copy and save in the table.

I load an image into the first, this saves it in the database without problems.
I copy it's image to the other with:

ImageEnDBView2.IEBitmap.Assign(ImageEnDBView1.IEBitmap);

You can see the image in the second DBView, but it does not store it in the table.

How to you assign an image and make it store in the table?

I am doing something stupid, but what?

ImageEn version 4.1.0

regards

Patrick

xequte

38616 Posts

Posted - May 23 2012 :  19:02:09  Show Profile  Reply
Hi Patrick

You do not need to use a visual control (TImageEnDBView) if all you want to is assign an image into a blob. You can do this in code using a memory stream:


// Inserts the specified bitmap into the database at the current cursor position
function TIEFunctions.InsertBlob_Bitmap(var ABitmap: TBitmap;
                                        TheTable: TTable; AField: TBlobField; 
                                        sFileExt: string): boolean;
begin
  try
    TempImageEnIO.Params.SetDefaultParams;
    TempImageEnIO.attachedbitmap := ABitmap;
    Result := InsertBlob_ImageEnIO(TempImageEnIO, TheTable, AField, sFileExt); 
  finally
    TempImageEnIO.attachedbitmap := nil;
  end;
end;

// Inserts the bitmap of the specified ImageEnIO into the database at the current cursor position
function TIEFunctions.InsertBlob_ImageEnIO(var AnImageEnIO: TImageEnIO; 
                                           TheTable: TTable; AField: TBlobField; 
                                           sFileExt: string): boolean;
var
  MemStream: TMemoryStream;
  BlobStream: TBlobStream;
  SaveFileType: TIOFileType;
begin
  Result := true;

  SaveFileType := IEExtToFileFormat(sFileExt);

  if SaveFileType = iounknown then
  begin
    Result := False;
    exit;
  end;

  try
    MemStream := TMemoryStream.create;
    try
      AnImageEnIO.SaveToStream(MemStream, SaveFileType);
      MemStream.position := 0;

      TheTable.Edit;
      BlobStream := TBlobStream.create(AField, bmwrite);
      try
        MemStream.SaveToStream(BlobStream); 
      finally
        BlobStream.Free;
        TheTable.Post;
      end;

    finally
      MemStream.free;
    end;
  except
    Result := false;
  end;
end;


Note: Untested with standard DB controls

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

Patrick Quinn

United Kingdom
81 Posts

Posted - May 24 2012 :  09:34:11  Show Profile  Reply
Thanks, Nigel.

I'll try this:

1) Create an IEBitmap, attach it to an ImageEnIO
2) Load an image via the ImageEnIO
3) Assign this image to the blob in the table's main 'image' field using the ImageEnIO.
4) Resize the IEBitmap with IEBitmap.Resize to (say) 150x150 for use as thumbnails
5) Assign this to the blob in the table's 'Thumb' field using the ImageEnIO.

I think this should do what I want.

I'm not using the BDE, but Absolute Database instead (no installation program needed for finished .exe).

http://www.componentace.com/bde_replacement_database_delphi_absolute_database.htm

It seems to work fine with ImageEn.
It works with a standard Delphi DataSource and most Delphi data controls will work with it. (some very slight differences, it uses a TABSBlobStream instead of TBlobStream for instance)

regards

Patrick
Go to Top of Page

Patrick Quinn

United Kingdom
81 Posts

Posted - May 26 2012 :  05:11:23  Show Profile  Reply
Hi Nigel, thanks for pointing me in the right direction.

I've got that code all working, it saves a full sized image as a blob, resize/resamples to thumbnail size (150x150 pixels) then saves that as a blob in another field.

Loading a TImageENView from small thumbnails rather than full sized images speeds up loading considerably.

regards

Patrick
Go to Top of Page

xequte

38616 Posts

Posted - May 26 2012 :  23:10:42  Show Profile  Reply
Hi Patrick

Another good way to speed up JPEG loading (if you are not displaying it full size) is to use TIOParams.JPEG_Scale:

http://www.imageen.com/help/TIOParams.JPEG_Scale.html

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

Patrick Quinn

United Kingdom
81 Posts

Posted - May 28 2012 :  15:33:49  Show Profile  Reply
In the past (before I started using ImageEn) I have used the Delphi TImage JPEG scale to make thumbnails. I prefer this way, though. It is really quick (even when tested on a netbook with a slow processor).

Also, some images I'm storing are scans of text, so I use png rather than JPEG, to avoid the artefacts that mess text up.

Also, most computers now have massive hard drives so file size is not much of an issue.



regards

Patrick
Go to Top of Page

1995steve

USA
2 Posts

Posted - Aug 19 2014 :  09:47:17  Show Profile  Reply
If you are using an ADODataSet Instead of a TTable this will save a JPG to an image field

TBlobField( TblImg.FieldByName( '<fieldName>' )).LoadFromFile(<FileName>);

Donald S. Bossen
Go to Top of Page

xequte

38616 Posts

Posted - Aug 27 2014 :  16:37:05  Show Profile  Reply

Note: Generic DB read/write functions are now available in iexHelperFunctions.pas (see your ImageEn source folder).

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: