Alex Shulgin wrote:
Alex Shulgin wrote:
Sebastien Pouliot wrote:
Sounds correct but will requires a lot of testing. Please open a bug
report for this  and copy/paste the email info into it (otherwise we'll
lose track of important data).

Thanks, filed a bug here: https://bugzilla.novell.com/show_bug.cgi?id=495516

Will prepare a patch soon.

Hi all again!

I'm not posting this to the bug report, because there might be quite a discussion about this patch.

Oh, yeah, and here's the test app I'm currently using (attached).

--
Alex

// -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 4; -*-
using System;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

namespace AlphaBlend
{
	class MainClass
	{
		public static void Main(string[] args) {
			DrawingTest();
			GreenLineTest();
			MixedMaskTest();
			LoadSaveTest();
			LoadAndDrawTest();
		}

		static void DrawingTest() {
			Bitmap canvas = new Bitmap(32, 32);

			Bitmap mask = new Bitmap(32, 32); //, PixelFormat.Format32bppPArgb);

			for (int y = 0; y < 32; ++y)
				for (int x = 0; x < 32; ++x) {
					int a = (x + y)*4;
					mask.SetPixel(x, y, Color.FromArgb(a, 255, 255, 255));
				}
			Console.WriteLine("mask[15,15]: {0}", mask.GetPixel(15, 15));

			mask.Save("drawing-1mask.png");

			using (Graphics g = Graphics.FromImage(canvas)) {
				using (SolidBrush b = new SolidBrush(Color.Red))
					g.FillRectangle(b, new Rectangle(0, 0, canvas.Width, canvas.Height));

				g.DrawImage(mask, 0, 0);
			}
			Console.WriteLine("canvas[15,15]: {0}", canvas.GetPixel(15, 15));

			canvas.Save("drawing-2canvas.png");
		}

		static void GreenLineTest() {
			Color color = Color.FromArgb(127, 0, 255, 0);

			Bitmap bmp1 = new Bitmap(32, 32);
			for (int i = 0; i < 32; ++i)
				bmp1.SetPixel(i, i, color);

			Bitmap bmp2 = new Bitmap(32, 32);
			using (Graphics g = Graphics.FromImage(bmp2)) {
				using (Pen p = new Pen(color, 1))
				  g.DrawLine(p, 0, 0, 31, 31);
			}

			Console.WriteLine("bmp1[15, 15]: {0} ({1})", bmp1.GetPixel(15, 15), bmp1.PixelFormat);
			Console.WriteLine("bmp2[15, 15]: {0} ({1})", bmp2.GetPixel(15, 15), bmp2.PixelFormat);
		}

		static void MixedMaskTest() {
			Color color = Color.FromArgb(127, 255, 255, 255);

			Bitmap mask = new Bitmap(32, 32);
			for (int y = 0; y < 16; ++y)
				for (int x = 0; x < 32; ++x)
					mask.SetPixel(x, y, color);

			mask.Save("mixedmask-0.png");

			using (Graphics g = Graphics.FromImage(mask))
				using (SolidBrush b = new SolidBrush(color))
				g.FillRectangle(b, new Rectangle(0, 16, 32, 32));

			mask.Save("mixedmask-1.png");

			Console.WriteLine("mixedmask: [10, 10]: {0}", mask.GetPixel(10, 10));
			Console.WriteLine("mixedmask: [20, 20]: {0}", mask.GetPixel(20, 20));
		}

		static void LoadSaveTest() {
			Bitmap mask = new Bitmap("gimpmask.png");
			Console.WriteLine("mask: {0}, @(4,4): {1}", mask.PixelFormat, mask.GetPixel(4, 4));
			mask.Save("savedmask.png");

			mask = new Bitmap("savedmask.png");
			Console.WriteLine("load: {0}, @(4,4): {1}", mask.PixelFormat, mask.GetPixel(4, 4));
		}

		static void LoadAndDrawTest() {
			Bitmap mask = new Bitmap("gimpmask.png");
			Bitmap canvas = new Bitmap(mask.Width, mask.Height);
			using (Graphics g = Graphics.FromImage(canvas)) {
				using (SolidBrush b = new SolidBrush(Color.Red))
					g.FillRectangle(b, new Rectangle(0, 0, canvas.Width, canvas.Height));

				g.DrawImage(mask, 0, 0);
			}
			canvas.Save("maskoncanvas.png");
		}
	}
}

<<inline: gimpmask.png>>

_______________________________________________
Mono-winforms-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-winforms-list

Reply via email to