Ver Mensaje Individual
  #5  
Antiguo 15-07-2019
jrojasmcfia jrojasmcfia is offline
Miembro
 
Registrado: feb 2018
Posts: 18
Reputación: 0
jrojasmcfia Va por buen camino
Hola , gracias por las respuestas pero en realidad lo que ocupo es leer una imagen almacenada en una Base de data mysql y cargarla en una aplicacion en Delphi, lo que son archivos tipo imagen como los ejemplos que me pusieron si los logro hacer, sin embargo al tratar de extraer la image de una base datos no la logro pasar bien a la app, en un principio mi idea es pasarla via PHP mediante JSON y luego capturar el string con HTTP de los componentes indy adjunto tanto mi php como el codigo en delphi para hacer esto.El inconveniente que se me presenta es que aunque logro leer del JSON los valores nregistro y fecha el campo imagen me da error, en el código indico con un comentario el fragmento de código que me da error, si pudieran ayudarme con esto se los agradezco mucho, en realidad si lograra leer la imagen luego la decodificaria a tipo imagen y listo.
Adjunto tambien la respuesta del JSON en pdf




Código PHP:

$query 
"SELECT nregistro,Fecha,Imagen FROM resgistrodatos WHERE nregistro = 1 order by Fecha";

if (!
$resultado mysqli_query($link,$query)) die();

   
$rawdata['imagenes'] = array();
   
//guardamos en un array multidimensional todos los datos de la consulta
   
$i=0;
   

 
while(
$row mysqli_fetch_array($resultado))
   {
    
array_push($rawdata['imagenes'], array(
     
'fecha' => $row['fecha'],
     
'nregistro' => $row['nregistro'],
     
'photo' => base64_encode($row['Imagen'])
    ));
   }

mysqli_close($link);

header('Content-type: application/json');

echo 
json_encode($rawdata); 

Código Delphi [-]

procedure TForm1.Button1Click(Sender: TObject);
var
JSonValue:TJSonValue;
Branch,ss:string;
st:ansistring;

imagen:ansistring;

strm:TMemoryStream;
imagenstream : TStringSTream;
ImgStream: TMemoryStream;
JSonObject:TJSonObject;


begin
ImgStream := TMemoryStream.Create;

  idHttp1 := TIdHTTP.Create(nil);
  idhttp1.get('http://mipagina/develveimagen.php',ImgStream);
  ImgStream.Position := 0;
  st := MemoryStreamToString(ImgStream);

   JSonObject := TJSonObject.Create;
   JsonValue:=JSonObject.ParseJSONValue(st);
   JsonValue:=(JsonValue as TJSONObject).Get('imagenes').JSONValue;


   if (JSONValue is TJSONArray) then
      nresgistro:= ((JSONValue as TJSONArray).Items[0] as TJSonObject).Get('nregistro').JSONValue.Value;
      fecha  :=  ((JSONValue as TJSONArray).Items[0] as TJSonObject).Get('fecha').JSONValue.Value;

     //ESte me esta dando error

      imagen  :=  ((JSONValue as TJSONArray).Items[0] as TJSonObject).get('imagen').JSONValue.Value;

end;
Imágenes Adjuntas
Tipo de Archivo: pdf respuestajson.pdf (887,8 KB, 3 visitas)
Responder Con Cita