JImageModifier - Immagine.java
Cerca
 











Immagine.java

Caricato da: Paoloricciuti
Scarica il programma completo

  1. package jmodimage;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Image;
  7. import java.awt.Point;
  8. import java.awt.image.BufferedImage;
  9. import java.awt.image.RenderedImage;
  10. import java.io.File;
  11. import java.io.IOException;
  12. import javax.imageio.ImageIO;
  13.  
  14. public class Immagine {
  15.     private Image img;
  16.  
  17.     public Immagine(String pImg) throws IOException{
  18.         this(new File(pImg));
  19.     }
  20.  
  21.     public Immagine(File pImg) throws IOException{
  22.         this.img= this.caricaImmagine(pImg);
  23.     }
  24.  
  25.     public Image getImg() {
  26.         return img;
  27.     }
  28.  
  29.     public void salvaImmagine(File pDestinazione) throws IOException{
  30.         String path=pDestinazione.getName();
  31.         String est=path.substring(path.length()-3);
  32.         ImageIO.write((RenderedImage) this.img, est, pDestinazione);
  33.     }
  34.  
  35.     public void scriviImmagine(Point pXy, String pString, Color pColor){
  36.         Graphics g= this.img.getGraphics();
  37.         g.setFont(new Font(Font.MONOSPACED, Font.BOLD, 35));
  38.         g.setColor(pColor);
  39.         g.drawString(pString, pXy.x, pXy.y+35);
  40.     }
  41.  
  42.     private BufferedImage caricaImmagine(File pImg) throws IOException {
  43.         BufferedImage getImg=null;
  44.         getImg=ImageIO.read(pImg);
  45.         return getImg;
  46.     }
  47.  
  48. }
 

Creative Commons License
Il layout di questo sito è concesso sotto licenza Creative Commons.
Per maggiori informazioni sulle licenze dei contenuti del sito, clicca.