I used Asp.net GDI + to draw an image. It produced JPG format, but the definition was not high enough. However, if it is changed to PNG, the system. Drawing. imaging. imagecodecinfo ICI = getencoderinfo ("image/JPEG") error is returned ");
I found a bunch of materials and finally found them. below is the code!
Code
1 using system;
2 using system. Data;
3 using system. configuration;
4 using system. collections;
5 using system. Web;
6 using system. Web. Security;
7 using system. Web. UI;
8 using system. Web. UI. webcontrols;
9 using system. Web. UI. webcontrols. webparts;
10 using system. Web. UI. htmlcontrols;
11 using system. drawing;
12 using system. Drawing. drawing2d;
13 using system. Drawing. imaging;
14
15 public partial class createimg: system. Web. UI. Page
16 {
17 protected void page_load (Object sender, eventargs E)
18 {
19
20
21
22
23}
24 Private Static imagecodecinfo getencoderinfo (string mimetype)
25 {
26 imagecodecinfo [] encoders;
27 encoders = imagecodecinfo. getimageencoders ();
28 For (Int J = 0; j <encoders. length; ++ J)
29 {
30 if (encoders [J]. mimetype = mimetype)
31 return encoders [J];
32}
33 return NULL;
34}
35 private bitmap getneralcodeimage ()
36 {
37
38 // create a bitmap
39
40 bitmap BMP = new Bitmap (150, 18 );
41
42 graphics G = graphics. fromimage (BMP );
43G. Clear (color. fromargb (247,213,225 ));
44 // depict characters
45g. drawstring ("1366666666", new font ("verdana", 11, fontstyle. Bold ),
46 new solidbrush (color. fromargb (255,102, 0 )),
47 0,
48 0
49 );
50g. compositingquality = compositingquality. highquality;
51g. smoothingmode = smoothingmode. highquality;
52g. interpolationmode = interpolationmode. highqualitybicubic;
53G. pixeloffsetmode = pixeloffsetmode. highquality;
54g. Dispose ();
55 return BMP;
56}
57
58 protected void btnpng_click (Object sender, eventargs E)
59 {
60 // generate a PNG Image (high definition)
61 system. Io. memorystream MS = new system. Io. memorystream ();
62 getneralcodeimage (). Save (MS, imageformat. PNG );
63 MS. writeto (response. outputstream );
64}
65 protected void btn1__click (Object sender, eventargs E)
66 {
67 // generate jpg image (not clear enough)
68 system. Drawing. imaging. encoderparameters Ep = new system. Drawing. imaging. encoderparameters (1 );
69 ep. Param [0] = new system. Drawing. imaging. encoderparameter (system. Drawing. imaging. encoder. Quality, 95l );
70 system. Drawing. imaging. imagecodecinfo ICI = getencoderinfo ("image/JPEG"); // The text is displayed after being replaced with GIF, but the background is unclear.
71 This. getneralcodeimage (). Save (response. outputstream, ici, EP );
72}
73}
74