// Authors:
// Sebastien Pouliot <sebastien@ximian.com>
//
-// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
}
}
+ [Test]
+ public void Icon ()
+ {
+ string filename = TestBitmap.getInFile ("bitmaps/64x64x256.ico");
+ IntPtr bitmap;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCreateBitmapFromFile (filename, out bitmap), "GdipCreateBitmapFromFile");
+ try {
+ int size;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImagePaletteSize (bitmap, out size), "GdipGetImagePaletteSize");
+ Assert.AreEqual (1032, size, "size");
+
+ IntPtr clone;
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipCloneImage (bitmap, out clone), "GdipCloneImage");
+ try {
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImagePaletteSize (clone, out size), "GdipGetImagePaletteSize/Clone");
+ Assert.AreEqual (1032, size, "size/clone");
+ }
+ finally {
+ GDIPlus.GdipDisposeImage (clone);
+ }
+
+ IntPtr palette = Marshal.AllocHGlobal (size);
+ try {
+
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetImagePalette (IntPtr.Zero, palette, size), "GdipGetImagePalette(null,palette,size)");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetImagePalette (bitmap, IntPtr.Zero, size), "GdipGetImagePalette(bitmap,null,size)");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipGetImagePalette (bitmap, palette, 0), "GdipGetImagePalette(bitmap,palette,0)");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImagePalette (bitmap, palette, size), "GdipGetImagePalette");
+
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipSetImagePalette (IntPtr.Zero, palette), "GdipSetImagePalette(null,palette)");
+ Assert.AreEqual (Status.InvalidParameter, GDIPlus.GdipSetImagePalette (bitmap, IntPtr.Zero), "GdipSetImagePalette(bitmap,null)");
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipSetImagePalette (bitmap, palette), "GdipSetImagePalette");
+
+ // change palette to 0 entries
+ int flags = Marshal.ReadInt32 (palette);
+ Marshal.WriteInt64 (palette, flags << 32);
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipSetImagePalette (bitmap, palette), "GdipSetImagePalette/Empty");
+
+ Assert.AreEqual (Status.Ok, GDIPlus.GdipGetImagePaletteSize (bitmap, out size), "GdipGetImagePaletteSize/Empty");
+ Assert.AreEqual (8, size, "size");
+ }
+ finally {
+ Marshal.FreeHGlobal (palette);
+ }
+ }
+ finally {
+ GDIPlus.GdipDisposeImage (bitmap);
+ }
+ }
+
[Test]
public void Encoder ()
{
// Sanjay Gupta <gsanjay@novell.com>
// Sebastien Pouliot <sebastien@ximian.com>
//
-// Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004,2006-2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
using System;
using System.Drawing;
+using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using System.Security.Permissions;
Icon icon;
Icon newIcon;
+ Icon icon16, icon32, icon48, icon64, icon96;
FileStream fs;
FileStream fs1;
String path = TestBitmap.getInFile ("bitmaps/smiley.ico");
icon = new Icon (path);
fs1 = new FileStream (path, FileMode.Open);
+
+ icon16 = new Icon (TestBitmap.getInFile ("bitmaps/16x16x16.ico"));
+ icon32 = new Icon (TestBitmap.getInFile ("bitmaps/32x32x16.ico"));
+ icon48 = new Icon (TestBitmap.getInFile ("bitmaps/48x48x1.ico"));
+ icon64 = new Icon (TestBitmap.getInFile ("bitmaps/64x64x256.ico"));
+ icon96 = new Icon (TestBitmap.getInFile ("bitmaps/96x96x256.ico"));
}
[TearDown]
File.Delete ("newIcon.ico");
}
-
[Test]
#if TARGET_JVM
[Category ("NotWorking")]
#endif
public void TestConstructors ()
{
+ Assert.AreEqual (32, icon.Height, "C#0a");
+ Assert.AreEqual (32, icon.Width, "C#0b");
+
newIcon = new Icon (fs1, 48, 48);
Assert.AreEqual (48, newIcon.Height, "C#1a");
Assert.AreEqual (48, newIcon.Width, "C#1b");
Assert.AreEqual (32, icon.Width, "P#2");
Assert.AreEqual (32, icon.Size.Width, "P#3");
Assert.AreEqual (32, icon.Size.Height, "P#4");
-
}
[Test]
Assert.AreEqual (fs1.Length, fs.Length, "M#3");
}
+
+ [Test]
+ public void Icon16ToBitmap ()
+ {
+ using (Bitmap b = icon16.ToBitmap ()) {
+ Assert.AreEqual (PixelFormat.Format32bppArgb, b.PixelFormat, "PixelFormat");
+ // unlike the GDI+ icon decoder the palette isn't kept
+ Assert.AreEqual (0, b.Palette.Entries.Length, "Palette");
+ Assert.AreEqual (icon16.Height, b.Height, "Height");
+ Assert.AreEqual (icon16.Width, b.Width, "Width");
+ Assert.IsTrue (b.RawFormat.Equals (ImageFormat.MemoryBmp), "RawFormat");
+ Assert.AreEqual (2, b.Flags, "Flags");
+ }
+ }
+
+ [Test]
+ public void Icon32ToBitmap ()
+ {
+ using (Bitmap b = icon32.ToBitmap ()) {
+ Assert.AreEqual (PixelFormat.Format32bppArgb, b.PixelFormat, "PixelFormat");
+ // unlike the GDI+ icon decoder the palette isn't kept
+ Assert.AreEqual (0, b.Palette.Entries.Length, "Palette");
+ Assert.AreEqual (icon32.Height, b.Height, "Height");
+ Assert.AreEqual (icon32.Width, b.Width, "Width");
+ Assert.IsTrue (b.RawFormat.Equals (ImageFormat.MemoryBmp), "RawFormat");
+ Assert.AreEqual (2, b.Flags, "Flags");
+ }
+ }
+
+ [Test]
+ public void Icon48ToBitmap ()
+ {
+ using (Bitmap b = icon48.ToBitmap ()) {
+ Assert.AreEqual (PixelFormat.Format32bppArgb, b.PixelFormat, "PixelFormat");
+ // unlike the GDI+ icon decoder the palette isn't kept
+ Assert.AreEqual (0, b.Palette.Entries.Length, "Palette");
+ Assert.AreEqual (icon48.Height, b.Height, "Height");
+ Assert.AreEqual (icon48.Width, b.Width, "Width");
+ Assert.IsTrue (b.RawFormat.Equals (ImageFormat.MemoryBmp), "RawFormat");
+ Assert.AreEqual (2, b.Flags, "Flags");
+ }
+ }
+
+ [Test]
+ public void Icon64ToBitmap ()
+ {
+ using (Bitmap b = icon64.ToBitmap ()) {
+ Assert.AreEqual (PixelFormat.Format32bppArgb, b.PixelFormat, "PixelFormat");
+ // unlike the GDI+ icon decoder the palette isn't kept
+ Assert.AreEqual (0, b.Palette.Entries.Length, "Palette");
+ Assert.AreEqual (icon64.Height, b.Height, "Height");
+ Assert.AreEqual (icon64.Width, b.Width, "Width");
+ Assert.IsTrue (b.RawFormat.Equals (ImageFormat.MemoryBmp), "RawFormat");
+ Assert.AreEqual (2, b.Flags, "Flags");
+ }
+ }
+
+ [Test]
+ public void Icon96ToBitmap ()
+ {
+ using (Bitmap b = icon96.ToBitmap ()) {
+ Assert.AreEqual (PixelFormat.Format32bppArgb, b.PixelFormat, "PixelFormat");
+ // unlike the GDI+ icon decoder the palette isn't kept
+ Assert.AreEqual (0, b.Palette.Entries.Length, "Palette");
+ Assert.AreEqual (icon96.Height, b.Height, "Height");
+ Assert.AreEqual (icon96.Width, b.Width, "Width");
+ Assert.IsTrue (b.RawFormat.Equals (ImageFormat.MemoryBmp), "RawFormat");
+ Assert.AreEqual (2, b.Flags, "Flags");
+ }
+ }
+
#if NET_2_0
[Test]
[ExpectedException (typeof (ArgumentException))]