示例#1
0
        public IBitmap ApplyArea(IArea area)
        {
            //todo: performance can be improved by only creating a bitmap the size of the area, and not the entire background.
            //This will require to change the rendering as well to offset the location
            byte   zero   = (byte)0;
            Bitmap output = Bitmap.CreateBitmap(Width, Height, Bitmap.Config.Argb8888);

            using (FastBitmap inBmp = new FastBitmap(_bitmap))
            {
                using (FastBitmap outBmp = new FastBitmap(output, true))
                {
                    for (int y = 0; y < Height; y++)
                    {
                        int bitmapY = Height - y - 1;
                        for (int x = 0; x < Width; x++)
                        {
                            global::Android.Graphics.Color color = inBmp.GetPixel(x, bitmapY);
                            byte alpha = area.IsInArea(new AGS.API.PointF(x, y)) ? color.A : zero;
                            outBmp.SetPixel(x, bitmapY, new global::Android.Graphics.Color(color.R, color.G, color.B, alpha));
                        }
                    }
                }
            }

            return(new AndroidBitmap(output, _graphics));
        }
示例#2
0
		public IBitmap ApplyArea(IArea area)
		{
			//todo: performance can be improved by only creating a bitmap the size of the area, and not the entire background.
			//This will require to change the rendering as well to offset the location
			byte zero = (byte)0;
			Bitmap output = Bitmap.CreateBitmap(Width, Height, Bitmap.Config.Argb8888);
			using (FastBitmap inBmp = new FastBitmap (_bitmap))
			{
				using (FastBitmap outBmp = new FastBitmap (output, true))
				{
					for (int y = 0; y < Height; y++)
					{
						int bitmapY = Height - y - 1;
						for (int x = 0; x < Width; x++)
						{
							global::Android.Graphics.Color color = inBmp.GetPixel(x, bitmapY);
							byte alpha = area.IsInArea(new AGS.API.PointF(x, y)) ? color.A : zero;
							outBmp.SetPixel(x, bitmapY, new global::Android.Graphics.Color(color.R, color.G, color.B, alpha));
						}
					}
				}
			}

            return new AndroidBitmap(output, _graphics);
		}
示例#3
0
		public void MakeTransparent(AGS.API.Color color)
		{
			global::Android.Graphics.Color c = new global::Android.Graphics.Color(color.R, color.G, color.B, color.A);
			global::Android.Graphics.Color transparent = global::Android.Graphics.Color.Transparent;
			using (FastBitmap fastBitmap = new FastBitmap (_bitmap))
			{
				for (int x = 0; x < _bitmap.Width; x++)
				{
					for (int y = 0; y < _bitmap.Height; y++)
					{
						if (fastBitmap.GetPixel(x, y) == c)
							fastBitmap.SetPixel(x, y, c);
					}
				}
			}
		}
示例#4
0
 public void MakeTransparent(AGS.API.Color color)
 {
     global::Android.Graphics.Color c           = new global::Android.Graphics.Color(color.R, color.G, color.B, color.A);
     global::Android.Graphics.Color transparent = global::Android.Graphics.Color.Transparent;
     using (FastBitmap fastBitmap = new FastBitmap(_bitmap))
     {
         for (int x = 0; x < Width; x++)
         {
             for (int y = 0; y < Height; y++)
             {
                 if (fastBitmap.GetPixel(x, y) == c)
                 {
                     fastBitmap.SetPixel(x, y, transparent);
                 }
             }
         }
     }
 }
示例#5
0
		public IMask CreateMask(IGameFactory factory, string path, bool transparentMeansMasked = false, 
			AGS.API.Color? debugDrawColor = null, string saveMaskToFile = null, string id = null)
		{
			Bitmap debugMask = null;
			FastBitmap debugMaskFast = null;
			if (saveMaskToFile != null || debugDrawColor != null)
			{
				debugMask = Bitmap.CreateBitmap (Width, Height, Bitmap.Config.Argb8888);
				debugMaskFast = new FastBitmap (debugMask, true);
			}

			bool[][] mask = new bool[Width][];
			global::Android.Graphics.Color drawColor = debugDrawColor != null ? debugDrawColor.Value.Convert() : global::Android.Graphics.Color.Black;

			using (FastBitmap bitmapData = new FastBitmap (_bitmap))
			{
				for (int x = 0; x < Width; x++)
				{
					for (int y = 0; y < Height; y++)
					{
						var pixelColor = bitmapData.GetPixel(x, y);

						bool masked = pixelColor.A == 255;
						if (transparentMeansMasked)
							masked = !masked;

						if (mask[x] == null)
							mask[x] = new bool[Height];
						mask[x][Height - y - 1] = masked;

						if (debugMask != null)
						{
							debugMaskFast.SetPixel(x, y, masked ? drawColor : global::Android.Graphics.Color.Transparent);
						}
					}
				}
			}

			if (debugMask != null)
				debugMaskFast.Dispose();

			//Save the duplicate
			if (saveMaskToFile != null)
			{
				using (Stream stream = Hooks.FileSystem.Create(saveMaskToFile))
				{
					debugMask.Compress(global::Android.Graphics.Bitmap.CompressFormat.Png, 100, stream);
				}
			}	

			IObject debugDraw = null;
			if (debugDrawColor != null)
			{
				debugDraw = factory.Object.GetObject(id ?? path ?? "Mask Drawable");
                debugDraw.Image = factory.Graphics.LoadImage(new AndroidBitmap(debugMask, _graphics), null, path);
				debugDraw.Anchor = new AGS.API.PointF ();
			}

			return new AGSMask (mask, debugDraw);
		}