fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Drawing.Text;
  7. using System.Drawing.Imaging;
  8. using System.Drawing.Drawing2D;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Windows.Forms;
  12. using System.IO;
  13.  
  14. namespace WindowsFormsApplication1
  15. {
  16. public partial class Form1 : Form
  17. {
  18. public Form1()
  19. {
  20. InitializeComponent();
  21. }
  22. FontFamily[] ffs;
  23. TextBox tb;
  24. PlayCard pc;
  25. //保存場所はデスクトップ
  26. string cardPass = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\card\\";
  27. private void Form1_Load(object sender, EventArgs e)
  28. {
  29. tb = new TextBox();
  30. tb.Multiline = true;
  31. tb.Dock = DockStyle.Fill;
  32. tb.ScrollBars = ScrollBars.Both;
  33. this.Controls.Add(tb);
  34. InstalledFontCollection ifc = new InstalledFontCollection();
  35. ffs = ifc.Families;
  36. if (!Directory.Exists(cardPass))
  37. Directory.CreateDirectory(cardPass);
  38. }
  39.  
  40. private void Form1_Shown(object sender, EventArgs e)
  41. {
  42. pc = new PlayCard();
  43. pc.ScaleX = 0.5f;
  44. pc.ScaleY = 0.5f;
  45. //pc.Outline = false;
  46. //Bitmap allbmp = new Bitmap(pc.Size.Width * 14, pc.Size.Height * 4, PixelFormat.Format32bppArgb);
  47. for (int k = 0; k < 4; k++)
  48. {
  49. for (int j = 0; j < 14; j++)
  50. {
  51. Bitmap bmp = pc.GetPlayCard(k, j);
  52. //using (Graphics g = Graphics.FromImage(allbmp))
  53. //{
  54. // g.DrawImage(bmp, new Point(j * pc.Size.Width, k * pc.Size.Height));
  55. //}
  56. string viewtext = cardPass + pc.CardInitial[k] + (j + 1).ToString("00") + ".png";
  57. bmp.Save(viewtext, ImageFormat.Png);
  58. tb.AppendText(viewtext + "\r\n");
  59. Application.DoEvents();
  60. }
  61. }
  62. //allbmp.Save(cardPass + "allcard.png", ImageFormat.Png);
  63. tb.AppendText("end");
  64. }
  65.  
  66. }
  67. class PlayCard : PlayCardMark
  68. {
  69. public Color BackgroundColor { get; set; }
  70. public Color FillColor { get; set; }
  71. public PixelFormat PixelFormat { get; set; }
  72. public bool Outline { get; set; }
  73. public int OutlineWidth { get; set; }
  74. public Color OutlineColor { get; set; }
  75. public string[] CardInitial = new string[]
  76. {
  77. "S","D","C","H"
  78. };
  79.  
  80. public PlayCard()
  81. {
  82. this.PixelFormat = PixelFormat.Format32bppArgb;
  83. this.Outline = true;
  84. this.OutlineWidth = 1;
  85. this.OutlineColor = Color.Black;
  86. this.FontName = "MS Pゴシック";
  87. this.FillColor = Color.White;
  88. }
  89. public Bitmap GetPlayCard(int Type, int CardNumber)
  90. {
  91. Bitmap bmp = new Bitmap((int)((float)this.Size.Width * this.ScaleX),
  92. (int)((float)(this.Size.Height * this.ScaleY)), this.PixelFormat);
  93. using (Graphics g = Graphics.FromImage(bmp))
  94. {
  95. g.SmoothingMode = SmoothingMode.HighQuality;
  96. //念のため透明色で塗る
  97. g.FillRectangle(new SolidBrush(BackgroundColor), 0, 0, bmp.Width, bmp.Height);
  98.  
  99. //カード作成
  100. ModelManager mm = new ModelManager();
  101. mm.AddRectangleArc(new RectangleF(0.0f, 0.0f, 199.0f, 299.0f), 10.0f);
  102. Matrix m = new Matrix();
  103. m.Scale(this.ScaleX, this.ScaleY);
  104. GraphicsPath gp = mm.GetModelPath(m);
  105. g.FillPath(new SolidBrush(this.FillColor), gp);
  106. //カードの輪郭
  107. if (this.Outline == true)
  108. g.DrawPath(new Pen(this.OutlineColor, this.OutlineWidth), gp);
  109. //カードの中味
  110. gp = this.GetMarkPath(Type, CardNumber);
  111. g.FillPath(this.MarkColor[Type], gp);
  112. }
  113. return bmp;
  114. }
  115. }
  116. public class PlayCardMark
  117. {
  118.  
  119. const int hosei_x = -11;
  120. const int hosei_y = -11;
  121. public string FontName { get; set; }
  122. public float ScaleX { get; set; }
  123. public float ScaleY { get; set; }
  124. public Size Size { get; set; }
  125. public Brush[] MarkColor = new Brush[]
  126. {
  127. Brushes.Black,
  128. Brushes.Crimson,
  129. Brushes.Black,
  130. Brushes.Crimson,
  131. };
  132. public string[] Mark = new string[]
  133. {
  134. "♠","♦","♣","♥"
  135. };
  136. public Point[] Point = new Point[]
  137. {
  138. new Point(hosei_x + 25,hosei_y + 25),
  139. new Point(hosei_x + 25,hosei_y + 87),
  140. new Point(hosei_x + 25,hosei_y + 125),
  141.  
  142. new Point(hosei_x + 125,hosei_y + 25),
  143. new Point(hosei_x + 125,hosei_y + 87),
  144. new Point(hosei_x + 125,hosei_y + 125),//5
  145.  
  146. new Point(hosei_x + 75,hosei_y + 75),
  147. new Point(hosei_x + 75,hosei_y + 125),
  148. new Point(hosei_x + 75,hosei_y + 25),
  149. new Point(hosei_x + 75,hosei_y + 67),
  150.  
  151. };
  152. public Size MarkSize;
  153. string[] cardnumber = new string[]
  154. {
  155. "A","2","3","4","5","6","7","8","9","10","J","Q","K","JOKER"
  156. };
  157. int[] cardnumberw = new int[]
  158. {
  159. 1,1,1,1,1,
  160. 1,1,1,1,-5,
  161. 1,1,1,1
  162. };
  163. public PlayCardMark()
  164. {
  165. this.Size = new Size(200, 300);
  166. }
  167. private void GetLeftUpMark(GraphicsPath gp, int Type, int CardNumber)
  168. {
  169. //カード左上のマークと数字を描画
  170. //右下は回転+平行移動で対応
  171. gp.AddString(this.cardnumber[CardNumber], new FontFamily(this.FontName),
  172. 0, 30, new Point(this.cardnumberw[CardNumber], 0), StringFormat.GenericDefault);
  173. if (CardNumber < 13) gp.AddString(this.Mark[Type], new FontFamily(this.FontName),
  174. 0, 30, new Point(2, 30), StringFormat.GenericDefault);
  175. Matrix m = new Matrix();
  176. m.Scale(0.8f, 1.0f);
  177. gp.Transform(m);
  178. }
  179. private void GetUpperMark(GraphicsPath gp, int Type, int CardNumber)
  180. {
  181. //A~10までの中のマークを描画
  182. //上半分共通部分だけ処理
  183. //下半分は上を回転+平行移動で対応
  184. switch ((CardNumber + 1))
  185. {
  186. case 2:
  187. case 3:
  188. gp.AddString(this.Mark[Type], new FontFamily(this.FontName),
  189. 0, 70, this.Point[8], StringFormat.GenericDefault);
  190. break;
  191. case 4:
  192. case 5:
  193. case 6:
  194. case 7:
  195. case 8:
  196. gp.AddString(this.Mark[Type], new FontFamily(this.FontName),
  197. 0, 70, Point[0], StringFormat.GenericDefault);
  198. gp.AddString(this.Mark[Type], new FontFamily(this.FontName),
  199. 0, 70, Point[3], StringFormat.GenericDefault);
  200. if ((CardNumber + 1) == 8)
  201. {
  202. gp.AddString(this.Mark[Type], new FontFamily(this.FontName),
  203. 0, 70, Point[6], StringFormat.GenericDefault);
  204. }
  205. break;
  206. case 9:
  207. case 10:
  208. gp.AddString(this.Mark[Type], new FontFamily(this.FontName),
  209. 0, 70, Point[0], StringFormat.GenericDefault);
  210. gp.AddString(this.Mark[Type], new FontFamily(this.FontName),
  211. 0, 70, Point[1], StringFormat.GenericDefault);
  212. gp.AddString(this.Mark[Type], new FontFamily(this.FontName),
  213. 0, 70, Point[3], StringFormat.GenericDefault);
  214. gp.AddString(this.Mark[Type], new FontFamily(this.FontName),
  215. 0, 70, Point[4], StringFormat.GenericDefault);
  216. if ((CardNumber + 1) == 10)
  217. {
  218. gp.AddString(this.Mark[Type], new FontFamily(this.FontName),
  219. 0, 70, Point[9], StringFormat.GenericDefault);
  220. }
  221. break;
  222. default:
  223. break;
  224. };
  225. }
  226. public GraphicsPath GetMarkPath(int Type, int CardNumber)
  227. {
  228. ModelManager mm = new ModelManager();
  229. //回転で対応可能なマークの処理
  230. //上半分
  231. GraphicsPath gp1 = new GraphicsPath();
  232. this.GetLeftUpMark(gp1, Type, CardNumber);
  233. this.GetUpperMark(gp1, Type, CardNumber);
  234. mm.AddPath(gp1);
  235. //下半分
  236. GraphicsPath gp2 = new GraphicsPath();
  237. this.GetLeftUpMark(gp2, Type, CardNumber);
  238. this.GetUpperMark(gp2, Type, CardNumber);
  239. Matrix m = new Matrix();
  240. m.Rotate(180f);
  241. gp2.Transform(m);
  242. m.Reset();
  243. m.Translate((float)(this.Size.Width - 1), (float)(this.Size.Height - 1));
  244. gp2.Transform(m);
  245. mm.AddPath(gp2);
  246. //回転で対応できないマークの処理
  247. switch ((CardNumber + 1))
  248. {
  249. case 1:
  250. case 3:
  251. case 5:
  252. case 9:
  253. mm.AddString(this.Mark[Type], this.FontName,
  254. 0, 70, Point[7], StringFormat.GenericDefault);
  255. break;
  256. case 6:
  257. case 7:
  258. case 8:
  259. mm.AddString(this.Mark[Type], this.FontName,
  260. 0, 70, Point[2], StringFormat.GenericDefault);
  261. mm.AddString(this.Mark[Type], this.FontName,
  262. 0, 70, Point[5], StringFormat.GenericDefault);
  263. if ((CardNumber + 1) == 7)
  264. {
  265. mm.AddString(this.Mark[Type], this.FontName,
  266. 0, 70, Point[6], StringFormat.GenericDefault);
  267. }
  268. break;
  269. default:
  270. break;
  271. };
  272. m.Reset();
  273. m.Scale(this.ScaleX, this.ScaleY);
  274. return mm.GetModelPath(m);
  275. }
  276. }
  277. public class ModelManager
  278. {
  279. public Matrix Matrix { get; set; }
  280. public List<VectorModel> Model { get; set; }
  281. public ModelManager()
  282. {
  283. this.Model = new List<VectorModel>();
  284. this.Matrix = new Matrix();
  285. }
  286. public void AddVectorModel(VectorModel vm)
  287. {
  288. this.Model.Add(vm);
  289. }
  290. public void AddLine(int StartX, int StartY, int EndX, int EndY)
  291. {
  292. this.AddLine(new Point(StartX, StartY), new Point(EndX, EndY));
  293. }
  294. public void AddLine(Point[] Point)
  295. {
  296. VectorModel vm = new VectorModel();
  297. vm.Type = 0;
  298. vm.Point = Point;
  299. this.AddVectorModel(vm);
  300. }
  301. public void AddLine(Point Start, Point End)
  302. {
  303. Point[] Point = new Point[2];
  304. Point[0] = Start;
  305. Point[1] = End;
  306. this.AddLine(Point);
  307. }
  308. public void AddLines(Point[] Point)
  309. {
  310. VectorModel vm = new VectorModel();
  311. vm.Type = 1;
  312. vm.Point = Point;
  313. this.AddVectorModel(vm);
  314. }
  315. public void AddArc(RectangleF RectangleF, float StartAngle, float SweepAngle)
  316. {
  317. VectorModel vm = new VectorModel();
  318. vm.Type = 2;
  319. vm.RectangleF = RectangleF;
  320. vm.StartAngle = StartAngle;
  321. vm.SweepAngle = SweepAngle;
  322. this.AddVectorModel(vm);
  323.  
  324. }
  325. public void AddArc(int StartX, int StartY, int Width, int Height, int StartAngle, int SweepAngle)
  326. {
  327. this.AddArc(new RectangleF((float)StartX, (float)StartY, (float)Width, (float)Height),
  328. (float)StartAngle, (float)SweepAngle);
  329. }
  330. public void AddArc(float StartX, float StartY, float Width, float Height, float StartAngle, float SweepAngle)
  331. {
  332. this.AddArc(new RectangleF(StartX, StartY, Width, Height),
  333. StartAngle, SweepAngle);
  334. }
  335. public void AddString(String Text, string FontName, int FontStyle, float FontemSize, Point Point, StringFormat StringFormat)
  336. {
  337. VectorModel vm = new VectorModel();
  338. vm.Type = 3;
  339. vm.Text = Text;
  340. vm.FontName = FontName;
  341. vm.FontStyle = FontStyle;
  342. vm.FontemSize = FontemSize;
  343. vm.Point = new Point[] { Point };
  344. vm.StringFormat = StringFormat;
  345. this.AddVectorModel(vm);
  346. }
  347. public void AddRectangle(RectangleF RectangleF)
  348. {
  349. VectorModel vm = new VectorModel();
  350. vm.Type = 4;
  351. vm.RectangleF = RectangleF;
  352. this.AddVectorModel(vm);
  353. }
  354. public void AddRectangle(int StartX, int StartY, int Width, int Height)
  355. {
  356. this.AddRectangle(new RectangleF((float)StartX, (float)StartY, (float)Width, (float)Height));
  357. }
  358. public void AddRectangle(float StartX, float StartY, float Width, float Height)
  359. {
  360. this.AddRectangle(new RectangleF(StartX, StartY, Width, Height));
  361. }
  362. public void AddRectangleArc(RectangleF RectangleF, float Radius)
  363. {
  364. VectorModel vm = new VectorModel();
  365. if (Radius < 1.0f)
  366. {
  367. //半径が1以下の場合は丸み無しに切り替え
  368. this.AddRectangle(RectangleF);
  369. }
  370. else
  371. {
  372. vm.Type = 5;
  373. vm.RectangleF = RectangleF;
  374. vm.Radius = Radius;
  375. this.AddVectorModel(vm);
  376. }
  377. }
  378. public void AddRectangleArc(int StartX, int StartY, int Width, int Height, int Radius)
  379. {
  380. this.AddRectangleArc(new RectangleF((float)StartX, (float)StartY, (float)Width, (float)Height), (float)Radius);
  381. }
  382. public void AddRectangleArc(float StartX, float StartY, float Width, float Height, float Radius)
  383. {
  384. this.AddRectangleArc(new RectangleF(StartX, StartY, Width, Height), Radius);
  385. }
  386. public void AddPath(GraphicsPath Path)
  387. {
  388. //if (Path.PointCount == 0) return;
  389. VectorModel vm = new VectorModel();
  390. vm.Type = 6;
  391. vm.Path = Path;
  392. this.AddVectorModel(vm);
  393. }
  394. public void Clear()
  395. {
  396. this.Model.Clear();
  397. }
  398. public GraphicsPath GetModelPath(Matrix m)
  399. {
  400. GraphicsPath gp = new GraphicsPath();
  401. foreach (VectorModel vm in this.Model)
  402. {
  403. vm.GetPath(gp);
  404. }
  405. gp.Transform(m);
  406. return gp;
  407. }
  408. public GraphicsPath GetModelPath()
  409. {
  410. //GraphicsPath gp = this.GetModelPath(this.Matrix);
  411. //return gp;
  412. return this.GetModelPath(this.Matrix);
  413. }
  414. }
  415. public class VectorModel
  416. {
  417. const float SwAngle = 90.0f;
  418. const float S000Angel = 0.0f;
  419. const float S090Angel = 90.0f;
  420. const float S180Angel = 180.0f;
  421. const float S270Angel = 270.0f;
  422. //public VectorModel Parent { get; set; }
  423. //public VectorModel Child { get; set; }
  424. //public VectorModel Next { get; set; }
  425. public int Type { get; set; }
  426. public Point[] Point { get; set; }
  427. public RectangleF RectangleF { get; set; }
  428. public float StartAngle { get; set; }
  429. public float SweepAngle { get; set; }
  430. public string Text { get; set; }
  431. public string FontName { get; set; }
  432. public int FontStyle { get; set; }
  433. public float FontemSize { get; set; }
  434. public StringFormat StringFormat { get; set; }
  435. public GraphicsPath Path { get; set; }
  436. public float Radius { get; set; }
  437. public float[] StAngel = new float[]
  438. {
  439. S180Angel,
  440. S270Angel,
  441. S000Angel,
  442. S090Angel,
  443. };
  444. public void GetPath(GraphicsPath gp)
  445. {
  446. //if (this.Child != null) Child.GetPath(gp);
  447. switch (this.Type)
  448. {
  449. case 0:
  450. gp.AddLine(this.Point[0], this.Point[1]);
  451. break;
  452. case 1:
  453. gp.AddLines(this.Point);
  454. break;
  455. case 2:
  456. gp.AddArc(this.RectangleF, this.StartAngle, this.SweepAngle);
  457. break;
  458. case 3:
  459. gp.AddString(this.Text, new FontFamily(this.FontName),
  460. this.FontStyle, this.FontemSize, Point[0], this.StringFormat);
  461. break;
  462. case 4:
  463. gp.AddRectangle(this.RectangleF);
  464. break;
  465. case 5:
  466. int xs = (int)this.RectangleF.Location.X;
  467. int ys = (int)this.RectangleF.Location.Y;
  468. int xe = (int)this.RectangleF.Width;
  469. int ye = (int)this.RectangleF.Height;
  470. int rad = (int)(this.Radius);
  471. int diameter = rad * 2;
  472. Point[] sp = new Point[]{
  473. new Point(xs + rad, ys),
  474. new Point(xe, ys + rad),
  475. new Point(xe - rad, ye),
  476. new Point(xs, ye - rad),
  477. };
  478. Point[] ep = new Point[]{
  479. new Point(xe - rad, ys),
  480. new Point(xe, ye - rad),
  481. new Point(xs + rad, ye),
  482. new Point(xs, ys + rad),
  483. };
  484. Rectangle[] r = new Rectangle[]{
  485. new Rectangle(xs, ys, diameter, diameter),
  486. new Rectangle(xe - diameter, ys, diameter, diameter),
  487. new Rectangle(xe - diameter, ye - diameter, diameter, diameter),
  488. new Rectangle(xs, ye - diameter, diameter, diameter),
  489. };
  490. for (int i = 0; i < 4; i++)
  491. {
  492. gp.AddArc(r[i], this.StAngel[i], SwAngle);
  493. gp.AddLine(sp[i], ep[i]);
  494. }
  495. break;
  496. case 6:
  497. gp.AddPath(this.Path, false);
  498. break;
  499. default:
  500. break;
  501. }
  502. //if (this.Next != null) Next.GetPath(gp);
  503. return;
  504. }
  505. }
  506. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty