コード例 #1
0
		private void InitSprite(Bitmap bmp, int cols, int rows)
		{
			if (bmp.PixelFormat != PixelFormat.Format8bppIndexed)
				throw new Exception("Image must be 8bpp indexed");
			var image = bmp.Bitmap8ToPixels();
			var paleta = bmp.Palette;
			var imgsz = bmp.Size;
			var sz = new Size(imgsz.Width / cols, imgsz.Height / rows);
			var rect = new Rectangle(Point.Empty, sz);
			for (var f = 0; f < rows; f++)
			{
				for (var g = 0; g < cols; g++)
				{
					rect.Location = new Point(g * sz.Width, f * sz.Height);
					var img = new Bitmap(rect.Width, rect.Height, PixelFormat.Format8bppIndexed);
					img.SetPalette(paleta.Entries);
					img.PixelsToBitmap8(rect, image);
					RawSprites.Add(img);
				}
			}
		}
コード例 #2
0
		public void SetImage(byte[] image)
		{
			var img = new Bitmap(ImageWidth, ImageHeight, PixelFormat.Format8bppIndexed);
			img.PixelsToBitmap8(image);
			Frame = img;
			SetImagePalette();
		}
コード例 #3
0
		public static Bitmap ToIndexFormat(this Bitmap image, Color[] palette)
		{
			var sz = image.Size;
			var res = new Bitmap(sz.Width, sz.Height, PixelFormat.Format8bppIndexed);
			res.SetPalette(palette);
			var bmpdataori = image.Bitmap32ToPixels();
			var bmpdatadest = new byte[sz.Height][];
			var dic = new Dictionary<int, int>();
			for (var f = 0; f < sz.Height; f++)
			{
				var pixelsori = bmpdataori[f];
				var pixeldest = ReduceLine(pixelsori, palette,dic);
				bmpdatadest[f] = pixeldest;
				Debug.Print($"Scanline {f} colors {dic.Count}");
			}
			res.PixelsToBitmap8(bmpdatadest);
			return res;
		}