public static Bitmap Draw(PixelMap pm) { int w = pm.PixelWidth * pm.Width; int h = pm.PixelWidth * pm.Height; if (pm.ShowGrid) { w += pm.GridWidth * (pm.Width + 1); h += pm.GridWidth * (pm.Height + 1); } Bitmap b = new Bitmap(w, h); using (Graphics g = Graphics.FromImage(b)) { g.Clear(pm.BackColor); for (int i = 0; i < pm.Width; ++i) { for (int j = 0; j < pm.Height; ++j) { DrawPixel(pm, g, i, j, pm.GetPixel(i, j)); } } if (pm.ShowGrid) { DrawGrid(pm, g); } } return b; }
private void ChangePixelPainterImage(Bitmap bmp) { int gw = RefreshCurrGridWidth(); CurrPixelMap = new PixelMap() { ShowGrid = ShowGridCheckBox.Checked, data = bmp, PixelWidth = PixelMap.DefaultPixelWidth - gw, GridWidth = gw, GridColor = GridColorButton.BackColor, }; PixelPainter.SourceImage = CurrPixelMap; }
public static void DrawGrid(PixelMap pm, Graphics g) { int x = pm.PixelWidth + pm.GridWidth; var w = pm.data.Width * x; var h = pm.data.Height * x; var GridPen = new Pen(pm.GridColor, pm.GridWidth); int BlockWidth = pm.PixelWidth + pm.GridWidth; for (int i = 0; i <= pm.data.Width; ++i) { g.DrawLine(GridPen, 0, i * BlockWidth, w, i * BlockWidth); g.DrawLine(GridPen, i * BlockWidth, 0, i * BlockWidth, h); } }
public static void DrawPixel(PixelMap pm, Graphics g, int x, int y, Color c) { var brush = new SolidBrush(c); if (pm.ShowGrid) { g.FillRectangle( brush, pm.GridWidth / 2.0f + x * (pm.PixelWidth + pm.GridWidth), pm.GridWidth / 2.0f + y * (pm.PixelWidth + pm.GridWidth), pm.PixelWidth, pm.PixelWidth); } else { g.FillRectangle( brush, x * pm.PixelWidth, y * pm.PixelWidth, pm.PixelWidth, pm.PixelWidth); } }
private void CloseFile() { CurrPixelMap = null; PixelPainter.SourceImage = null; IsModified = false; SetCurrPathStatusLabel("无"); }