程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> GdiPlus[53]: 圖像(五) 圖像的屬性(圖像元數據)

GdiPlus[53]: 圖像(五) 圖像的屬性(圖像元數據)

編輯:Delphi

相關方法和屬性:

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; 




  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved