--> Saving Graphicsor picture to the Table on delphi 7 | Delphi Tips Trick

For Newbie

Tuesday 15 November 2011

Saving Graphicsor picture to the Table on delphi 7

| Tuesday 15 November 2011


Tricks to save data in the form of an image (graphic) into the field.

The way used is the same with the standard procedure when you want to save the new data (insert, edit) on the field. Due to a BLOB data type then use the Table command on Assign.

For example, you want to keep the existing graphics on TImage (image1) into a BLOB fields (in the following example, the name field is a pic):
procedure TForm1.Button1Click (Sender: TObject);
begin
   if Image1.Picture.Graphic <> nil then
   begin
     with ADOTable1 do
     begin
       Insert;
       FieldByName ('pic'). Assign (Image1.Picture.Graphic);
       Post;
     end;
   end;
end;

Of particular interest in saving the image into the field is of type / format of image you want to save, whether as JPEG / JPG, PNG, GIF or BMP. If you want the entire data on the field 'pic' is merely a graphic of type JPEG / JPG, then you must convert existing graphic on the image1 to TJPEGImage then stored into the field. This will facilitate you to a TImage when displaying graphics, because the graphic to be shown it is definitely a TJPEGImage, so without the need to detect the type of image to be displayed. But all depends on the orientation of the program you are awake.

Related Posts

No comments: