AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia PNG - Image mit Transparenz in Clipboard
Thema durchsuchen
Ansicht
Themen-Optionen

PNG - Image mit Transparenz in Clipboard

Ein Thema von geesmith · begonnen am 27. Mär 2014 · letzter Beitrag vom 14. Dez 2018
Antwort Antwort
Seite 2 von 2     12   
berens

Registriert seit: 3. Sep 2004
431 Beiträge
 
Delphi 2010 Professional
 
#11

AW: PNG - Image mit Transparenz in Clipboard

  Alt 14. Dez 2018, 11:58
Man möge mir verzeihen, dass ich dieses uralte Thema ausgrabe. Ich versuche schon seit mehreren Tagen über diverse Suchmaschinen herauszufinden, wie ich ein -partiell transparentes- PNG aus der Zwischenablage in mein Programm bekomme - leider ohne Erfolg. Da dieses Thema hier in DP und Google bei allen Suchwort-Variationen zu dem Thema immer weit Oben erscheint, und ich letztendlich die von jaenicke genannte Prozedur umgebaut habe, scheint mir dies entsprechend der sinnvollste Platz zu sein, um mein Wissen mit der Nachwelt zu teilen:

Delphi-Quellcode:
unit uClipboardPNG;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls;

type
  TForm2 = class(TForm)
    Image1: TImage;
    procedure Image1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form2: TForm2;

implementation

uses
  Clipbrd, pngimage;

{$R *.dfm}

// The given TargetPNG will load the PNG from the clipboard, if possible
// Will return True if successfull
// TargetPNG won't be changed if unsuccessfull
function LoadPNGFromClipboard(_TargetPNG: TPngImage): Boolean;
var
  DataStream: TMemoryStream;
  Data: Pointer;
  DataHandle: THandle;
  PNGClipboardFormat: Integer;
begin
  Result := False;
  DataStream := NIL;
  try
    if not assigned(_TargetPNG) then Exit;

    PNGClipboardFormat := RegisterClipboardFormat('PNG');

    DataStream := TMemoryStream.Create;
    Clipboard.Open;
    DataHandle := Clipboard.GetAsHandle(PNGClipboardFormat);
    Clipboard.Close;

    // DataHandle will only be <> 0, if the clipboard contains a PNG Image
    if DataHandle <> 0 then begin
      Data := GlobalLock(DataHandle);
      if Data <> nil then begin
        try
          DataStream.Write(Data^, GlobalSize(DataHandle));
          DataStream.Position := 0;
          Result := True;
        finally
          GlobalUnlock(DataHandle);
        end;
      end;
    end;

    // If Handle has been assigned and data has been read, load the PNG Data into the PNGImage
    if Result then begin
      _TargetPNG.LoadFromStream(DataStream);
    end;
  except
    //
  end;
  FreeAndNil(DataStream);
end;

// The given TargetImage will contain a TPNGImage with the clipboard's content, if clipboard contains a PNG
// Returns True if successfull
// TargetImage won't be changed if unsuccessfull
function LoadImageFromClipboard_PNG(_TargetImage: TImage): Boolean;
var
  png: TPngImage;
begin
  Result := False;
  png := NIL;
  try
    if not assigned(_TargetImage) then Exit;

    png := TPngImage.Create;
    Result := LoadPNGFromClipboard(png);
    _TargetImage.Picture.Assign(png);
  except
    //
  end;
  FreeAndNil(png);
end;


procedure TForm2.Image1Click(Sender: TObject);
begin
  // Load PNG into Image1 from Clipboard
  if not LoadImageFromClipboard_PNG(Image1) then begin
    // If not successfull, clear Image1
    Image1.Picture.Assign(NIL);

    // If Clipboard <> PNG, feel free to use other methods to load it, like
    // Image1.Picture.Assign(Clipboard);
  end;
end;

end.
Dieser Post erfordert keine Antwort, für Verbesserungsvorschläge bin ich wie immer offen.
Delphi 10.4 32-Bit auf Windows 10 Pro 64-Bit, ehem. Delphi 2010 32-Bit auf Windows 10 Pro 64-Bit
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:41 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