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