implement Image.SetPropertyItem() method v4 (#1167)
authorralovich <ralovich@users.noreply.github.com>
Mon, 5 Jun 2017 23:43:41 +0000 (19:43 -0400)
committerMiguel de Icaza <miguel@gnome.org>
Mon, 5 Jun 2017 23:43:41 +0000 (19:43 -0400)
This is thought to be fixing https://bugzilla.novell.com/show_bug.cgi?id=406307.

v4: state that my changes are licensed under MIT X11 license

mcs/class/System.Drawing/System.Drawing/Image.cs

index 6bd89918dd66815ca07baedfa7a8a3762c54c53f..528d91004faa7372446cc5bc9081f77be8a04a28 100644 (file)
@@ -10,6 +10,7 @@
 //
 // Copyright (C) 2002 Ximian, Inc.  http://www.ximian.com
 // Copyright (C) 2004, 2007 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2013 Kristof Ralovich, changes are available under the terms of the MIT X11 license
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -529,16 +530,30 @@ public abstract class Image : MarshalByRefObject, IDisposable , ICloneable, ISer
 
        public void SetPropertyItem(PropertyItem propitem)
        {
-               throw new NotImplementedException ();
-/*
-               GdipPropertyItem pi = new GdipPropertyItem ();
-               GdipPropertyItem.MarshalTo (pi, propitem);
-               unsafe {
-                       Status status = GDIPlus.GdipSetPropertyItem (nativeObject, &pi);
+               if (propitem == null)
+                       throw new ArgumentNullException ("propitem");
+
+               int nItemSize =  Marshal.SizeOf (propitem.Value[0]);
+               int size = nItemSize * propitem.Value.Length;
+               IntPtr dest = Marshal.AllocHGlobal (size);
+               try {
+                       GdipPropertyItem pi = new GdipPropertyItem ();
+                       pi.id    = propitem.Id;
+                       pi.len   = propitem.Len;
+                       pi.type  = propitem.Type;
+
+                       Marshal.Copy (propitem.Value, 0, dest, size);
+                       pi.value = dest;
+
+                       unsafe {
+                               Status status = GDIPlus.GdipSetPropertyItem (nativeObject, &pi);
                        
-                       GDIPlus.CheckStatus (status);
+                               GDIPlus.CheckStatus (status);
+                       }
+               }
+               finally {
+                       Marshal.FreeHGlobal (dest);
                }
-*/
        }
 
        // properties