AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Werkzeuge Interessante Tools für Clipboard Management, Wie JPG/PNG copy/pasten ?
Thema durchsuchen
Ansicht
Themen-Optionen

Interessante Tools für Clipboard Management, Wie JPG/PNG copy/pasten ?

Ein Thema von Rollo62 · begonnen am 3. Mai 2018 · letzter Beitrag vom 9. Mai 2018
Antwort Antwort
Seite 2 von 2     12   
Redeemer

Registriert seit: 19. Jan 2009
Ort: Kirchlinteln (LK Verden)
1.018 Beiträge
 
Delphi 2009 Professional
 
#11

AW: Interessante Tools für Clipboard Management, Wie JPG/PNG copy/pasten ?

  Alt 6. Mai 2018, 13:38
Ein JPG in die Zwischenablage zu kopieren, ist sinnlos. Es gibt nur zwei Sachen, für die man einen JPG-Stream brauchen könnte (verlustfreies Drehen/Spiegeln und Ausschneiden), aber das nutzt keiner mit der Zwischenablage.
"PNG" und "Alphakanal" sind auch zwei verschiedene Begriffe. PNGs in die Zwischenablage zu kopieren, ist sinnlos, da sie bei jeder Änderung neu kodiert werden müssen (was immerhin verlustfrei ist). Für Alphakanäle hat sich leider kein Standard durchgesetzt.
Janni
2005 PE, 2009 PA, XE2 PA
  Mit Zitat antworten Zitat
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.183 Beiträge
 
Delphi 12 Athens
 
#12

AW: Interessante Tools für Clipboard Management, Wie JPG/PNG copy/pasten ?

  Alt 6. Mai 2018, 15:21
Diese Bilder im "original" Speicherformat zu kopieren hat nur einen Vorteil, wenn sie am Ziel im selben Format bleiben und nicht verändert werden.
> Dann bleibt bei den verlustbehafteten Formaten die Qualität gleich.

PS: Bilder als 32-Bit-Bitmap (mit Alpha) da rein und zusätzlich als IStream, kleiner Dateien als Global-Memory oder extern als Path verlinken (die original-Datei).
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests

Geändert von himitsu ( 6. Mai 2018 um 15:28 Uhr)
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
3.929 Beiträge
 
Delphi 12 Athens
 
#13

AW: Interessante Tools für Clipboard Management, Wie JPG/PNG copy/pasten ?

  Alt 6. Mai 2018, 16:29
1. Siehe himitzu
2. Der Speicherbeyarf in der Zielapp, wenn es embedded wird.

Leider kann man das nicht immer gut feststellen wie apps das handhaben, ich gehe aber mittlerweile davon aus das es immer als bmp im Ziel ankommt.
Ob das ZielApp daraus etwas anderes konvertiert hängt von dessen Gusto ab.
Ich denke das dann immer eine ZielApp eigene Konvertierung eingesetzt wird, aber nie das OrginalApp Datei.

Damit muss ich wohl leben ...
Romlo

Geändert von Rollo62 ( 6. Mai 2018 um 19:30 Uhr)
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#14

AW: Interessante Tools für Clipboard Management, Wie JPG/PNG copy/pasten ?

  Alt 6. Mai 2018, 21:01
Es gibt dutzende Möglichkeiten was mit Clipboard anzustellen, ehe Du Dich um Formate sorgst, schau lieber wie Deine Ziel App überhaupt mit der Außenwelt Kommuniziert. Das von Dir genannte "Ditto" ist schon mega komplex und Umfangreich, man wird ja förmlich erschlagen mit Möglichkeiten.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
3.929 Beiträge
 
Delphi 12 Athens
 
#15

AW: Interessante Tools für Clipboard Management, Wie JPG/PNG copy/pasten ?

  Alt 7. Mai 2018, 05:34
@Kodezwerg
Ochmal zur Klarstellung: Es geht nicht in erster Linie um meine App.
Es geht drum wie ich das JPG/PNG in meiner und anderen konservieren kann, ohne das es zu BMP aufbläht.

Am Besten erscheint mir vielleicht als Beispiel IrFanView, das kann alle Fomate bearbeiten und per Copy-Paste übernehmen.
Aber erst nach dem Speichern wird das neue (oder alte)) Format erstellt.
Solange es in IrFanView in der Bearbeitung ist wird es intern womöglich als BMP im Memory sein
(macht ja auch Sinn).

