Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi JPG zu Bitmap (https://www.delphipraxis.net/71145-jpg-zu-bitmap.html)

qb-tim 9. Jun 2006 15:32


JPG zu Bitmap
 
Hi,

in meinem Programm will ich einen JPG in eine TImage laden:

Delphi-Quellcode:
function DownloadJPGToImage(AURL: String; AImage: TImage): Boolean;
var lGiveback : Boolean;
    lHTTP    : TIdHTTP;
    lDstStream: TStream;
    lGraphic : TJPEGImage;
begin
  lHTTP     := TIdHTTP.Create(nil);
  lDstStream := TMemoryStream.Create;
  lGraphic  := TJPEGImage.Create;
  try
    lHTTP.Get(AURL, lDstStream);
    lDstStream.Position := 0;
    lGraphic.LoadFromStream(lDstStream);
    AImage.Picture.Graphic := lGraphic;
    lGiveback := True;
  except
    lGiveback := False;
  end;
  lGraphic.Free;
  lDstStream.Free;
  lHTTP.Free;
  result := lGiveback;
end;
(Danke an SirThornberry) :thumb:

Nun will ich die Größe des Bildes verkleiner (NIE vergrößern):

Delphi-Quellcode:
procedure ResizeImage(newWidth, newHeight: integer; Image: TImage);
begin
  Image.Canvas.StretchDraw(Rect(0,0,newWidth,newHeight), Image.Picture.Graphic);
  Image.Picture.Graphic.Width := newWidth;
  Image.Picture.Graphic.Height := newHeight;
end;
Nun sagt Delphi, dass es nur eine Image mit Bitmap ändern kann...

Wie ändere ich jetzt die JPG (schon im Image) in eine "brauchbare" weiße für die ResizeImage-Prozedur?

qb-tim 9. Jun 2006 17:31

Re: JPG zu Bitmap
 
Tut mir leid...

Es hat sich erledigt.

TIPP: Suche nach "JPG Bitmap"

qb-tim 11. Jun 2006 14:54

Re: JPG zu Bitmap
 
Hier ist die Lösung:

Delphi-Quellcode:
function DownloadJPGToBitmap(const URL : string; ABitmap: TBitmap): Boolean;
var
  idHttp: TIdHTTP;
  ImgStream: TMemoryStream;
  JpgImage: TJPEGImage;
begin
  Result := False;
  ImgStream := TMemoryStream.Create;
  try
    idHttp := TIdHTTP.Create(nil);
    try
      idHttp.Get(URL, ImgStream);
    finally
      idHttp.Free;
    end;
    ImgStream.Position := 0;
    JpgImage := TJPEGImage.Create;
    try
      JpgImage.LoadFromStream(ImgStream);
      ABitmap.Assign(JpgImage);
    finally
      Result := True;
      JpgImage.Free;
    end;
  finally
    ImgStream.Free;
  end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:45 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz