membuat text dalam gambar dengan Java BufferedImage class


Kali ini kita mencoba mengaplikasikan image processing menggunakan java. kali ini class yang akan kita coba adalah Java BufferedImage class. berikut contoh code nya


mport java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class loadimage2 extends JPanel {

   public void paint(Graphics g) {
      Image img = createImageWithText();
      g.drawImage(img, 40,40,this);
   }

   private Image createImageWithText(){
      BufferedImage bufferedImage = new BufferedImage(200,200,BufferedImage.TYPE_INT_RGB);
      Graphics g = bufferedImage.getGraphics();

      g.drawString("aaaa", 20,20);
      g.drawString("bbbb", 20,40);
      g.drawString("cccc", 20,60);
      g.drawString("dddd", 20,80);
      g.drawString("eeee", 40,100);
      
      return bufferedImage;
   }
   
   public static void main(String[] args) {
      JFrame frame = new JFrame();
      frame.getContentPane().add(new loadimage2());

      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setSize(400, 400);
      frame.setVisible(true);
   }
}

  

maka yang akan dihasilkan sebagai berikut

Screenshot from 2015-07-06 19:45:22

Advertisements

Author: ridhobustami

orang ngak jelas

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s