Delphi - Jpeg en DataSet

 
Vista:

Jpeg en DataSet

Publicado por Delfino (1216 intervenciones) el 04/12/2003 12:58:36
Como casi todo el mundo tiene problemas para visualizar imagenes jpeg insertadas como Blob en un Dataset, aqui hay un codigo compacto y eficaz para hacerlo, se chequean 2 bytes al principio del campo Blob para saber el tipo de imagen, asi no se necesita ningun truco para chequearlo:

procedure TForm1.DataSourceDataChange(Sender: TObject; Field: TField);
var bs : TStream; jp : TJpegImage; buff: Word;
begin
bs := DataSet.CreateBlobStream(CampoBlob,bmRead);
try
bs.Seek(0,soFromBeginning);
if bs.Read(buff,2) > 0 then
begin
bs.Seek(0, soFromBeginning);
case buff of
$4D42: image1.Picture.Bitmap.LoadFromStream(bs);
$0000: image1.Picture.Icon.LoadFromStream(bs);
$0001,$CDD7: image1.Picture.Metafile.LoadFromStream(bs);
$D8FF: begin
jp := TJpegImage.Create;
jp.LoadFromStream(bs);
image1.Picture.Assign(jp);
FreeAndNil(jp);
end
else image1.Picture := nil;
end;
end;
finally
FreeAndNil(bs);
end;
end;

A mi me funciona muy bien, espero q sirva a quien lo necesite..
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder