Subject | RE: [IBO] BLOBS |
---|---|
Author | Thomas Steinmaurer |
Post date | 2003-05-27T07:22:12Z |
Alfred,
for updating and loading a JPEG image. You might get the idea.
procedure TIB_CustomJPEGImage.SysUpdateData;
var JPEG: TJPEGImage;
begin
with DataLink do begin
if ControlIsModified then begin
if Assigned( Field ) and Field.IsBlob and not FIsUpdating then begin
with Field as TIB_ColumnBlob do begin
FIsUpdating := true;
try
if Assigned( Picture.Graphic ) and ( not Picture.Graphic.Empty ) then begin
if Picture.Graphic is TJpegImage then begin
Assign( Picture.Graphic );
end else begin
(* Convert to JPEG *)
JPEG := TJPEGImage.Create;
try
JPEG.Assign(Picture.Graphic);
Assign(JPEG);
finally
JPEG.Free;
end;
end;
end else begin
Clear;
end;
finally
FPictureLoaded := true;
FIsUpdating := false;
end;
end;
end;
end;
end;
end;
procedure TIB_CustomJPEGImage.LoadPicture;
var JPEG: TJPEGImage;
BlobStream: TStream;
begin
if not FPictureLoaded and not FIgnorePictureChange then
begin
FIgnorePictureChange := true;
try
if Assigned( Field ) and not Field.IsNull and Field.IsBlob then begin
JPEG := TJPEGImage.Create;
try
BlobStream := DataLink.Dataset.CreateBlobStream(Field, bsmRead);
try
JPEG.LoadFromStream(BlobStream);
Picture.Assign(JPEG);
finally
BlobStream.Free;
end;
finally
JPEG.Free;
end;
end else begin
Picture.Graphic := nil;
end;
finally
FIgnorePictureChange := false;
end;
FPictureLoaded := true;
end;
end;
Regards,
Thomas Steinmaurer
http://www.iblogmanager.com
> Can anyone put me on the right track on how to insert JPEG images in aI'm using the following two methods in my TIB_JPEGImage component
> database, and extract them to files again.
> I am having trouble with Assigning the JPEG data(in a Stream) to a column to
> update it and assigning the blob data to stream to save. Im using a query
> and would like to know how to assign the BLOB data to the BLOB field in the
> query.
for updating and loading a JPEG image. You might get the idea.
procedure TIB_CustomJPEGImage.SysUpdateData;
var JPEG: TJPEGImage;
begin
with DataLink do begin
if ControlIsModified then begin
if Assigned( Field ) and Field.IsBlob and not FIsUpdating then begin
with Field as TIB_ColumnBlob do begin
FIsUpdating := true;
try
if Assigned( Picture.Graphic ) and ( not Picture.Graphic.Empty ) then begin
if Picture.Graphic is TJpegImage then begin
Assign( Picture.Graphic );
end else begin
(* Convert to JPEG *)
JPEG := TJPEGImage.Create;
try
JPEG.Assign(Picture.Graphic);
Assign(JPEG);
finally
JPEG.Free;
end;
end;
end else begin
Clear;
end;
finally
FPictureLoaded := true;
FIsUpdating := false;
end;
end;
end;
end;
end;
end;
procedure TIB_CustomJPEGImage.LoadPicture;
var JPEG: TJPEGImage;
BlobStream: TStream;
begin
if not FPictureLoaded and not FIgnorePictureChange then
begin
FIgnorePictureChange := true;
try
if Assigned( Field ) and not Field.IsNull and Field.IsBlob then begin
JPEG := TJPEGImage.Create;
try
BlobStream := DataLink.Dataset.CreateBlobStream(Field, bsmRead);
try
JPEG.LoadFromStream(BlobStream);
Picture.Assign(JPEG);
finally
BlobStream.Free;
end;
finally
JPEG.Free;
end;
end else begin
Picture.Graphic := nil;
end;
finally
FIgnorePictureChange := false;
end;
FPictureLoaded := true;
end;
end;
Regards,
Thomas Steinmaurer
http://www.iblogmanager.com