Dynamically generating GIF or JPG samples on the server side

Source: Internet
Author: User
Dynamic | server | example package web.images;





/**


* Insert type description here.


* Date Created: (2002-6-6-9:59:00)


* @author: Administrator


*/


import java.io.*;





import java.util.*;





import com.sun.image.codec.jpeg.*;





import java.awt.image.*;





import java.awt.*;








public class Chartgraphics {





bufferedimage image;





public void CreateImage (String filelocation) {





try {





FileOutputStream fos = new FileOutputStream (filelocation);





bufferedoutputstream bos = new Bufferedoutputstream (FOS);





JPEGImageEncoder encoder = jpegcodec.createjpegencoder (BOS);





Encoder.encode (image);





Bos.close ();





catch (Exception e) {





System.out.println (e);





}





}








public void graphicsgeneration (int h1,int h2,int h3,int h4,int h5) {








final int x=10;





int imagewidth = 800;//the width of the picture





int imageheight =900;//picture height





int columnwidth=70;//column width




Maximum height of
int columnheight=800;//column








chartgraphics chartgraphics = new Chartgraphics ();





chartgraphics.image = new BufferedImage (ImageWidth, ImageHeight, Bufferedimage.type_int_rgb);





Graphics Graphics = ChartGraphics.image.getGraphics ();





Graphics.setcolor (Color.White);





Graphics.fillrect (0,0,imagewidth,imageheight);





Graphics.setcolor (Color.Black);


Graphics.setxormode (Color.Blue);


Graphics.drawline (columnwidth+x,columnheight-h5-50,columnwidth+x,columnheight);//y Axis





Graphics.drawline (columnwidth+x,columnheight-h5-50,columnwidth+x-10,columnheight-h5-40);//y Axis Arrow left





Graphics.drawline (columnwidth+x,columnheight-h5-50,columnwidth+x+10,columnheight-h5-40);//y Axis Arrow Right





Graphics.drawline (750,columnheight,columnwidth+x,columnheight);//x Axis





Graphics.drawline (750,columnheight,740,columnheight-10);//x Axis





Graphics.drawline (750,columnheight,740,columnheight+10);//x Axis





Graphics.setcolor (Color.yellow);





Graphics.fillrect (x+1*columnwidth+10, COLUMNHEIGHT-H1, ColumnWidth, H1);





Graphics.fillrect (x+2*columnwidth+20, COLUMNHEIGHT-H2, ColumnWidth, H2);





Graphics.fillrect (x+3*columnwidth+30, Columnheight-h3, ColumnWidth, H3);





Graphics.fillrect (x+4*columnwidth+40, Columnheight-h4, ColumnWidth, H4);





Graphics.fillrect (x+5*columnwidth+50, Columnheight-h5, ColumnWidth, h5);





//graphics.drawstring ()





chartgraphics.createimage ("d:\\leaderquery\\leaderqueryweb\\web800\\images\\chart.jpg");





}





}














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.