Aber wenn ich das jetzt per CopyPaste rausgeben möchte wie kann ich erzwingen das JPG o.ä. erhalten bleibt, so das der Empfänger das nicht umwandln muss.

Mir scheint das es da wohl keine allgemeine Lösung gibt, das DnD will ich mir noch genaur anschauen.
Ich hätte gehofft das man ein CustomFormal irgendwie global registrieren könnte, so das es clevere Apps auch nutzen könnten, aber das ist wohl nicht vorgesehen.
Dann scheint es nur formatsicher über Export/Import zu funktionieren, geht auch ist aber nicht sehr elegant.

Rollo
  Mit Zitat antworten Zitat
Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#16

AW: Interessante Tools für Clipboard Management, Wie JPG/PNG copy/pasten ?

  Alt 7. Mai 2018, 10:41
how-would-you-copy-a-png-image-to-the-clipboard-using-delphi
Zitat:
It could be that they use an alternative clipboard format, see http://msdn.microsoft.com/en-us/libr...13(VS.85).aspx for a list of available clipboard formats. Or they could register their own clipboard format such as

RegisterClipboardFormat('PNG')
and then simply write the png data to the clipboard. If the clipboard format string specified is standard (i.e. other applications register the same clipboard format) then you will be able to paste it into other applications which support this clipboard format.

You might need to call windows functions directly as Delphi's clipboard wrapper isn't very good.

how-to-save-pngimage-from-clipboard
Get current clipboard formats
Hier eine bessere Version als von PasteBin >>>
Delphi-Quellcode:
uses
  ActiveX;

function GetClipboardFormatString(Format: Word): string;
var
  S: string;
begin
  case Format of
    1: S := 'CF_TEXT';
    2: S := 'CF_BITMAP';
    3: S := 'CF_METAFILEPICT';
    4: S := 'CF_SYLK';
    5: S := 'CF_DIF';
    6: S := 'CF_TIFF';
    7: S := 'CF_OEMTEXT';
    8: S := 'CF_DIB';
    9: S := 'CF_PALETTE';
    10: S := 'CF_PENDATA';
    11: S := 'CF_RIFF';
    12: S := 'CF_WAVE';
    13: S := 'CF_UNICODETEXT';
    14: S := 'CF_ENHMETAFILE';
    15: S := 'CF_HDROP';
    16: S := 'CF_LOCALE';
    17: S := 'CF_DIBV5';
    $0080: S := 'CF_OWNERDISPLAY';
    $0081: S := 'CF_DSPTEXT';
    $0082: S := 'CF_DSPBITMAP';
    $0083: S := 'CF_DSPMETAFILEPICT';
    $008E: S := 'CF_DSPENHMETAFILE';
    $0200: S := 'CF_PRIVATEFIRST';
    $02FF: S := 'CF_PRIVATELAST';
    $0300: S := 'CF_GDIOBJFIRST';
    $03FF: S := 'CF_GDIOBJLAST';
  else
    begin
      SetLength(S, 255);
      SetLength(S, GetClipboardFormatName(Format, PChar(S), 255));
      if Length(S) = 0 then
        S := 'Unknown, unregistered clipboard format';
      Result := S + ' (' + IntToStr(Format) + ')';
      Exit;
    end;
  end;
  Result := 'Standard clipboard format (' + S + ')';
end;

function GetClipboardFormats: string;
var
  S: string;
  FormatEtc: TFormatEtc;
  DataObject: IDataObject;
  EnumFormatEtc: IEnumFormatEtc;
begin
  Result := '';
  if Succeeded(OleGetClipboard(DataObject)) then
  begin
    if Succeeded(DataObject.EnumFormatEtc(DATADIR_GET, EnumFormatEtc)) then
    begin
      S := DupeString('-', 65) + sLineBreak +
        'Clipboard data formats: ' + sLineBreak +
        DupeString('-', 65) + sLineBreak;
      while EnumFormatEtc.Next(1, FormatEtc, nil) = S_OK do
        S := S + GetClipboardFormatString(FormatEtc.cfFormat) + sLineBreak;
      Result := S;
    end;
  end;
end;

function GetClipboardInfoDIB: string;
var
  S: string;
  ClipboardData: HGLOBAL;
  BitmapInfoHeader: PBitmapInfoHeader;
const
  BI_JPEG = 4;
  BI_PNG = 5;
