Ir al contenido


Foto

Jpeg en campo longblob de MySQL como guardar y leer la imagen


  • Por favor identifícate para responder
1 respuesta en este tema

#1 cesarfgt

cesarfgt

    Newbie

  • Miembros
  • Pip
  • 4 mensajes

Escrito 18 octubre 2011 - 02:50

Hola foreros.

Tengo el problema de no poder leer una imagen almacenada en un campo lonblob de MySQL y que se visualize en un cambpo TDBImage o TImage, solo usando instrucciones SQL, es decir sin usan directamente los componentes TTable a continuacion coloco el codigo que me permite guardar la imagen en el campo longblob en MySQL, el campo que almacena la imagen es el campo IMAGEN.

Alguien tiene idea de como resolver este problema, la idea es que pulsando un boton muestre la imagen almacenada




delphi
  1. procedure TFormSalidaXVale.BitBtnGuardaEnBlobClick(Sender: TObject);
  2. Var
  3.   xSQl:String;
  4.   xIDAlmacen:Integer;
  5.   myYear, myMonth, myDay : Word;
  6.   DFormat : String;
  7. begin
  8.     xIDAlmacen:=0;
  9.     DecodeDate(DateTimePicker1.Date, myYear, myMonth, myDay);
  10.     DFormat:=IntToStr(myYear)+'-'+IntToStr(myMonth)+'-'+IntToStr(myDay);
  11.  
  12.     with DM1.QueryDM do
  13.   begin
  14.       Close;
  15.       SQL.Clear;
  16.       xSQL := ' Insert into repositorio (IDAlmacen,Anio,NoFacReq,Titulo,Imagen) ';
  17.       xSQL := xSQL + ' Values ('+IntToStr(0)+',"'+IntToStr(myYear)+'","'+EditNumSalida.Text+'","bella",:xDocumento)';
  18.       SQL.Add(xSQL);
  19.       ParamByName('xDocumento').DataType := ftBlob;
  20.       ParamByName('xDocumento').LoadFromFile('F:\SAyM\Series\65ca57.jpg', ftBlob);
  21.       ExecSQL;
  22.   end;
  23. end;


  • 0

#2 Wilson

Wilson

    Advanced Member

  • Moderadores
  • PipPipPip
  • 2.137 mensajes

Escrito 18 octubre 2011 - 03:52

Yo colocaría un TImage y agregaría esta línea de código al final del procedimiento.




delphi
  1.   image1.Picture.LoadFromFile('F:\SAyM\Series\65ca57.jpg');




Quedaría así:





delphi
  1. procedure TFormSalidaXVale.BitBtnGuardaEnBlobClick(Sender: TObject);
  2. Var
  3.   xSQl:String;
  4.   xIDAlmacen:Integer;
  5.   myYear, myMonth, myDay : Word;
  6.   DFormat : String;
  7. begin
  8.     xIDAlmacen:=0;
  9.     DecodeDate(DateTimePicker1.Date, myYear, myMonth, myDay);
  10.     DFormat:=IntToStr(myYear)+'-'+IntToStr(myMonth)+'-'+IntToStr(myDay);
  11.  
  12.     with DM1.QueryDM do
  13.   begin
  14.       Close;
  15.       SQL.Clear;
  16.       xSQL := ' Insert into repositorio (IDAlmacen,Anio,NoFacReq,Titulo,Imagen) ';
  17.       xSQL := xSQL + ' Values ('+IntToStr(0)+',"'+IntToStr(myYear)+'","'+EditNumSalida.Text+'","bella",:xDocumento)';
  18.       SQL.Add(xSQL);
  19.       ParamByName('xDocumento').DataType := ftBlob;
  20.       image1.Picture.LoadFromFile('F:\SAyM\Series\65ca57.jpg');//AQUI
  21.       ParamByName('xDocumento').LoadFromFile('F:\SAyM\Series\65ca57.jpg', ftBlob);
  22.       ExecSQL;
  23.   end;
  24. end;




PD: Incluso podrías valerte de un TOpenDialog para escoger la imagen.
  • 0




IP.Board spam blocked by CleanTalk.