Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace BitShiftCardCreator
- {
- public partial class frmMain : Form
- {
- static Image baseImage { get { return Image.FromFile(@"C:\Users\Alex\Desktop\Board and Card Games\Bit Shift\Cards\PNG Files\BitShiftCardTemplate.png"); } }
- public frmMain()
- {
- InitializeComponent();
- var previewImage = DrawImage(baseImage, "01010101");
- pbxPreview.Image = previewImage;
- pbxPreview.Height = previewImage.Height;
- pbxPreview.Width = previewImage.Width;
- imgInfo.Text = string.Format("Height: {0}, Width: {1}, PhysicalDimHeight: {2}, PhysicalDimWidth: {3}",
- baseImage.Height, baseImage.Width, baseImage.PhysicalDimension.Height, baseImage.PhysicalDimension.Width);
- }
- private void btnCreate_Click(object sender, EventArgs e)
- {
- //Loop through the numbers and create the images, and then save them
- var savedImagesDirectory = @"C:\Users\Alex\Desktop\Board and Card Games\Bit Shift\Cards\PNG Files\";
- //CREATE THE IMAGES DAWG!
- for (short i = 0; i < 256; i++)
- {
- var numAsBinaryString = GetShortBinaryString(i);
- if (numAsBinaryString.Where(c => c == '0').Count() == 4)
- {
- var newImage = DrawImage(baseImage, numAsBinaryString);
- newImage.Save(savedImagesDirectory + "Bit_Shift_" + i.ToString().PadLeft(3, '0') + ".png", System.Drawing.Imaging.ImageFormat.Png);
- }
- }
- }
- static Image DrawImage(Image baseImage, string textline1)
- {
- var newImage = new Bitmap(baseImage);
- var graphics = Graphics.FromImage(newImage);
- var line1start = new PointF(100.0f, 162.0f);
- var line2start = new PointF(100.0f, 798.0f);
- var cardFont = new Font("Quartz MS", 114.0f, FontStyle.Regular, GraphicsUnit.Pixel);
- var whiteBrush = Brushes.White;
- graphics.DrawString(textline1, cardFont, whiteBrush, line1start);
- graphics.DrawString(textline1, cardFont, whiteBrush, line2start);
- return newImage;
- }
- static string GetShortBinaryString(short n)
- {
- char[] b = new char[8];
- int pos = 7;
- int i = 0;
- while (i < 8)
- {
- if ((n & (1 << i)) != 0)
- {
- b[pos] = '1';
- }
- else
- {
- b[pos] = '0';
- }
- pos--;
- i++;
- }
- return new string(b);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement