![]() |
JPG zu Bitmap
Hi,
in meinem Programm will ich einen JPG in eine TImage laden:
Delphi-Quellcode:
(Danke an SirThornberry) :thumb:
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; Nun will ich die Größe des Bildes verkleiner (NIE vergrößern):
Delphi-Quellcode:
Nun sagt Delphi, dass es nur eine Image mit Bitmap ändern kann...
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; Wie ändere ich jetzt die JPG (schon im Image) in eine "brauchbare" weiße für die ResizeImage-Prozedur? |
Re: JPG zu Bitmap
Tut mir leid...
Es hat sich erledigt. TIPP: Suche nach "JPG Bitmap" |
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 21:44 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz