Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Gráficos (https://www.clubdelphi.com/foros/forumdisplay.php?f=8)
-   -   cargar a un DBImage un jpg (https://www.clubdelphi.com/foros/showthread.php?t=28646)

fergape 27-12-2005 14:42:39

cargar a un DBImage un jpg
 
tengo esto en el codigo

DBImage1.Picture.Bitmap.LoadFromFile(OpenPictureDialog1.FileName);

y me cargar un bmp a la base de datos sin problemas. el tema esta en que no puedo cargar un JPG. cuando se abre el OpenPictureDialog y elijo un JPG y me salta el siguiente error "Project1.exe raised exception class EInvalidGraphic with message 'Bitmap image is not valid'", me imagino que de esta forma no soporta bmp, pero mi pregunta es como se hace para levantar un JPG? y guardarlo en la Base de datos?

Neftali [Germán.Estévez] 27-12-2005 15:31:05

¿Qué base de datos estás utilizando?
Haz una busqueda en los foros por "DBImage jpg" (sin comillas) y seuramente encontrarás lo que necesitas.

fergape 27-12-2005 15:35:57

estoy utilizando SQLServer 2000 y el campo Foto es de tipo image

Loviedo 27-12-2005 16:18:05

Esto me funciona con Firebird.

Código Delphi [-]
procedure TFFicha.cargafoto; 
var
  BS: TStream;
  Graphic: TGraphic;
begin
 if FDM.qunafichafoto.isnull then // FDM: TDataModule   
  Image1.picture.graphic:=nil     // Image1: Timage
else
  begin
    BS := FDM.ficha.CreateBlobStream(FDM.qunaficha.FieldByName('foto'), bmRead);
    try
      Graphic := TJPEGImage.Create;
      try
        Graphic.LoadFromStream(BS);
        Image1.Picture := nil;
        Image1.picture.graphic := Graphic;
      Finally
        Graphic.Free;
      end;
    Finally
      BS.free;
    end;
  end;
end;
procedure TFFicha.SpeedButton1Click(Sender: TObject);
begin
  if OpenPictureDialog1.execute then
   if OpenPicturedialog1.filename <> '' then
     begin
       Image1.Picture.LoadFromFile(OpenPicturedialog1.filename);
       if not (FDM.IBT1.InTransaction) then
         FDM.IBT1.StartTransaction;
       try
         FDM.MODIFOTO.Parambyname('mcod').asinteger:=FDM.Qfichascodigo.asinteger; // MODIFOTO: procedimiento almacenado
         FDM.MODIFOTO.Parambyname('mfoto').LoadFromFile(OpenPictureDialog1.filename,ftBlob);
         FDM.MODIFOTO.ExecProc;
         FDM.IBT1.Commit;
       except
         FDM.IBT1.Rollback;
         raise Exception.Create('Error al grabar foto');
       end;
       FDM.Qfichas.open;        
     end;
end;
procedure TFFicha.SpeedButton3Click(Sender: TObject);
begin
  Image1.Picture := nil;
  if not (FDM.IBT1.InTransaction) then
    FDM.IBT1.StartTransaction;
  try
    FDM.MODIFOTO.Parambyname('mcod').asinteger:=FDM.Qfichascodigo.asinteger;
    FDM.MODIFOTO.Parambyname('mfoto').value:=null;
    FDM.MODIFOTO.ExecProc;
    FDM.IBT1.Commit;
  except
    FDM.IBT1.Rollback;
    raise Exception.Create('Error al eliminar foto');
  end;
  FDM.Qfichas.open;
end;

Saludos.

fergape 27-12-2005 19:20:00

gracias Loviedo!


La franja horaria es GMT +2. Ahora son las 13:12:41.

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