begin
  Result := '';
  if OpenClipboard(0) then
  try
    ClipboardData := GetClipboardData(CF_DIB);
    if ClipboardData <> 0 then
    begin
      BitmapInfoHeader := GlobalLock(ClipboardData);
      if Assigned(BitmapInfoHeader) then
      try
        S := DupeString('-', 65) + sLineBreak +
          'Clipboard data of CF_DIB format: ' + sLineBreak +
          DupeString('-', 65) + sLineBreak +
          'Width: ' + IntToStr(BitmapInfoHeader.biWidth) + ' px' + sLineBreak +
          'Height: ' + IntToStr(BitmapInfoHeader.biHeight) + ' px' + sLineBreak +
          'Bit depth: ' + IntToStr(BitmapInfoHeader.biBitCount) + ' bpp' + sLineBreak +
          'Compression format: ';
        case BitmapInfoHeader.biCompression of
          BI_RGB: S := S + 'Uncompressed format (BI_RGB)';
          BI_RLE8: S := S + 'RLE format for bitmaps with 8 bpp (BI_RLE8)';
          BI_RLE4: S := S + 'RLE format for bitmaps with 4 bpp (BI_RLE4)';
          BI_BITFIELDS: S := S + 'Not compressed with color masks (BI_BITFIELDS)';
          BI_JPEG: S := S + 'Compressed using JPEG file format (BI_JPEG)';
          BI_PNG: S := S + 'Compressed using PNG file format (BI_PNG)';
        end;
        S := S + sLineBreak;
        Result := S;
      finally
        GlobalUnlock(ClipboardData);
      end;
    end;
  finally
    CloseClipboard;
  end;
end;

function GetClipboardInfoDIBV5: string;
var
  S: string;
  ClipboardData: HGLOBAL;
  BitmapInfoHeader: PBitmapV5Header;
const
  BI_JPEG = 4;
  BI_PNG = 5;
begin
  Result := '';
  if OpenClipboard(0) then
  try
    ClipboardData := GetClipboardData(CF_DIBV5);
    if ClipboardData <> 0 then
    begin
      BitmapInfoHeader := GlobalLock(ClipboardData);
      if Assigned(BitmapInfoHeader) then
      try
        S := DupeString('-', 65) + sLineBreak +
          'Clipboard data of CF_DIBV5 format: ' + sLineBreak +
          DupeString('-', 65) + sLineBreak +
          'Width: ' + IntToStr(BitmapInfoHeader.bV5Width) + ' px' + sLineBreak +
          'Height: ' + IntToStr(BitmapInfoHeader.bV5Height) + ' px' + sLineBreak +
          'Bit depth: ' + IntToStr(BitmapInfoHeader.bV5BitCount) + ' bpp' + sLineBreak +
          'Compression format: ';
        case BitmapInfoHeader.bV5Compression of
          BI_RGB: S := S + 'Uncompressed format (BI_RGB)';
          BI_RLE8: S := S + 'RLE format for bitmaps with 8 bpp (BI_RLE8)';
          BI_RLE4: S := S + 'RLE format for bitmaps with 4 bpp (BI_RLE4)';
          BI_BITFIELDS: S := S + 'Not compressed with color masks (BI_BITFIELDS)';
          BI_JPEG: S := S + 'Compressed using JPEG file format (BI_JPEG)';
          BI_PNG: S := S + 'Compressed using PNG file format (BI_PNG)';
        end;
        S := S + sLineBreak;
        Result := S;
      finally
        GlobalUnlock(ClipboardData);
      end;
    end;
  finally
    CloseClipboard;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  S: string;
begin
  S := GetClipboardFormats;
  if IsClipboardFormatAvailable(CF_DIB) then
    S := S + sLineBreak + GetClipboardInfoDIB;
  if IsClipboardFormatAvailable(CF_DIBV5) then
    S := S + sLineBreak + GetClipboardInfoDIBV5;
  ShowMessage(S);
end;

save-bitmap-with-transparency-to-png-in-delphi
Delphi-Quellcode:
Use PNGImage. In Delphi, try this:

function ConvertToPNG(oBMPSrc: TBitmap; sFilename: String);
var
  oPNGDest: TPNGObject;
begin
  oPNGDest := TPNGObject.Create;
  try
    oPNGDest.Assign(oBMPSrc);
    oPNGDest.SaveToFile(sFilename);
  finally
    oPNGDest.Free;
  end;
end;
If that doesn't work for you, you'll probably have to copy over the alpha and RGB values individually.

function ConvertToPNG(oBMPSrc: TBitmap; sFilename: String);
var
  oPNGDest: TPNGObject;
begin
  oPNGDest := TPNGObject.CreateBlank(COLOR_RGBALPHA, 8, oBMPSrc.Width, oBMPSrc.Height);
  try
    oPNGDest.CreateAlpha;
    // Copy over RGB
    ..
    // Copy over Alpha
    ..
    // Save to file
    oPNGDest.SaveToFile(sFilename);
  finally
    oPNGDest.Free;
  end;
end;
Das beste am Schluss:
png-image-mit-transparenz-clipboard
Delphi-Quellcode:
var
  DataStream: TMemoryStream;
  Data: Pointer;
  DataHandle: THandle;
  ClipboardFormat: Integer;
begin
  // Das Format sollte man natürlich eher nur beim Start der Anwendung einmal registrieren
  ClipboardFormat := RegisterClipboardFormat('PNG');
  DataStream := TMemoryStream.Create;
  try
    // Die Bilddaten können natürlich auch direkt aus einer Datei usw. stammen
    Image1.Picture.Graphic.SaveToStream(DataStream);

    DataHandle := GlobalAlloc(GMEM_DDESHARE, DataStream.Size);
    Data := GlobalLock(DataHandle);
    try
      DataStream.Position := 0;
      DataStream.ReadBuffer(Data^, DataStream.Size);
    finally
      GlobalUnlock(DataHandle);
    end;
    Clipboard.Open;
    Clipboard.SetAsHandle(ClipboardFormat, DataHandle);
    Clipboard.Close;
  finally
    DataStream.Free;
  end;
Wenn Du mit all diesen Informationen nichts anfangen kannst, dann glaube ich das ich nicht verstehe worum es Dir eigentlich geht.
Gruß vom KodeZwerg
  Mit Zitat antworten Zitat
Rollo62

Registriert seit: 15. Mär 2007
3.929 Beiträge
 
Delphi 12 Athens
 
#17

AW: Interessante Tools für Clipboard Management, Wie JPG/PNG copy/pasten ?

  Alt 9. Mai 2018, 14:13
Hallo Kodezwerg,

dankesehr für die Mühe.
Das sieht vielversprechend aus, werde ich demnächst checken.

Rollo
  Mit Zitat antworten Zitat
Redeemer

Registriert seit: 19. Jan 2009
Ort: Kirchlinteln (LK Verden)
1.018 Beiträge
 
Delphi 2009 Professional
 
#18

AW: Interessante Tools für Clipboard Management, Wie JPG/PNG copy/pasten ?

  Alt 9. Mai 2018, 16:15
Am Besten erscheint mir vielleicht als Beispiel IrFanView, das kann alle Fomate bearbeiten und per Copy-Paste übernehmen.
Aber erst nach dem Speichern wird das neue (oder alte)) Format erstellt.
Solange es in IrFanView in der Bearbeitung ist wird es intern womöglich als BMP im Memory sein
(macht ja auch Sinn).

Aber wenn ich das jetzt per CopyPaste rausgeben möchte wie kann ich erzwingen das JPG o.ä. erhalten bleibt, so das der Empfänger das nicht umwandln muss.

Mir scheint das es da wohl keine allgemeine Lösung gibt, das DnD will ich mir noch genaur anschauen.
Ich hätte gehofft das man ein CustomFormal irgendwie global registrieren könnte, so das es clevere Apps auch nutzen könnten, aber das ist wohl nicht vorgesehen.
Dann scheint es nur formatsicher über Export/Import zu funktionieren, geht auch ist aber nicht sehr elegant.
IrfanView lädt das Bild als DIB in den Speicher und interessiert sich ab diesem Punkt nicht mehr für die Datei, da es ausschließlich mit der DIB im Speicher arbeitet. Zu diesem Zeitpunkt schmeiß IrfanView auch den Alphakanal weg, da es Alphakanäle im Speicher nicht unterstützt. Du kannst die Datei sofort löschen, wenn das Bild angezeigt wird (außer für verlustfreie JPEG-Bearbeitung und Mehrseitenbilder, aber diese beiden Features sind nur mit Dateien und nicht mit der Zwischenlage möglich, da IrfanView auch nur DIBs aus der Zwischenablage unterstützt).
Janni
2005 PE, 2009 PA, XE2 PA
  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 10:39 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