Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Test code for rotating 8-bit, 16-bit and 24-bit Bitmap objects.

(libgdiplus does not currently support 16-bit Bitmaps.)

svn path=/trunk/winforms/; revision=52112
  • Loading branch information...
commit f71de776be803104ffa1a102a2ebadbc3ac5a498 1 parent 9c8c5bf
Jonathan Gilbert authored
View
BIN  rotate/24bit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN  rotate/8bit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
12 rotate/Makefile
@@ -0,0 +1,12 @@
+all: test
+
+test: clean test.exe
+ mono test.exe
+
+test.exe: test.cs
+ mcs test.cs -r:System.Drawing
+
+clean:
+ rm -f test.exe *_Rotate*.png
+
+.PHONY: all test clean
View
88 rotate/test.cs
@@ -0,0 +1,88 @@
+using System;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
+
+class Test
+{
+ static Bitmap load(string name)
+ {
+ using (Stream stream = new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.None))
+ return (Bitmap)Bitmap.FromStream(stream);
+ }
+
+ static void Main()
+ {
+ foreach (string type_name in Enum.GetNames(typeof(RotateFlipType)))
+ {
+ RotateFlipType type = (RotateFlipType)Enum.Parse(typeof(RotateFlipType), type_name);
+
+ if (type_name != type.ToString())
+ Console.WriteLine("- processing {0} ({1})...", type_name, type);
+ else
+ Console.WriteLine("- processing {0}...", type_name);
+
+ Bitmap result = null;
+
+ try
+ {
+ result = load("24bit.png");
+ result.RotateFlip(type);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("EXCEPTION (24-bit): {0}: {1}", e.GetType().Name, e.Message);
+ if (result != null) try { result.Dispose(); } catch {}
+ result = null;
+ }
+
+ if (result != null)
+ result.Save("24bit_" + type_name + ".png", ImageFormat.Png);
+
+ try { result.Dispose(); } catch {}
+
+ try
+ {
+ Bitmap intermediate = load("24bit.png");
+ result = new Bitmap(intermediate.Width, intermediate.Height, PixelFormat.Format16bppRgb565);
+ using (Graphics g = Graphics.FromImage(result))
+ {
+ Rectangle bounds = new Rectangle(0, 0, result.Width, result.Height);
+ g.DrawImage(intermediate, bounds, bounds, GraphicsUnit.Pixel);
+ }
+
+ result.RotateFlip(type);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("EXCEPTION (16-bit): {0}: {1}", e.GetType().Name, e.Message);
+ if (result != null) try { result.Dispose(); } catch {}
+ result = null;
+ }
+
+ if (result != null)
+ result.Save("16bit_" + type_name + ".png", ImageFormat.Png);
+
+ try { result.Dispose(); } catch {}
+
+ try
+ {
+ result = load("8bit.png");
+ result.RotateFlip(type);
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine("EXCEPTION (8-bit): {0}: {1}", e.GetType().Name, e.Message);
+ if (result != null) try { result.Dispose(); } catch {}
+ result = null;
+ }
+
+ if (result != null)
+ result.Save("8bit_" + type_name + ".png", ImageFormat.Png);
+
+ try { result.Dispose(); } catch {}
+ }
+
+ Console.WriteLine("done!");
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.