private void CreateImage() { _Image = new Bitmap(32, 32); Color[] cols = null; if (_Pattern == null && _PreviewSprite != null) { cols = ((Texture2D)_PreviewSprite.texture).GetPixels(); } for (int y = 0; y < 32; y++) { for (int x = 0; x < 32; x++) { if (_Pattern != null) { int index = _Pattern.GetPixel(x, y); System.Drawing.Color col = System.Drawing.Color.FromArgb(0, 0, 0, 0); if (index < 15) { col = System.Drawing.Color.FromArgb(_Pattern.Palette[index].R, _Pattern.Palette[index].G, _Pattern.Palette[index].B); } _Image.SetPixel(x, y, col); } else if (cols != null) { _Image.SetPixel(x, 32 - y, System.Drawing.Color.FromArgb((byte)(cols[x + y * 32].a * 255f), (byte)(cols[x + y * 32].r * 255f), (byte)(cols[x + y * 32].g * 255f), (byte)(cols[x + y * 32].b * 255f))); } } } }
public static TextureBitmap GetBitmap(this DesignPattern pattern) { int width = pattern.Width; int height = pattern.Height; var bitmap = new TextureBitmap(width, height); unsafe { TextureBitmap.Color *ptr = bitmap.GetColors(); for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { var b = pattern.GetPixel(x, y); if (b == 15) { *(ptr + x + (height - 1 - y) * width) = new TextureBitmap.Color(0, 0, 0, 0); } else { var c = pattern.Palette[b]; *(ptr + x + (height - 1 - y) * width) = new TextureBitmap.Color(c.R, c.G, c.B, 255); } } } } return(bitmap); }
public static System.Drawing.Bitmap GetBitmap(this DesignPattern pattern) { int width = pattern.Width; int height = pattern.Height; var bitmap = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); var data = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); var pixelSize = data.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb ? 4 : 3; var padding = data.Stride - (data.Width * pixelSize); unsafe { byte *ptr = (byte *)data.Scan0.ToPointer(); var index = 0; for (var y = 0; y < data.Height; y++) { for (var x = 0; x < data.Width; x++) { var b = pattern.GetPixel(x, y); if (b == 15) { *(ptr + index + 2) = 0; *(ptr + index + 1) = 0; *(ptr + index + 0) = 0; *(ptr + index + 3) = 0; } else { var c = pattern.Palette[b]; *(ptr + index + 2) = c.R; *(ptr + index + 1) = c.G; *(ptr + index + 0) = c.B; *(ptr + index + 3) = 255; } index += pixelSize; } index += padding; } } bitmap.UnlockBits(data); return(bitmap); }
public static UnityEngine.Color[] GetPixels(this DesignPattern pattern) { int width = pattern.Width; int height = pattern.Height; UnityEngine.Color[] pixels = new UnityEngine.Color[width * height]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int colorIndex = pattern.GetPixel(x, y); if (colorIndex < 0x0F) { var color = pattern.Palette[colorIndex]; pixels[x + y * width] = new UnityEngine.Color(((float)color.R) / 255f, ((float)color.G) / 255f, ((float)color.B) / 255f); } else { pixels[x + y * width] = new UnityEngine.Color(0f, 0f, 0f, 0f); } } } return(pixels); }