
Cargar una Imagen en Timage desde una BD Access
#1
Escrito 15 septiembre 2009 - 09:27
Fleon xD
#2
Escrito 15 septiembre 2009 - 10:10
Pero si lo que quieres es usar el TImage, entonces este código te podría ayudar:
procedure MuestraImagen; var stImage: TStream; begin Image1.Picture := nil; stImage := Query1.CreateBlobStream(Query1_CampoImagen, bmRead); Image1.Picture.Graphic.LoadFromStream(stImage); stImage.Free; end;
Espero te sirva, saludos.

#3
Escrito 15 septiembre 2009 - 11:43
procedure TFEmpleados.DBGrid1DblClick(Sender: TObject); var No1: String; No2: Integer; stImage: TStream; begin FHuella := TFHuella.Create(self); try FHuella.lbNombre.Caption := dsEmpleados.DataSet.FieldByName('name').AsString; FHuella.lbApellido.Caption := dsEmpleados.DataSet.FieldByName('lastname').AsString; No1 := dsEmpleados.DataSet.FieldByName('code').AsString; No2 := StrToInt(No1); EHuellas.Close; EHuellas.SQL.Clear; EHuellas.SQL.Text := 'Select Huella From Huellas Where Codigo = :Cod'; EHuellas.Parameters.ParamByName('Cod').Value := IntToStr(No2); EHuellas.Open; //Cargamos la imagen de la huella en Plantilla1 stImage := TStream.Create; FHuella.Plantilla1.Picture := nil; stImage := EHuellas.CreateBlobStream(EHuellas.Fields[0], bmRead); FHuella.Plantilla1.Picture.Graphic.LoadFromStream(stImage); stImage.Free; //Fin carga FHuella.ShowModal; finally FHuella.Free; end; end;
y me da este error:
---------------------------
Debugger Exception Notification
---------------------------
Project WReporter.exe raised exception class EAccessViolation with message 'Access violation at address 004F3B4F in module 'Nominas.exe'. Read of address 00000000'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
#4
Escrito 15 septiembre 2009 - 11:46
#5
Escrito 15 septiembre 2009 - 12:47
FHuella.Plantilla1.Picture.Graphic.LoadFromStream(stImage);
Y también me pone este error:
[Warning] Empleados.pas(133): Constructing instance of 'TStream' containing abstract method 'TStream.Read'
[Warning] Empleados.pas(133): Constructing instance of 'TStream' containing abstract method 'TStream.Write'
Fleon xD
#6
Escrito 15 septiembre 2009 - 01:33
FHuella.Plantilla1.Picture.Graphic := TBitmap.Create
en tu caso sería algo como esto
procedure TFEmpleados.DBGrid1DblClick(Sender: TObject); var No1: String; No2: Integer; stImage: TStream; begin FHuella := TFHuella.Create(self); try FHuella.lbNombre.Caption := dsEmpleados.DataSet.FieldByName('name').AsString; FHuella.lbApellido.Caption := dsEmpleados.DataSet.FieldByName('lastname').AsString; No1 := dsEmpleados.DataSet.FieldByName('code').AsString; No2 := StrToInt(No1); EHuellas.Close; EHuellas.SQL.Clear; EHuellas.SQL.Text := 'Select Huella From Huellas Where Codigo = :Cod'; EHuellas.Parameters.ParamByName('Cod').Value := IntToStr(No2); EHuellas.Open; //Cargamos la imagen de la huella en Plantilla1 //stImage := TStream.Create; FHuella.Plantilla1.Picture := nil; {si es un bmp} FHuella.Plantilla1.Picture.Graphic := TBitmap.Create; {en caso de que sea un jpg FHuella.Plantilla1.Picture.Graphic := TJpegImage.Create; } stImage := EHuellas.CreateBlobStream(EHuellas.Fields[0], bmRead); FHuella.Plantilla1.Picture.Graphic.LoadFromStream(stImage); stImage.Free; //Fin carga FHuella.ShowModal; finally FHuella.Free; end; end;
así te debe correr sin problema.
saludos
#7
Escrito 15 septiembre 2009 - 01:48
Cuando no es JPEG:
---------------------------
Debugger Exception Notification
---------------------------
Project WReporter.exe raised exception class EInvalidGraphic with message 'Bitmap image is not valid'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
Cuando es JPEG:
---------------------------
Debugger Exception Notification
---------------------------
Project WReporter.exe raised exception class EJPEG with message 'JPEG error #53'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------

#8
Escrito 15 septiembre 2009 - 01:53
Hola razadi, probé y funciona cuando no hay imagen pero cuando hay me da error:
Cuando no es JPEG:
---------------------------
Debugger Exception Notification
---------------------------
Project WReporter.exe raised exception class EInvalidGraphic with message 'Bitmap image is not valid'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
Cuando es JPEG:
---------------------------
Debugger Exception Notification
---------------------------
Project WReporter.exe raised exception class EJPEG with message 'JPEG error #53'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
Solo necesitas agregar a tu uses la unidad JPEG
saludos
#9
Escrito 15 septiembre 2009 - 01:58

#10
Escrito 15 septiembre 2009 - 02:37
No habia puesto atención al código pero al parecer puedes meter allí tanto jpg como bmps, te aconsejop que agreges un campo que defina e tipo de imagen y de acuerdo a este tipo utilices el TBitmap o el TJPEGHola Poliburro, gracias por contestar, ya tenía en el uses la unidad Jpeg
saludos.
#11
Escrito 16 septiembre 2009 - 08:22
Fleon xD
#12
Escrito 16 septiembre 2009 - 09:18
Hola Poliburro, gracias de nuevo, no sé si llegué a mencionarlo, pero la imagen está guardada en binario (creo) y no con la ruta :$ :$
Fleon xD
Es que depende de como se guarde, eso es a lo que se refiere Poli