GDI + Generate admission ticket

Source: Internet
Author: User
Tags datetime draw box range tostring ticket

            Random Random = new Random ();
            Create canvas Bitmap bt = new Bitmap (353, 404, Pixelformat.format24bpprgb);
            Graphics g = Graphics.fromimage (BT);
            Define Text style font fn1 = new Font ("Tahoma", ten, FontStyle.Bold);
            FONT fn = new Font ("Tahoma", 9, FontStyle.Bold);
            Fill background color g.clear (color.lightblue);
            Fill in text g.drawstring ("Certification examination of Electronic Design Engineer of China Electronic Society", FN1, Brushes.black, New PointF (46, 20));
            g.DrawString ("Admission Ticket", FN1, Brushes.black, New PointF (140, 50));
            g.DrawString ("Admission ticket Number", FN, Brushes.black, new PointF (14, 85));
            g.DrawString ("EDP200903060001", FN, Brushes.black, New PointF (90, 85));
            g.DrawString ("Candidate name", FN, Brushes.black, new PointF (14, 115));
            g.DrawString ("Du Runrong", FN, Brushes.black, New PointF (90, 115));
            g.DrawString ("examinee sex", FN, Brushes.black, new PointF (14, 145)); g.DrawString ("Male", FN, Brushes.black,New PointF (90, 145));
            g.DrawString ("ID number", FN, Brushes.black, new PointF (14, 175));
            g.DrawString ("411024198806021230", FN, Brushes.black, New PointF (90, 175));
            g.DrawString ("Examination Level", FN, Brushes.black, new PointF (14, 205));
            g.DrawString ("Electronic design Assistant Engineer", FN, Brushes.black, New PointF (90, 205));
            g.DrawString ("Examination Subjects", FN, Brushes.black, new PointF (14, 235));
            g.DrawString ("Comprehensive knowledge", FN, Brushes.black, New PointF (90, 235));
            g.DrawString ("Actual operation", FN, Brushes.black, new PointF (220, 235));
            g.DrawString ("Exam Time", FN, Brushes.black, new PointF (14, 265));
            g.DrawString ("09-05-25 PM 8:00", FN, Brushes.black, New PointF (90, 265));
            g.DrawString ("09-05-25 PM 8:00", FN, Brushes.black, new PointF (220, 265));
            g.DrawString ("School name", FN, Brushes.black, new PointF (14, 295));
            g.DrawString ("Beijing University of Technology", FN, Brushes.black, New PointF (90, 295)); g.DrawString ("Beijing Normal University"),FN, Brushes.black, new PointF (220, 295));
            g.DrawString ("Examination room Number", FN, Brushes.black, new PointF (14, 323));
            g.DrawString ("First examination room", FN, Brushes.black, New PointF (90, 323));
            g.DrawString ("Nineth examination Room", FN, Brushes.black, new PointF (220, 323));
            g.DrawString ("Detailed Address", FN, Brushes.black, new PointF (14, 353));
            String Dizhi = "Beijing Industrial University address Beijing Industry";    int j = 335;    initial coordinate int j2 = 335;  The initial coordinates for (int z = 0; z < z + + 8)///cycle times {int k = z + 10; The first time is 0 o'clock if (k > Dizhi. Length)//k is greater than the total number of words {k = Dizhi.  Length-k;      If greater than for example k=45 dizhi.length=40 k=40-45 k=-5 int i = k + 10; i = -5+20 so as not to intercept beyond the range g.drawstring (Dizhi.
                    Substring (z, i), FN, Brushes.black, new PointF (18, J + +));
                Break } g.drawstring (Dizhi. Substring (z, 8), FN, Brushes.black, new PointF (n = + 18));
            String dizhi2 = "Beijing Normal University address Beijing Normal School";  for (int z2 = 0; Z2 < Z2 + + 8)//cycle times {int K2 = z2 + 10; The first time is 0 o'clock if (K2 > Dizhi2). Length)//k is greater than the total number of words {K2 = Dizhi2.  LENGTH-K2;      If greater than for example k=45 dizhi.length=40 k=40-45 k=-5 int i2 = k2 + 10; i = -5+20 so as not to intercept beyond the range g.drawstring (dizhi2.
                    Substring (Z2, I2), FN, Brushes.black, new PointF (J2 = 18));
                Break } g.drawstring (Dizhi2.
            Substring (Z2, 8), FN, Brushes.black, new PointF (J2 + + 18)); //generate pragma for (int i = 0; i < i++) {int x1 = random. Next (BT.
                WIDTH-20); int y1 = random. Next (BT.
                HEIGHT-20); Bt. SetPixel (x1, y1, Color.FromArgb (random).
            Next ()));
    }        Generates a random curve for (int i = 0; i < i++) {int x1 = random. Next (BT.
                WIDTH-20); int y1 = random. Next (BT.
                HEIGHT-20); int x2 = random.
                Next (1, 30); int y2 = random.
                Next (1, 20); int x3 = random.
                Next (15, 45); int y3 = random.
                Next (70, 270); G.drawarc (Random, New Pen (COLOR.FROMARGB).
            Next ())), x1, y1, x2, y2, X3, y3);      //Draw horizontal line G.drawline (new Pen (Color.Black), 10, 75, 341, 75);    1 G.drawline (New Pen (Color.Black), 10, 105, 243, 105);    2 G.drawline (New Pen (Color.Black), 10, 135, 243, 135);    3 G.drawline (New Pen (Color.Black), 10, 165, 243, 165);    4 G.drawline (New Pen (Color.Black), 10, 195, 341, 195);    5 G.drawline (New Pen (Color.Black), 10, 197, 341, 197);    5 G.drawline (New Pen (Color.Black), 10, 225, 341, 225);
        6    G.drawline (New Pen (Color.Black), 10, 255, 341, 255);    7 G.drawline (New Pen (Color.Black), 10, 285, 341, 285);    8 G.drawline (New Pen (Color.Black), 10, 315, 341, 315);    9 G.drawline (New Pen (Color.Black), 10, 345, 341, 345);      10//Draw vertical bar G.drawline (new Pen (Color.Black), 80, 75, 80, 392);      One g.drawline (new Pen (Color.Black), 82, 75, 82, 392);   G.drawline (New Pen (Color.Black), 210, 225, 210, 392);    G.drawline (New Pen (Color.Black), 243, 75, 243, 195);
            14//Draw box G.drawrectangle (new Pen (Color.Black), 10, 10, 331, 382);
            G.drawrectangle (New Pen (Color.Black), 7, 7, 338, 388); Fill image System.Drawing.Image NewImage = System.Drawing.Image.FromFile (Server.MapPath (@ "~\image\308329547.gif")
            ));
            Image positioning G.drawimage (newimage, 248, 80, 89, 111); Release image cache G.dispose ();
            Define Response.ContentType = "image/jpeg" to produce picture format; Bt.
            Save (Response.outputstream, imageformat.jpeg);
            Create a folder string Wenjanpath = Server.MapPath (@ "~\zkz_image"); if (!
            Directory.Exists (Wenjanpath)) {directory.createdirectory (Wenjanpath); }//Picture automatically save path BT.
            Save (Server.MapPath (@ "~\zkz_image\ Du Runrong's admission ticket" + DateTime.Now.ToString ("yyyy-mm-dd") + ". jpg"), imageformat.jpeg); Releases the bitmap cache BT.
            Dispose ();
            String lujing = Server.MapPath (@ "~\zkz_image\ Du Runrong's ticket" + DateTime.Now.ToString ("yyyy-mm-dd") + ". jpg");  Image1.imageurl = lujing;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.