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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 How to save Thumbnail to DB fileld using SQL?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
yogiyang Posted - Apr 19 2016 : 02:35:00
Hello,

I have build a small utility. In this utility I have a need to save a thumbnail of the original image. As I am using SQLite for my DB I am using Insert SQL statement to insert various data in DB along with the other data I need to save the image data to a blob field.

If we were using the standard Datasource then it would be easy as we will just have to link Datasource to the control. But in my case I am NOT using Datasrouce component.

I am just using the SQLConnection and SQLQuery components.

I am loading data using code and saving data using code. That is by generating a SQL Query and direct executing it using SQLQuery component.

Any ideas as to how to achieve this please.

TIA

Yogi Yang


Yogi Yang
3   L A T E S T    R E P L I E S    (Newest First)
yogiyang Posted - Apr 23 2016 : 00:07:43
Hello,

Hope this will help others here...

Finally!! I have managed to solve my problem using following code.

I don't know if this is the best thing or not but it just works as expected..!!
procedure TfrmMain.cmdSaveClick(Sender: TObject);
var
  I, ObjID: Integer;
  BookType, Orientation, LayWidth, LayHeight: Integer;
  PCount, LCount, SCount: Integer;
  LayData: String;
  SQL: String;

  ss: TStringStream;
  ms: TStream;
  ThumbnailString: String;
begin
  //First Validate data
  if cboProductType.ItemIndex < 0 then
  begin
    ShowMessage('Please select Product Type');
    cboProductType.SetFocus;
    Exit;
  end;
  if cboOrientation.ItemIndex < 0 then
  begin
    ShowMessage('Please select Orientation');
    cboOrientation.SetFocus;
    Exit;
  end;

  if StrToInt(txtPageWidth.Text) <= 0 then
  begin
    ShowMessage('Please Enter Page Width');
    txtPageWidth.SetFocus;
    Exit;
  end;

  if StrToInt(txtPageHeight.Text) <= 0 then
  begin
    ShowMessage('Please Enter Page Height');
    txtPageHeight.SetFocus;
    Exit;
  end;

  if ievMain.ObjectsCount = 0 then
  begin
    ShowMessage('There are not Layout Details to save');
    Exit;
  end;

  CalcObjOrientation; //Recalculate Obj Orientation

  ievMain.CopyObjectsToBack(true);

  if ievMain.IEBitmap.Width > ievMain.IEBitmap.Height then
    ievMain.Proc.Resample(50,-1,rfProjectBW,True)
  else
    ievMain.Proc.Resample(-1,50,rfProjectBW,True);

  ss := TStringStream.Create();
  ms := TMemoryStream.Create();

  //TIdDecoder.DecodeStream();

  ievMain.IO.SaveToStreamJpeg(ms);

  ms.Seek(0, soFromBeginning);

  ThumbnailString := TIdEncoderMIME.EncodeStream(ms);

  //ShowMessage(ThumbnailString);

  //Save data to DB here
  SQL := 'INSERT INTO [layouts] ([lay_book_type], [lay_orientation], [' +
     'lay_width], [lay_height], [lay_p_count], [lay_l_count], [lay_s_count], [' +
     'lay_data], [lay_preview]) VALUES(';
  SQL := SQL + IntToStr(cboProductType.ItemIndex + 1) + ',';
  SQL := SQL + IntToStr(cboOrientation.ItemIndex + 1) + ',';
  SQL := SQL + txtPageWidth.Text + ',';
  SQL := SQL + txtPageHeight.Text + ',';
  SQL := SQL + txtPCount.Text + ',';
  SQL := SQL + txtLCount.Text + ',';
  SQL := SQL + txtSCount.Text + ',';

  LayData := '';

  for I := 0 to ievMain.ObjectsCount - 1 do
  begin
    ObjID := ievMain.GetObjFromIndex(I);
    LayData := LayData + IntToStr(ievMain.ObjLeft[ObjID]) + ',';
    LayData := LayData + IntToStr(ievMain.ObjTop[ObjID]) + ',';
    LayData := LayData + IntToStr(ievMain.ObjWidth[ObjID]) + ',';
    LayData := LayData + IntToStr(ievMain.ObjHeight[ObjID]) + #13;
  end;  //for I := 0 to ievMain.ObjectsCount - 1 do

  SQL := SQL + Chr(39) + LayData + Chr(39) + ',';
  SQL := SQL + Chr(39) + ThumbnailString + Chr(39);

  SQL := SQL + ');';

  //Execute Query to insert Data in DB
  SQLConnection1.ExecuteDirect(SQL);
  LoadDataInGrid;

  ShowMessage('Layout saved in DB');

end;


TO get the code to work I had to add these units also:
IdCoder, IdCoderMIME


HTH



Yogi Yang
yogiyang Posted - Apr 20 2016 : 01:27:05
Hello,

I am using following code to save data:

//Save data to DB here
  SQL := 'INSERT INTO [layouts] ([lay_book_type], [lay_orientation], [' +
     'lay_width], [lay_height], [lay_p_count], [lay_l_count], [lay_s_count], [' +
     'lay_data]) VALUES(';
  SQL := SQL + IntToStr(cboProductType.ItemIndex + 1) + ',';
  SQL := SQL + IntToStr(cboOrientation.ItemIndex + 1) + ',';
  SQL := SQL + txtPageWidth.Text + ',';
  SQL := SQL + txtPageHeight.Text + ',';
  SQL := SQL + txtPCount.Text + ',';
  SQL := SQL + txtLCount.Text + ',';
  SQL := SQL + txtSCount.Text + ',';

  LayData := '';

  for I := 0 to ievMain.ObjectsCount - 1 do
  begin
    ObjID := ievMain.GetObjFromIndex(I);
    LayData := LayData + IntToStr(ievMain.ObjLeft[ObjID]) + ',';
    LayData := LayData + IntToStr(ievMain.ObjTop[ObjID]) + ',';
    LayData := LayData + IntToStr(ievMain.ObjWidth[ObjID]) + ',';
    LayData := LayData + IntToStr(ievMain.ObjHeight[ObjID]) + #13;
  end;  //for I := 0 to ievMain.ObjectsCount - 1 do

  SQL := SQL + Chr(39) + LayData + Chr(39);
  SQL := SQL + ');';
  // Have to work out as to how to save a thumbnail of the whole image in DB using SQL statement.
  //Execute Query to insert Data in DB
  SQLConnection1.ExecuteDirect(SQL);
  LoadDataInGrid;

  ShowMessage('Layout saved in DB');



Yogi Yang
xequte Posted - Apr 19 2016 : 16:36:30
Hi Yogi

Can you not use something like:

    // Load from blob
    aMemStream := TMemoryStream.create;
    try         
      aField.SaveToStream( aMemStream );
      aMemStream.Position := 0;
      LoadFromStream(aMemStream);
    finally
      aMemStream.free;
    end;


    // Save To Blob
    aMemStream := TMemoryStream.create;
    try
      SaveToStream(aMemStream, aFileType);
      aMemStream.Position := 0;

      aBlobStream := aField.DataSet.CreateBlobStream( aField, bmWrite );
      try
        aMemStream.SaveToStream(aBlobStream);
      finally
        aBlobStream.Free;
      end;

    finally
      aMemStream.free;
    end;


(from iexHelperFunctions.pas)


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com