Advertisement
Guest User

Bit Shift Designer Source

a guest
Feb 26th, 2013
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace BitShiftCardCreator
  11. {
  12.     public partial class frmMain : Form
  13.     {
  14.         static Image baseImage { get { return Image.FromFile(@"C:\Users\Alex\Desktop\Board and Card Games\Bit Shift\Cards\PNG Files\BitShiftCardTemplate.png"); } }
  15.         public frmMain()
  16.         {
  17.             InitializeComponent();
  18.             var previewImage = DrawImage(baseImage, "01010101");
  19.             pbxPreview.Image = previewImage;
  20.             pbxPreview.Height = previewImage.Height;
  21.             pbxPreview.Width = previewImage.Width;
  22.             imgInfo.Text = string.Format("Height: {0}, Width: {1}, PhysicalDimHeight: {2}, PhysicalDimWidth: {3}",
  23.                 baseImage.Height, baseImage.Width, baseImage.PhysicalDimension.Height, baseImage.PhysicalDimension.Width);
  24.         }
  25.  
  26.         private void btnCreate_Click(object sender, EventArgs e)
  27.         {
  28.             //Loop through the numbers and create the images, and then save them
  29.             var savedImagesDirectory = @"C:\Users\Alex\Desktop\Board and Card Games\Bit Shift\Cards\PNG Files\";
  30.  
  31.             //CREATE THE IMAGES DAWG!
  32.             for (short i = 0; i < 256; i++)
  33.             {
  34.                 var numAsBinaryString = GetShortBinaryString(i);
  35.                 if (numAsBinaryString.Where(c => c == '0').Count() == 4)
  36.                 {
  37.                     var newImage = DrawImage(baseImage, numAsBinaryString);
  38.                     newImage.Save(savedImagesDirectory + "Bit_Shift_" + i.ToString().PadLeft(3, '0') + ".png", System.Drawing.Imaging.ImageFormat.Png);
  39.                 }                
  40.             }
  41.         }
  42.         static Image DrawImage(Image baseImage, string textline1)
  43.         {
  44.             var newImage = new Bitmap(baseImage);
  45.             var graphics = Graphics.FromImage(newImage);
  46.             var line1start = new PointF(100.0f, 162.0f);
  47.             var line2start = new PointF(100.0f, 798.0f);
  48.             var cardFont = new Font("Quartz MS", 114.0f, FontStyle.Regular, GraphicsUnit.Pixel);            
  49.             var whiteBrush = Brushes.White;
  50.  
  51.             graphics.DrawString(textline1, cardFont, whiteBrush, line1start);
  52.             graphics.DrawString(textline1, cardFont, whiteBrush, line2start);
  53.  
  54.             return newImage;
  55.         }
  56.         static string GetShortBinaryString(short n)
  57.         {
  58.             char[] b = new char[8];
  59.             int pos = 7;
  60.             int i = 0;
  61.  
  62.             while (i < 8)
  63.             {
  64.                 if ((n & (1 << i)) != 0)
  65.                 {
  66.                     b[pos] = '1';
  67.                 }
  68.                 else
  69.                 {
  70.                     b[pos] = '0';
  71.                 }
  72.                 pos--;
  73.                 i++;
  74.             }
  75.             return new string(b);
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement