自己绘制JPEG图片

String sFileName = "name.jpg";
  try
  {
   FileOutputStream fos = new FileOutputStream(sFileName);
   BufferedImage myImage = new BufferedImage(225, 225,
                                           BufferedImage.TYPE_INT_RGB);


   Graphics g = myImage.getGraphics();
   g.setColor(Color.white);


   g.fillRect(0, 0, 225, 225);
   g.setColor(Color.black);
   g.drawString("Finance Balance Summary", 40, 15);
   g.drawString("Primary", 90, 30);
   g.setColor(Color.darkGray);
   g.fillRect(15, 193, 7, 7);
   g.setColor(Color.black);
   g.drawString("% Operating", 25, 200);
   g.setColor(Color.yellow);
   g.fillRect(130, 193, 7, 7);
   g.setColor(Color.black);
   g.drawString("% Term", 140, 200);
   g.setColor(Color.lightGray);
   g.fillRect(15, 213, 7, 7);
   g.setColor(Color.black);
   g.drawString("% Mortgage", 25, 220);
   g.setColor(Color.green);
   g.fillRect(130, 213, 7, 7);
   g.setColor(Color.black);
   g.drawString("% Lease", 140, 220);


   JPEGImageEncoder jpg = JPEGCodec.createJPEGEncoder(fos);
   jpg.encode(myImage);


  }
  catch (IOException e)
  {
   e.printStackTrace();
  }

你可能感兴趣的:(jpeg jpg)