Notifications
Clear all

[Closed] BitmapMetadata

C# code

-- Stream pngStream = new System.IO.FileStream("smiley.png", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
-- PngBitmapDecoder pngDecoder = new PngBitmapDecoder(pngStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
-- BitmapFrame pngFrame = pngDecoder.Frames[0];
-- InPlaceBitmapMetadataWriter pngInplace = pngFrame.CreateInPlaceBitmapMetadataWriter();
-- if (pngInplace.TrySave() == true)
-- { pngInplace.SetQuery("/Text/Description", "Have a nice day."); }
-- pngStream.Close();

Translation to maxscript

dotnet.loadAssembly "PresentationCore.dll"
file=@"c:\Temp\wood.png"
FileMode=dotNetClass "System.IO.FileMode"
FileAccess=dotNetClass "System.IO.FileAccess"
FileShare=dotNetClass "System.IO.FileShare"
pngStream = dotNetObject "System.IO.FileStream" file FileMode.Open FileAccess.ReadWrite FileShare.ReadWrite;

BitmapCreateOptions=dotNetClass "System.Windows.Media.Imaging.BitmapCreateOptions"
BitmapCacheOption=dotNetClass "System.Windows.Media.Imaging.BitmapCacheOption"
pngDecoder = dotNetObject "System.Windows.Media.Imaging.PngBitmapDecoder"  pngStream  BitmapCreateOptions.PreservePixelFormat BitmapCacheOption.Default;

pngFrame = pngDecoder.Frames.Item[dotNetObject "System.Int32" 0]

On the last line of the script gives an error

-- Runtime error: dotNet runtime exception: Specified value of type 'System.Windows.Media.Imaging.BitmapFrameDecode' must have IsFrozen set to false to modify.

Thanks