* System.Drawing/Image.cs: On win32, when cloning images initialized from
[mono.git] / mcs / class / System.Drawing / System.Drawing.Imaging / EncoderParameter.cs
index 89fd331325de20be2fe4847ba42e1a6aad85228f..f21831faa49f42af62d3669d57a509e58db0957e 100644 (file)
@@ -38,6 +38,7 @@ using System.Runtime.InteropServices;
 
 namespace System.Drawing.Imaging {
 
+       [StructLayout(LayoutKind.Sequential)]
        public sealed class EncoderParameter : IDisposable {
 
                private Encoder encoder;
@@ -164,12 +165,9 @@ namespace System.Drawing.Imaging {
                        this.valuesCount = numerator.Length;
                        this.type = EncoderParameterValueType.ValueTypeRational;
                        this.valuePtr = Marshal.AllocHGlobal (4 * valuesCount * 2);
-                       IntPtr dest = this.valuePtr;
                        for (int i = 0; i < valuesCount; i++) {
-                               Marshal.WriteInt32 (dest, (int) numerator[i]);
-                               dest = (IntPtr) ((int) dest + 4);
-                               Marshal.WriteInt32 (dest, (int) denominator[i]);
-                               dest = (IntPtr) ((int) dest + 4);
+                               Marshal.WriteInt32 (valuePtr, i * 4, (int) numerator[i]);
+                               Marshal.WriteInt32 (valuePtr, (i + 1) * 4, (int) denominator[i]);
                        }
                }
 
@@ -195,10 +193,8 @@ namespace System.Drawing.Imaging {
                        this.valuePtr = Marshal.AllocHGlobal (4 * valuesCount * 2);
                        IntPtr dest = this.valuePtr;
                        for (int i = 0; i < valuesCount; i++) {
-                               Marshal.WriteInt32 (dest, (int) rangebegin[i]);
-                               dest = (IntPtr) ((int) dest + 4);
-                               Marshal.WriteInt32 (dest, (int) rangeend[i]);
-                               dest = (IntPtr) ((int) dest + 4);
+                               Marshal.WriteInt32 (dest, i * 4, (int) rangebegin[i]);
+                               Marshal.WriteInt32 (dest, (i + 1) * 4, (int) rangeend[i]);
                        }
                }
 
@@ -234,14 +230,10 @@ namespace System.Drawing.Imaging {
                        this.valuePtr = Marshal.AllocHGlobal (4 * valuesCount * 4);
                        IntPtr dest = this.valuePtr;
                        for (int i = 0; i < valuesCount; i++) {
-                               Marshal.WriteInt32 (dest, numerator1[i]);
-                               dest = (IntPtr) ((int) dest + 4);
-                               Marshal.WriteInt32 (dest, denominator1[i]);
-                               dest = (IntPtr) ((int) dest + 4);
-                               Marshal.WriteInt32 (dest, numerator2[i]);
-                               dest = (IntPtr) ((int) dest + 4);
-                               Marshal.WriteInt32 (dest, denominator2[i]);
-                               dest = (IntPtr) ((int) dest + 4);
+                               Marshal.WriteInt32 (dest, i * 4, numerator1[i]);
+                               Marshal.WriteInt32 (dest, (i + 1) * 4, denominator1[i]);
+                               Marshal.WriteInt32 (dest, (i + 2) * 4, numerator2[i]);
+                               Marshal.WriteInt32 (dest, (i + 3) * 4, denominator2[i]);
                        }
                }