知道了格式名称, 用 GetEncoderClsid 函数可以获取格式的 GUID;
GetEncoderClsid 函数来自 GDIPUTIL 单元, 本例并没有用到前面一直不可或缺的 GDIPOBJ、GDIPAPI 单元.
如果要获取 image/bmp、image/jpeg、image/gif、image/tiff、image/png 格式以外的 GUID 不能使用此函数.
另外, 为了把 GUID 转换为字符串显示, 本例用到了 GUIDToString 函数.
本例效果图:
代码文件:
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;typeTForm1 = class(TForm)Memo1: TMemo;procedure FormCreate(Sender: TObject);end;varForm1: TForm1;implementation{$R *.dfm}uses GDIPUTIL;procedure TForm1.FormCreate(Sender: TObject); varList: TStringList;ImgGUID: TGUID;i: Integer; beginList := TStringList.Create;List.Add('image/bmp');List.Add('image/jpeg');List.Add('image/gif');List.Add('image/tiff');List.Add('image/png');Memo1.Clear;for i := 0 to List.Count - 1 dobeginGetEncoderClsid(List[i], ImgGUID);Memo1.Lines.Add(Format('%s: %s', [GUIDToString(ImgGUID), List[i]]));end;List.Free; end;end.窗体文件:
object Form1: TForm1Left = 0Top = 0Caption = 'Form1'ClientHeight = 115ClientWidth = 329Color = clBtnFaceFont.Charset = DEFAULT_CHARSETFont.Color = clWindowTextFont.Height = -11Font.Name = 'Tahoma'Font.Style = []OldCreateOrder = FalseOnCreate = FormCreatePixelsPerInch = 96TextHeight = 13object Memo1: TMemoLeft = 0Top = 0Width = 321Height = 115Align = alLeftLines.Strings = ('Memo1')ScrollBars = ssBothTabOrder = 0ExplicitHeight = 128end end