Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

storing .jpeg in database

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
hi,

i want to store a jpeg image in my file(blob). It works ok when storing a .bmp image.Is it possible to store a jpeg or do some sort of coding to convert the jpeg image into .bmp format and then post it.

can some one help me wqith the coding?

Thanks.
 
An easier way of storing Jpegs I have found is to create a subdirectory where you store your table and save all jpegs into it. In your table just store the jpeg filenames and you can instantly view a list of all available jpeg images. Arte Et Labore
 
Code:
procedure SavePhoto(DSet: TDataSet; fldName: String; Img: TImage);
var
  jpgPhoto   : TJPEGImage;
  stPhoto    : TStream;
  PhotoField : TBlobField;
begin
  if Assigned(DSet)then
   PhotoField := DSet.FieldByName(fldName) as TBlobField
  else
   Exit;
  if Assigned(PhotoField)then
   stPhoto := DSet.CreateBlobStream(PhotoField, bmWrite)
  else
   Exit;
  try
    if Assigned(stPhoto)
    begin
      jpgPhoto := TJPEGImage.Create;
      jpgPhoto.Assign(Img.Picture.Bitmap);
      jpgPhoto.Compress;
      if (not((DSet.State = dsEdit)or(DSet.State = dsInsert)))then
       DSet.Edit;
      jpgPhoto.SaveToStream (stPhoto);
      jpgPhoto.Free;
    end
    else
     Exit;
  finally
    stPhoto.Free;
  end;
end;
Hope that helps.

--- markus
 
you can store the path and the filename of your bitmaps to a string and saved it it your table... its more convenient since the filesize of your wud be smaller.
 
Yes, the filesize would be lesser, but you you won't be able to move your files to another server or directory without updating you database. Well,i think xxbx just should decide for himself what is more important.

--- markus
 
hi
Is there a way to convert a .jpeg file to .bmp so that i can store it in a database?

Or is there another way to store .jpeg to a file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top