相关方法和属性:
IGPImage.GetPropertyItem(); { 获取属性项 }
IGPImage.SetPropertyItem(); { 设置属性项 }
IGPImage.RemovePropertyItem(); { 删除属性项 }
IGPImage.PropertyIdList; { 获取图像属性 ID 数组 }
IGPImage.PropertyItems; { 获取图像属性集合 }
IGPImage.PropertyItems 指向一个 IGPPropertyItems 类型的数组;
IGPPropertyItem 是 IGPPropertyItems 属性数组中的一个属性(或叫属性项).
每个属性项都包含:
IGPPropertyItem.Id; { 属性 ID, 也就是属性类别, 譬如是标题还是版权说明等 }
IGPPropertyItem.ValueType; { 属性的数据类型 }
IGPPropertyItem.Length; { 属性数据长度 }
IGPPropertyItem.Value; { 属性数据指针 }
IGPImage.PropertyIdList 只是获取属性 ID 的数组.
IGPPropertyItem.ValueType 常数:
PropertyTagTypeByte = 1; { 字节数组 }
PropertyTagTypeASCII = 2; { PAnsiChar }
PropertyTagTypeShort = 3; { Word }
PropertyTagTypeLong = 4; { Cardinal }
PropertyTagTypeRational = 5; { Cardinal/Cardinal; 第一个数是分子, 第二个数是分母 }
PropertyTagTypeUndefined = 7; { 可包含任何数据类型的字节数组 }
PropertyTagTypeSLONG = 9; { Integer }
PropertyTagTypeSRational = 10; { Integer/Integer; 第一个数是分子, 第二个数是分母 }
IGPPropertyItem.Id 常数:
PropertyTagGpsVer = $0000
PropertyTagGpsLatitudeRef = $0001
PropertyTagGpsLatitude = $0002
PropertyTagGpsLongitudeRef = $0003
PropertyTagGpsLongitude = $0004
PropertyTagGpsAltitudeRef = $0005
PropertyTagGpsAltitude = $0006
PropertyTagGpsGpsTime = $0007
PropertyTagGpsGpsSatellites = $0008
PropertyTagGpsGpsStatus = $0009
PropertyTagGpsGpsMeasureMode = $000A
PropertyTagGpsGpsDop = $000B
PropertyTagGpsSpeedRef = $000C
PropertyTagGpsSpeed = $000D
PropertyTagGpsTrackRef = $000E
PropertyTagGpsTrack = $000F
PropertyTagGpsImgDirRef = $0010
PropertyTagGpsImgDir = $0011
PropertyTagGpsMapDatum = $0012
PropertyTagGpsDestLatRef = $0013
PropertyTagGpsDestLat = $0014
PropertyTagGpsDestLongRef = $0015
PropertyTagGpsDestLong = $0016
PropertyTagGpsDestBearRef = $0017
PropertyTagGpsDestBear = $0018
PropertyTagGpsDestDistRef = $0019
PropertyTagGpsDestDist = $001A
PropertyTagNewSubfileType = $00FE
PropertyTagSubfileType = $00FF
PropertyTagImageWidth = $0100
PropertyTagImageHeight = $0101
PropertyTagBitsPerSample = $0102
PropertyTagCompression = $0103
PropertyTagPhotometricInterp = $0106
PropertyTagThreshHolding = $0107
PropertyTagCellWidth = $0108
PropertyTagCellHeight = $0109
PropertyTagFillOrder = $010A
PropertyTagDocumentName = $010D
PropertyTagImageDescription = $010E
PropertyTagEquipMake = $010F
PropertyTagEquipModel = $0110
PropertyTagStripOffsets = $0111
PropertyTagOrientation = $0112
PropertyTagSamplesPerPixel = $0115
PropertyTagRowsPerStrip = $0116
PropertyTagStripBytesCount = $0117
PropertyTagMinSampleValue = $0118
PropertyTagMaxSampleValue = $0119
PropertyTagXResolution = $011A
PropertyTagYResolution = $011B
PropertyTagPlanarConfig = $011C
PropertyTagPageName = $011D
PropertyTagXPosition = $011E
PropertyTagYPosition = $011F
PropertyTagFreeOffset = $0120
PropertyTagFreeByteCounts = $0121
PropertyTagGrayResponseUnit = $0122
PropertyTagGrayResponseCurve = $0123
PropertyTagT4Option = $0124
PropertyTagT6Option = $0125
PropertyTagResolutionUnit = $0128
PropertyTagPageNumber = $0129
PropertyTagTransferFunction = $012D
PropertyTagSoftwareUsed = $0131
PropertyTagDateTime = $0132
PropertyTagArtist = $013B
PropertyTagHostComputer = $013C
PropertyTagPredictor = $013D
PropertyTagWhitePoint = $013E
PropertyTagPrimaryChromaticities = $013F
PropertyTagColorMap = $0140
PropertyTagHalftoneHints = $0141
PropertyTagTileWidth = $0142
PropertyTagTileLength = $0143
PropertyTagTileOffset = $0144
PropertyTagTileByteCounts = $0145
PropertyTagInkSet = $014C
PropertyTagInkNames = $014D
PropertyTagNumberOfInks = $014E
PropertyTagDotRange = $0150
PropertyTagTargetPrinter = $0151
PropertyTagExtraSamples = $0152
PropertyTagSampleFormat = $0153
PropertyTagSMinSampleValue = $0154
PropertyTagSMaxSampleValue = $0155
PropertyTagTransferRange = $0156
PropertyTagJPEGProc = $0200
PropertyTagJPEGInterFormat = $0201
PropertyTagJPEGInterLength = $0202
PropertyTagJPEGRestartInterval = $0203
PropertyTagJPEGLosslessPredictors = $0205
PropertyTagJPEGPointTransforms = $0206
PropertyTagJPEGQTables = $0207
PropertyTagJPEGDCTables = $0208
PropertyTagJPEGACTables = $0209
PropertyTagYCbCrCoefficients = $0211
PropertyTagYCbCrSubsampling = $0212
PropertyTagYCbCrPositioning = $0213
PropertyTagREFBlackWhite = $0214
PropertyTagGamma = $0301
PropertyTagICCProfileDescriptor = $0302
PropertyTagSRGBRenderingIntent = $0303
PropertyTagImageTitle = $0320
PropertyTagResolutionXUnit = $5001
PropertyTagResolutionYUnit = $5002
PropertyTagResolutionXLengthUnit = $5003
PropertyTagResolutionYLengthUnit = $5004
PropertyTagPrintFlags = $5005
PropertyTagPrintFlagsVersion = $5006
PropertyTagPrintFlagsCrop = $5007
PropertyTagPrintFlagsBleedWidth = $5008
PropertyTagPrintFlagsBleedWidthScale = $5009
PropertyTagHalftoneLPI = $500A
PropertyTagHalftoneLPIUnit = $500B
PropertyTagHalftoneDegree = $500C
PropertyTagHalftoneShape = $500D
PropertyTagHalftoneMisc = $500E
PropertyTagHalftoneScreen = $500F
PropertyTagJPEGQuality = $5010
PropertyTagGridSize = $5011
PropertyTagThumbnailFormat = $5012
PropertyTagThumbnailWidth = $5013
PropertyTagThumbnailHeight = $5014
PropertyTagThumbnailColorDepth = $5015
PropertyTagThumbnailPlanes = $5016
PropertyTagThumbnailRawBytes = $5017
PropertyTagThumbnailSize = $5018
PropertyTagThumbnailCompressedSize = $5019
PropertyTagColorTransferFunction = $501A
PropertyTagThumbnailData = $501B
PropertyTagThumbnailImageWidth = $5020
PropertyTagThumbnailImageHeight = $5021
PropertyTagThumbnailBitsPerSample = $5022
PropertyTagThumbnailCompression = $5023
PropertyTagThumbnailPhotometricInterp = $5024
PropertyTagThumbnailImageDescription = $5025
PropertyTagThumbnailEquipMake = $5026
PropertyTagThumbnailEquipModel = $5027
PropertyTagThumbnailStripOffsets = $5028
PropertyTagThumbnailOrientation = $5029
PropertyTagThumbnailSamplesPerPixel = $502A
PropertyTagThumbnailRowsPerStrip = $502B
PropertyTagThumbnailStripBytesCount = $502C
PropertyTagThumbnailResolutionX = $502D
PropertyTagThumbnailResolutionY = $502E
PropertyTagThumbnailPlanarConfig = $502F
PropertyTagThumbnailResolutionUnit = $5030
PropertyTagThumbnailTransferFunction = $5031
PropertyTagThumbnailSoftwareUsed = $5032
PropertyTagThumbnailDateTime = $5033
PropertyTagThumbnailArtist = $5034
PropertyTagThumbnailWhitePoint = $5035
PropertyTagThumbnailPrimaryChromaticities = $5036
PropertyTagThumbnailYCbCrCoefficients = $5037
PropertyTagThumbnailYCbCrSubsampling = $5038
PropertyTagThumbnailYCbCrPositioning = $5039
PropertyTagThumbnailRefBlackWhite = $503A
PropertyTagThumbnailCopyRight = $503B
PropertyTagLuminanceTable = $5090
PropertyTagChrominanceTable = $5091
PropertyTagFrameDelay = $5100
PropertyTagLoopCount = $5101
PropertyTagGlobalPalette = $5102
PropertyTagIndexBackground = $5103
PropertyTagIndexTransparent = $5104
PropertyTagPixelUnit = $5110
PropertyTagPixelPerUnitX = $5111
PropertyTagPixelPerUnitY = $5112
PropertyTagPaletteHistogram = $5113
PropertyTagCopyright = $8298
PropertyTagExifExposureTime = $829A
PropertyTagExifFNumber = $829D
PropertyTagExifIFD = $8769
PropertyTagICCProfile = $8773
PropertyTagExifExposureProg = $8822
PropertyTagExifSpectralSense = $8824
PropertyTagGpsIFD = $8825
PropertyTagExifISOSpeed = $8827
PropertyTagExifOECF = $8828
PropertyTagExifVer = $9000
PropertyTagExifDTOrig = $9003
PropertyTagExifDTDigitized = $9004
PropertyTagExifCompConfig = $9101
PropertyTagExifCompBPP = $9102
PropertyTagExifShutterSpeed = $9201
PropertyTagExifAperture = $9202
PropertyTagExifBrightness = $9203
PropertyTagExifExposureBias = $9204
PropertyTagExifMaxAperture = $9205
PropertyTagExifSubjectDist = $9206
PropertyTagExifMeteringMode = $9207
PropertyTagExifLightSource = $9208
PropertyTagExifFlash = $9209
PropertyTagExifFocalLength = $920A
PropertyTagExifMakerNote = $927C
PropertyTagExifUserComment = $9286
PropertyTagExifDTSubsec = $9290
PropertyTagExifDTOrigSS = $9291
PropertyTagExifDTDigSS = $9292
PropertyTagExifFPXVer = $A000
PropertyTagExifColorSpace = $A001
PropertyTagExifPixXDim = $A002
PropertyTagExifPixYDim = $A003
PropertyTagExifRelatedWav = $A004
PropertyTagExifInterop = $A005
PropertyTagExifFlashEnergy = $A20B
PropertyTagExifSpatialFR = $A20C
PropertyTagExifFocalXRes = $A20E
PropertyTagExifFocalYRes = $A20F
PropertyTagExifFocalResUnit = $A210
PropertyTagExifSubjectLoc = $A214
PropertyTagExifExposureIndex = $A215
PropertyTagExifSensingMethod = $A217
PropertyTagExifFileSource = $A300
PropertyTagExifSceneType = $A301
PropertyTagExifCfaPattern = $A302
遍历属性:
uses GdiPlus;
procedure TForm1.Button1Click(Sender: TObject);
var
Image: IGPImage;
PropertyItem: IGPPropertyItem;
begin
Image := TGPImage.Create('C:\GdiPlusImg\FakePhoto.jpg');
Memo1.Clear;
for PropertyItem in Image.PropertyItems do with Memo1.Lines do
begin
Add(Format('Id: $%.4x', [PropertyItem.Id]));
Add(Format('ValueType: %d', [PropertyItem.ValueType]));
Add(Format('Length: %d', [PropertyItem.Length]));
Add(Format('Value: $%p', [PropertyItem.Value]));
Add(EmptyStr);
end;
end;
只遍历属性 ID:
uses GdiPlus;
procedure TForm1.Button1Click(Sender: TObject);
var
Image: IGPImage;
PropID: Cardinal;
begin
Image := TGPImage.Create('C:\GdiPlusImg\FakePhoto.jpg');
Memo1.Clear;
for PropID in Image.PropertyIdList do
begin
Memo1.Lines.Add(Format('$%.4x', [PropID]));
end;
end;
下面例子测试了 SetPropertyItem、GetPropertyItem、RemovePropertyItem 三个方法.
先给图像添加了标题属性(其属性 ID 是 PropertyTagImageTitle);
保存图像后重新打开再读取这个属性;
删除这个属性后有试着找了找...
uses GdiPlus;
procedure TForm1.Button1Click(Sender: TObject);
var
Image: IGPImage;
PropTitle: IGPPropertyItem;
Title: AnsiString;
i: Integer;
begin
ChDir('C:\GdiPlusImg\');
Image := TGPImage.Create('FakePhoto.jpg');
//
Title := 'New Title';
PropTitle := TGPPropertyItem.Create;
PropTitle.Id := PropertyTagImageTitle;
PropTitle.ValueType := PropertyTagTypeASCII;
PropTitle.Length := Length(Title) + 1;
PropTitle.Value := PAnsiChar(Title);
Image.SetPropertyItem(PropTitle);
Image.Save('FakePhoto_Test.jpg', TGPImageFormat.Jpeg);
Image := nil;
//
PropTitle := nil;
Image := TGPImage.Create('FakePhoto_Test.jpg');
PropTitle := Image.GetPropertyItem(PropertyTagImageTitle);
ShowMessage(PAnsiChar(PropTitle.Value)); { New Title }
//
Image.RemovePropertyItem(PropertyTagImageTitle);
for i := 0 to Image.PropertyIdList.Count - 1 do
if Image.PropertyIdList[i] = PropertyTagImageTitle then
ShowMessage('检测到属性标题存在'); { 已删除不会再有了 }
end;