Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Gráficos (https://www.clubdelphi.com/foros/forumdisplay.php?f=8)
-   -   Mostrar una imagen JPG (https://www.clubdelphi.com/foros/showthread.php?t=39365)

Doraemon 18-01-2007 00:00:31

Mostrar una imagen JPG
 
Hola a todos,... estuve buscando en el foro y encontre la manera de mostrar en un TImage una imagen almacenada en un campo de access tipo OLE... creo haber buscado lo suficiente como para pedir a alguien me pueda decir porque me sale el error "Invalid class typecast" en la linea donde hago el "SaveToStream"...¿¿???

Aqui esta el codigo:

Código Delphi [-]
procedure TfraDefinicionNotificadores.MostrarFoto;
var   MS: TMemoryStream;   IB: TJPEGImage;   sSQL: String;
begin   with ADQFotoX do     begin       SQL.Clear;       sSQL:= 'SELECT Foto FROM Notificadores WHERE CodigoNotificadores=' + ADONotificadoresCodigoNotificadores.AsString;
      SQL.Add(sSQL);
      Open;
      (FieldByName('Foto') as TGraphicField).SaveToStream(MS);
    end;
  IB.LoadFromStream(MS);
  imgFoto.Picture.Assign(IB);
  MS.Free;
  IB.Free;
end;

Desde ya muchas gracias... espero haber dicho todo como para recibir alguna ayudita ;)

Doraemon 19-01-2007 04:10:36

Ya encontre la solucion...
 
Estuve buscando mas ejemplos y pude solucionar mi problema...

Acá pongo el codigo que quedo finalmente:

Código Delphi [-]procedure TfraDefinicionNotificadores.MostrarFoto; var bS : TADOBlobStream; Pic : TJpegImage; begin bS := TADOBlobStream.Create(ADONotificadoresFoto, bmRead); try bS.Seek(JpegStartsInBlob(ADONotificadoresFoto), soFromBeginning); Pic:=TJpegImage.Create; try if Length(ADONotificadoresFoto.AsString)>0 then begin Pic.LoadFromStream(bS); imgFoto.Picture.Graphic:=Pic; end else imgFoto.Picture.Assign(nil); finally Pic.Free; end; finally bS.Free end; end;


Código Delphi [-]function TfraDefinicionNotificadores.JpegStartsInBlob( PicField: TBlobField): integer; var bS : TADOBlobStream; buffer : Word; hx : string; begin Result := -1; bS := TADOBlobStream.Create(PicField, bmRead); try while (Result = -1) and (bS.Position + 1 < bS.Size) do begin bS.ReadBuffer(buffer, 1); hx:=IntToHex(buffer, 2); if hx = 'FF' then begin bS.ReadBuffer(buffer, 1); hx:=IntToHex(buffer, 2); if hx = 'D8' then Result := bS.Position - 2 else if hx = 'FF' then bS.Position := bS.Position-1; end; //if end; //while finally bS.Free end; //try end;


La franja horaria es GMT +2. Ahora son las 01:54:03.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi