Einzelnen Beitrag anzeigen

peterbelow

Registriert seit: 12. Jan 2019
Ort: Hessen
714 Beiträge
 
Delphi 12 Athens
 
#4

AW: Bitmap aus Clipboard laden

  Alt 8. Apr 2025, 10:41
Ich habe eine .bmp-Datei
Die öffne ich mit Paint.
In Paint wird das Bild korrekt angezeigt (Bild_1).
Mit Ctrl-A und Ctrl-C kopiere ich die ins Clipboard,
Dann lade ich die aus dem Clipboard (siehe unten) und speichere sie.
Die gespeicherte Datei öffne ich mit Paint.
Die Datei wird angezeigt, aber mit verfälschten Farben (Bild_2).
Ähnliches passiert, wenn ich die Originaldatei mit Paint öffne, ins Clipboard kopiere und mit Photoshop aus dem Clipboard lade (Bild_3).
2 Fragen
1) Was ist der Fehler?
2) Wie kann ich herausfinden, welche Daten (Speicherauszug) tatsächlich im Clipboard sind?
Sieh dir mal dieses Beispiel in der online-Hilfe an.

Dein Problem kommt vermutlich daher, daß Du eine Palette angibst. Die meisten Bitmap-Formate verwenden aber keine, daher könnte das dazu führen, das die Bitmap als in das 256-Farben Format konvertiert wird.

Die momentan verfügbaren Formate im Clipboard bekommst Du über die Clipboard.Formats-Property. Einen Text-Namen aus der ID des Formats liefert die folgende Routine mit Hilfe der GetclipboardFormatName API-Funktion.

Delphi-Quellcode:
{!
<summary>
Get a string name for a clipboard format.</summary>
<returns>
the name the format was registered with, if it is a custom format, or
the symbolic name for the known predefined formats. The string
'unknown format' is returned for a format that cannot be identified.</returns>
<param name="fmt">is the format to get a name for.</param>
}

function GetClipFmtname(fmt: Cardinal): string;
const
  MaxChars = 128;
var
  buf: array[0..MaxChars] of Char;
  Len: Integer;
begin
  Len := GetclipboardFormatName(fmt, buf, MaxChars);
  if Len <> 0 then
    SetString(Result, buf, Len)
  else
    case fmt of
      1: Result := 'CF_TEXT';
      2: Result := 'CF_BITMAP';
      3: Result := 'CF_METAFILEPICT';
      4: Result := 'CF_SYLK';
      5: Result := 'CF_DIF';
      6: Result := 'CF_TIFF';
      7: Result := 'CF_OEMTEXT';
      8: Result := 'CF_DIB';
      9: Result := 'CF_PALETTE';
      10: Result := 'CF_PENDATA';
      11: Result := 'CF_RIFF';
      12: Result := 'CF_WAVE';
      13: Result := 'CF_UNICODETEXT';
      14: Result := 'CF_ENHMETAFILE';
      15: Result := 'CF_HDROP';
      16: Result := 'CF_LOCALE';
      17: Result := 'CF_DIBV5';
      $0080: Result := 'CF_OWNERDISPLAY';
      $0081: Result := 'CF_DSPTEXT';
      $0082: Result := 'CF_DSPBITMAP';
      $0083: Result := 'CF_DSPMETAFILEPICT';
      $008E: Result := 'CF_DSPENHMETAFILE';
      $0200..$02FF: Result := 'private format';
      $0300..$03FF: Result := 'GDI object';
    else
      Result := 'unknown format';
    end; {Case}
end;
Peter Below
  Mit Zitat antworten Zitat