ChrisL Posted October 9, 2008 Share Posted October 9, 2008 I'm trying to set the meta data in an image file, I can't get it to work and wondered if someone might be able to point me in the right direction..expandcollapse popup#include <GDIPlus.au3> Global Const $PropertyTagImageTitle = 0x0320 Global Const $PropertyTagEquipMake = 0x010f Global Const $PropertyTagEquipModel = 0x0110 Global Const $tagPropertyItem = "long id; long length; int Type; ptr value" Global Const $PropertyTagTypeByte = 1 Global Const $PropertyTagTypeASCII = 2 Global Const $PropertyTagTypeShort = 3 Global Const $PropertyTagTypeLong = 4 Global Const $PropertyTagTypeRational = 5 Global Const $PropertyTagTypeUndefined = 7 Global Const $PropertyTagTypeSLong = 9 Global Const $PropertyTagTypeSRational = 10 _GDIPlus_Startup () $hFile = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\TestImport.jpg") _GDIPlus_SetMetaData($hFile,"My Camera Model",$PropertyTagEquipMake) _GDIPlus_ImageSaveToFile($hFile,@desktopDir & "\New.jpg") _GDIPlus_ImageDispose($hFile) _GDIPlus_Shutdown() Func _GDIPlus_SetMetaData($hHandle,$vStr,$iD) $Struct_Meta = DllstructCreate($tagPropertyItem) DllStructSetData($Struct_Meta,"ID",$iD) DllStructSetData($Struct_Meta,"Length",StringLen($vStr) +1) DllStructSetData($Struct_Meta,"Type",$PropertyTagTypeASCII) DllStructSetData($Struct_Meta,"Value",$vStr) $aResult = DllCall($ghGDIPDll, "int", "GdipSetPropertyItem", "hwnd", $hHandle, "long*", DllStructGetPtr($Struct_Meta)) If @error Then $Struct_Meta = 0 Return SetError(@error, @extended, False) EndIf $Struct_Meta = 0 Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunchttp://msdn.microsoft.com/en-us/library/ms533832(VS.85).aspx [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
monoceres Posted October 10, 2008 Share Posted October 10, 2008 Hi! I was not able to get it to work (At least I don't think so) but I've fixed some errors: expandcollapse popup#include <GDIPlus.au3> Global Const $PropertyTagImageTitle = 0x0320 Global Const $PropertyTagEquipMake = 0x010f Global Const $PropertyTagEquipModel = 0x0110 ; Changed long to ulong and int to ushort Global Const $tagPropertyItem = "ulong id; ulong length; ushort Type; ptr value" Global Const $PropertyTagTypeByte = 1 Global Const $PropertyTagTypeASCII = 2 Global Const $PropertyTagTypeShort = 3 Global Const $PropertyTagTypeLong = 4 Global Const $PropertyTagTypeRational = 5 Global Const $PropertyTagTypeUndefined = 7 Global Const $PropertyTagTypeSLong = 9 Global Const $PropertyTagTypeSRational = 10 _GDIPlus_Startup () $hFile = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\300.jpg") _GDIPlus_SetMetaData($hFile,"My Camera Model",$PropertyTagEquipMake) _GDIPlus_ImageSaveToFile($hFile,@desktopDir & "\New.jpg") _GDIPlus_ImageDispose($hFile) _GDIPlus_Shutdown() Func _GDIPlus_SetMetaData($hHandle,$vStr,$iD) ; Store strings in arrays $MemString=DllStructCreate("char[255];") DllStructSetData($MemString,1,$vStr) $Struct_Meta = DllstructCreate($tagPropertyItem) DllStructSetData($Struct_Meta,"ID",$iD) DllStructSetData($Struct_Meta,"Length",StringLen($vStr) +1) DllStructSetData($Struct_Meta,"Type",$PropertyTagTypeASCII) DllStructSetData($Struct_Meta,"Value",DllStructGetPtr($MemString)) $aResult = DllCall($ghGDIPDll, "int", "GdipSetPropertyItem", "hwnd", $hHandle, "long*", DllStructGetPtr($Struct_Meta)) If @error Then ;~ MsgBox(0,"","") $Struct_Meta = 0 Return SetError(@error, @extended, False) EndIf $Struct_Meta = 0 Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc What I changed was, long to ulong, most likely not the issue, but still it's good to do things properly. int Type to ushort Type, this was important int is 4 bytes, ushort is 2 (would make the GDI+ read to few bytes). The most important thing is how you saved the string, you were trying to save the entire string as a ptr, in C strings are saved in arrays therefore you need to create a struct with a byte[] array in it and then store the pointer to that struct in the Value property. Hope I cleared up some things Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
ChrisL Posted October 10, 2008 Author Share Posted October 10, 2008 Well thanks for the corrections.. but as you pointed out it still doesn't work [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
ChrisL Posted July 1, 2011 Author Share Posted July 1, 2011 Digging up an old post I started a few years ago, I had to revisit this setting of exif meta data and I got it working today, so here is how you do it... expandcollapse popup#include <GDIPlus.au3> Global Const $PropertyTagTypeByte = 1 Global Const $PropertyTagTypeASCII = 2 Global Const $PropertyTagTypeShort = 3 Global Const $PropertyTagTypeLong = 4 Global Const $PropertyTagTypeRational = 5 Global Const $PropertyTagTypeUndefined = 7 Global Const $PropertyTagTypeSLong = 9 Global Const $PropertyTagTypeSRational = 10 _GDIPlus_Startup () $hFile = _GDIPlus_ImageLoadFromFile(@DesktopDir & "\Photo.jpg") _GDIPlus_SetMetaData($hFile,"Make", "Any Old Camera") _GDIPlus_SetMetaData($hFile,"Author", "Chris Lambert") _GDIPlus_SetMetaData($hFile,"Software", "Chris's Application") _GDIPlus_ImageSaveToFile($hFile,@desktopDir & "\New.jpg") _GDIPlus_ImageDispose($hFile) _GDIPlus_Shutdown() Func _GDIPlus_SetMetaData($hHandle,$sTagName, $vStr) Local $tagPropertyItem = "ulong id; ulong length; ushort Type; ptr value" Local $Struct_String, $Struct_Meta, $aResult, $PropertyTagType Switch $sTagName Case "ImageWidth" $ID = 0x100 $PropertyTagType = $PropertyTagTypeShort Case "ImageLength" $ID = 0x101 $PropertyTagType = $PropertyTagTypeShort Case "BitsPerSample" $ID = 0x102 $PropertyTagType = $PropertyTagTypeShort Case "Compression" $ID = 0x103 $PropertyTagType = $PropertyTagTypeShort Case "PhotometricInterpretation" $ID = 0x106 $PropertyTagType = $PropertyTagTypeShort Case "Orientation" $ID = 0x112 $PropertyTagType = $PropertyTagTypeShort Case "SamplesPerPixel" $ID = 0x115 $PropertyTagType = $PropertyTagTypeShort Case "PlanarConfiguration" $ID = 0x11C $PropertyTagType = $PropertyTagTypeShort Case "YCbCrSubSampling" $ID = 0x212 $PropertyTagType = $PropertyTagTypeShort Case "YCbCrPositioning" $ID = 0x213 $PropertyTagType = $PropertyTagTypeShort Case "XResolution" $ID = 0x11A $PropertyTagType = $PropertyTagTypeRational Case "YResolution" $ID = 0x11B $PropertyTagType = $PropertyTagTypeRational Case "ResolutionUnit" $ID = 0x296 $PropertyTagType = $PropertyTagTypeShort Case "StripOffsets" $ID = 0x111 $PropertyTagType = $PropertyTagTypeShort Case "RowsPerStrip" $ID = 0x116 $PropertyTagType = $PropertyTagTypeShort Case "StripByteCounts" $ID = 0x117 $PropertyTagType = $PropertyTagTypeShort Case "JPEGInterchangeFormat" $ID = 0x201 $PropertyTagType = $PropertyTagTypeLong Case "JPEGInterchangeFormatLength" $ID = 0x202 $PropertyTagType = $PropertyTagTypeLong Case "TransferFunction" $ID = 0x12D $PropertyTagType = $PropertyTagTypeShort Case "WhitePoint" $ID = 0x13E $PropertyTagType = $PropertyTagTypeRational Case "PrimaryChromaticities" $ID = 0x13F $PropertyTagType = $PropertyTagTypeRational Case "YCbCrCoefficients" $ID = 0x211 $PropertyTagType = $PropertyTagTypeRational Case "ReferenceBlackWhite" $ID = 0x214 $PropertyTagType = $PropertyTagTypeRational Case "DateTime" $ID = 0x132 $PropertyTagType = $PropertyTagTypeASCII Case "ImageDescription" $ID = 0x10E $PropertyTagType = $PropertyTagTypeASCII Case "Make" $ID = 0x10F $PropertyTagType = $PropertyTagTypeASCII Case "Model" $ID = 0x110 $PropertyTagType = $PropertyTagTypeASCII Case "Software" $ID = 0x131 $PropertyTagType = $PropertyTagTypeASCII Case "Artist", "Author" $ID = 0x13B $PropertyTagType = $PropertyTagTypeASCII Case "Copyright" $ID = 0x8298 $PropertyTagType = $PropertyTagTypeASCII Case Else Return SetError(1, -1, False) EndSwitch ; Store string in array $Struct_String=DllStructCreate("char[" & StringLen($vStr) +1 & "];") DllStructSetData($Struct_String,1,$vStr) $Struct_Meta = DllstructCreate($tagPropertyItem) DllStructSetData($Struct_Meta,"ID",$ID) DllStructSetData($Struct_Meta,"Length",StringLen($vStr) +1) DllStructSetData($Struct_Meta,"Type",$PropertyTagType) DllStructSetData($Struct_Meta,"Value",DllStructGetPtr($Struct_String)) $aResult = DllCall($ghGDIPDll, "int", "GdipSetPropertyItem", "hwnd", $hHandle, "ptr", DllStructGetPtr($Struct_Meta)) If @error Then Return SetError(@error, @extended, False) Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc Parsix 1 [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
matwachich Posted March 2, 2012 Share Posted March 2, 2012 Thanks! Exactly what i was looking for! PS: just a small remak: it doesn't work with PNG files (only JPG) Link to comment Share on other sites More sharing options...
Lupo73 Posted January 23, 2014 Share Posted January 23, 2014 I'm trying to extend this function to work also with other meta data, using these parameters: http://msdn.microsoft.com/en-us/library/ms534416(v=vs.85).aspx#_gdiplus_constant_propertytagexifdtorig But some Exif are not modified. Do you know if there are some limits following this way? This is the updated code I'm using: expandcollapse popupFunc _GDIPlus_SetMetaData($hHandle, $sTagName, $vStr) Local $tagPropertyItem = "ulong id; ulong length; ushort Type; ptr value" Local $Struct_String, $Struct_Meta, $aResult, $PropertyTagType Local Const $PropertyTagTypeByte = 1 Local Const $PropertyTagTypeASCII = 2 Local Const $PropertyTagTypeShort = 3 Local Const $PropertyTagTypeLong = 4 Local Const $PropertyTagTypeRational = 5 Local Const $PropertyTagTypeUndefined = 7 Local Const $PropertyTagTypeSLong = 9 Local Const $PropertyTagTypeSRational = 10 Switch $sTagName Case "ImageWidth" $ID = 0x100 $PropertyTagType = $PropertyTagTypeShort Case "ImageLength" $ID = 0x101 $PropertyTagType = $PropertyTagTypeShort Case "BitsPerSample" $ID = 0x102 $PropertyTagType = $PropertyTagTypeShort Case "Compression" $ID = 0x103 $PropertyTagType = $PropertyTagTypeShort Case "PhotometricInterpretation" $ID = 0x106 $PropertyTagType = $PropertyTagTypeShort Case "Orientation" $ID = 0x112 $PropertyTagType = $PropertyTagTypeShort Case "SamplesPerPixel" $ID = 0x115 $PropertyTagType = $PropertyTagTypeShort Case "PlanarConfiguration" $ID = 0x11C $PropertyTagType = $PropertyTagTypeShort Case "YCbCrSubSampling" $ID = 0x212 $PropertyTagType = $PropertyTagTypeShort Case "YCbCrPositioning" $ID = 0x213 $PropertyTagType = $PropertyTagTypeShort Case "XResolution" $ID = 0x11A $PropertyTagType = $PropertyTagTypeRational Case "YResolution" $ID = 0x11B $PropertyTagType = $PropertyTagTypeRational Case "ResolutionUnit" $ID = 0x296 $PropertyTagType = $PropertyTagTypeShort Case "StripOffsets" $ID = 0x111 $PropertyTagType = $PropertyTagTypeShort Case "RowsPerStrip" $ID = 0x116 $PropertyTagType = $PropertyTagTypeShort Case "StripByteCounts" $ID = 0x117 $PropertyTagType = $PropertyTagTypeShort Case "JPEGInterchangeFormat" $ID = 0x201 $PropertyTagType = $PropertyTagTypeLong Case "JPEGInterchangeFormatLength" $ID = 0x202 $PropertyTagType = $PropertyTagTypeLong Case "TransferFunction" $ID = 0x12D $PropertyTagType = $PropertyTagTypeShort Case "WhitePoint" $ID = 0x13E $PropertyTagType = $PropertyTagTypeRational Case "PrimaryChromaticities" $ID = 0x13F $PropertyTagType = $PropertyTagTypeRational Case "YCbCrCoefficients" $ID = 0x211 $PropertyTagType = $PropertyTagTypeRational Case "ReferenceBlackWhite" $ID = 0x214 $PropertyTagType = $PropertyTagTypeRational Case "DateTime" $ID = 0x132 $PropertyTagType = $PropertyTagTypeASCII Case "ImageDescription" $ID = 0x10E $PropertyTagType = $PropertyTagTypeASCII Case "Make" $ID = 0x10F $PropertyTagType = $PropertyTagTypeASCII Case "Model" $ID = 0x110 $PropertyTagType = $PropertyTagTypeASCII Case "Software" $ID = 0x131 $PropertyTagType = $PropertyTagTypeASCII Case "Artist", "Author" $ID = 0x13B $PropertyTagType = $PropertyTagTypeASCII Case "ImageTitle" $ID = 0x320 $PropertyTagType = $PropertyTagTypeASCII Case "Copyright" $ID = 0x8298 $PropertyTagType = $PropertyTagTypeASCII Case "ExposureTime" $ID = 0x829A $PropertyTagType = $PropertyTagTypeRational Case "FNumber" $ID = 0x829D $PropertyTagType = $PropertyTagTypeRational Case "ISO" $ID = 0x8827 $PropertyTagType = $PropertyTagTypeShort Case "ExifVersion" $ID = 0x9000 $PropertyTagType = $PropertyTagTypeUndefined Case "DateTimeOriginal" $ID = 0x9003 $PropertyTagType = $PropertyTagTypeASCII Case "DateTimeDigitized" $ID = 0x9004 $PropertyTagType = $PropertyTagTypeASCII Case "ExposureBiasValue" $ID = 0x9204 $PropertyTagType = $PropertyTagTypeSRational Case "FocalLength" $ID = 0x920A $PropertyTagType = $PropertyTagTypeRational Case "ShutterSpeedValue" $ID = 0x9201 $PropertyTagType = $PropertyTagTypeSRational Case "ApertureValue" $ID = 0x9202 $PropertyTagType = $PropertyTagTypeRational Case "BrightnessValue" $ID = 0x9203 $PropertyTagType = $PropertyTagTypeSRational Case "MaxApertureValue" $ID = 0x9205 $PropertyTagType = $PropertyTagTypeRational Case "SubjectDistance" $ID = 0x9206 $PropertyTagType = $PropertyTagTypeRational Case "UserComments" $ID = 0x9286 $PropertyTagType = $PropertyTagTypeUndefined Case Else Return SetError(1, -1, False) EndSwitch ConsoleWrite("$sTagName = " & $sTagName & " | $vStr = " & $vStr & @LF) ; Store String In Array: $Struct_String = DllStructCreate("char[" & StringLen($vStr) +1 & "];") DllStructSetData($Struct_String, 1, $vStr) $Struct_Meta = DllstructCreate($tagPropertyItem) DllStructSetData($Struct_Meta, "ID", $ID) DllStructSetData($Struct_Meta, "Length", StringLen($vStr) +1) DllStructSetData($Struct_Meta, "Type", $PropertyTagType) DllStructSetData($Struct_Meta, "Value", DllStructGetPtr($Struct_String)) $aResult = DllCall($ghGDIPDll, "int", "GdipSetPropertyItem", "hwnd", $hHandle, "ptr", DllStructGetPtr($Struct_Meta)) If @error Then Return SetError(@error, @extended, False) EndIf Return SetError($aResult[0], 0, $aResult[0] = 0) EndFunc ;==>_GDIPlus_SetMetaData Parsix 1 SFTPEx, AutoCompleteInput, _DateTimeStandard(), _ImageWriteResize(), _GUIGraduallyHide(): some AutoIt functions. Lupo PenSuite: all-in-one and completely free selection of portable programs and games. DropIt: a personal assistant to automatically manage your files. ArcThemALL!: application to multi-archive your files and folders. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now