Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   FireMonkey (https://www.clubdelphi.com/foros/forumdisplay.php?f=50)
-   -   Mostrar imagen en timage (https://www.clubdelphi.com/foros/showthread.php?t=95694)

LACV 16-05-2022 19:21:55

Mostrar imagen en timage
 
Buen dia

necesito mostrar imagenes que estan guardadas en la DB en un Timage pero no lo e logrado, la verdad ando algo perdido, si me pueden ayudar se los agredeceria
tengo este codigo, es de recordar que es un proyecto en Friemonkey


Código Delphi [-]
procedure TS.reset;
var
  JpegStream: TMemoryStream;
  Jpeg, Bitmap: TBitmap;
  tmpPos, tmpLen: integer;
  pp: string;
  Data: string;
begin
  with QueryProductos Do
  begin
    Active := false;
    Active := true;

    Data := FieldByName('ImgProd').AsString;

    try
      tmpPos := Pos('B]>', Data);
      pp := Copy(Data, 5, tmpPos - 5);
      tmpLen := StrToInt(pp);
      Data := Copy(Data, tmpPos + 3, tmpLen);

      Bitmap := TBitmap.Create;
      try
        Jpeg := TBitmap.Create;
        try
          JpegStream := TMemoryStream.Create;
          try
            TIdDecoderMIME.DecodeStream(Data, JpegStream);
            JpegStream.Position := 0;
            Jpeg.LoadFromStream(JpegStream);
          finally
            JpegStream.Free;
          end;

          with Bitmap do
          begin
            SetSize(Jpeg.Width, Jpeg.Height);

            if Canvas.BeginScene then
              try
                Canvas.DrawBitmap(Jpeg,
{$IF RTLVersion >= 31} // 10.1 Berlin or higher
                  Jpeg.BoundsF,
{$ELSE}
                  TRectF.Create(0, 0, Jpeg.Width, Jpeg.Height),
{$IFEND}
                  TRectF.Create(0, 0, 200, 160), 1.0);
              finally
                Canvas.EndScene;
              end;
          end;
        finally
          Jpeg.Free;
        end;

        Image1.Bitmap.Assign(Bitmap);
        //image1.Bitmap.LoadFromFile(Bitmap);
      finally
        Bitmap.Free;
      end;
    except
      on E: Exception do
        //
    end;

  end;
end;

LACV 16-05-2022 23:45:17

Código Delphi [-]
Buena tarde e intetado de esta forma que es algo parecido  en vcl, peno no lo logro realizar.

procedure TS.reset;
var
  img: TBitmap;
begin
  with QueryProductos Do
  begin
    Active := false;
    Active := true;

    try
      img.Create;
      img.Assign(FieldByName('ImgProd'));
      Image1.Bitmap.Assign(img);
    finally
      img.Free;
    end;

  end;
end;

mRoman 17-05-2022 16:10:19

Que tal LACV

Yo lo hago de esta manera:

Código Delphi [-]
        Image1.Picture.Assign(dsProducto.fieldbyname('foto'));

dsProducto es mi DataSet que apunta a una tabla llamada PRODUCTO que tiene un campo FOTO donde almaceno la imagen, "Image1" es del tipo TImage. El campo FOTO es del tipo BLOB Binary en la tabla PRODUCTO.

Espero te sirva.

Saludos.

Neftali [Germán.Estévez] 17-05-2022 17:27:05

¿Has probado con LiveBindings?


La franja horaria es GMT +2. Ahora son las 20:43:51.

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