Class JFImage

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Icon

public class JFImage extends JComponent implements Icon
Encapsules BufferedImage to provide more functions. Implements javax.swing.Icon so it can also be used with JLabel.
Author:
Peter Quiring
See Also:
  • Field Details

  • Constructor Details

    • JFImage

      public JFImage()
    • JFImage

      public JFImage(boolean alpha)
    • JFImage

      public JFImage(int x, int y)
    • JFImage

      public JFImage(int x, int y, boolean alpha)
  • Method Details

    • setImageSize

      public void setImageSize(int x, int y)
    • setBounds

      public void setBounds(int x, int y, int w, int h)
      Overrides:
      setBounds in class Component
    • setSize

      public void setSize(int x, int y)
      Overrides:
      setSize in class Component
    • setSize

      public void setSize(Dimension d)
      Overrides:
      setSize in class Component
    • setResizeOperation

      public void setResizeOperation(JFImage.ResizeOperation ro)
      Controls how this image is resized by layout managers.
    • getImage

      public Image getImage()
    • getBufferedImage

      public BufferedImage getBufferedImage()
    • setBufferedImage

      public void setBufferedImage(BufferedImage bi)
      Replaced BufferedImage. If image is not TYPE_INT_ARGB or TYPE_INT_RGB then the pixels are just copied.
      Parameters:
      bi - - new BufferedImage
    • getGraphics

      public Graphics getGraphics()
      Overrides:
      getGraphics in class JComponent
    • getGraphics2D

      public Graphics2D getGraphics2D()
    • paint

      public void paint(Graphics g)
      Paint this image onto Graphics.
      Overrides:
      paint in class JComponent
    • getWidth

      public int getWidth()
      Overrides:
      getWidth in class JComponent
    • getHeight

      public int getHeight()
      Overrides:
      getHeight in class JComponent
    • load

      public boolean load(InputStream in)
    • save

      public boolean save(OutputStream out, String fmt)
    • load

      public boolean load(String filename)
    • save

      public boolean save(String filename, String fmt)
    • loadmulti

      public static JFImage[] loadmulti(InputStream is)
    • savemulti

      public static boolean savemulti(OutputStream os, JFImage[] imgs, String format)
    • loadJPG

      public boolean loadJPG(InputStream in)
    • saveJPG

      public boolean saveJPG(OutputStream out)
    • loadJPG

      public boolean loadJPG(String filename)
    • saveJPG

      public boolean saveJPG(String filename)
    • loadPNG

      public boolean loadPNG(InputStream in)
    • savePNG

      public boolean savePNG(OutputStream out)
    • loadPNG

      public boolean loadPNG(String filename)
    • savePNG

      public boolean savePNG(String filename)
    • loadBMP

      public boolean loadBMP(String filename, int index)
    • saveBMP

      public boolean saveBMP(String filename)
    • loadBMP

      public boolean loadBMP(InputStream in, int index)
    • saveBMP

      public boolean saveBMP(OutputStream out)
    • saveICO

      public boolean saveICO(String filename)
    • saveICO

      public boolean saveICO(OutputStream out)
    • saveICNS

      public boolean saveICNS(String filename)
      save icns (Mac icon)
    • saveICNS

      public boolean saveICNS(OutputStream out)
      save icns (Mac icon)
    • loadSVG

      public boolean loadSVG(String filename, int width, int height)
    • saveSVG

      public boolean saveSVG(String filename)
    • loadSVG

      public boolean loadSVG(InputStream in, int width, int height)
    • saveSVG

      public boolean saveSVG(OutputStream out)
    • loadXPM

      public boolean loadXPM(String filename)
    • loadXPM

      public boolean loadXPM(InputStream in)
    • loadTIFF

      public boolean loadTIFF(InputStream in)
    • saveTIFF

      public boolean saveTIFF(OutputStream out)
    • loadTIFF

      public boolean loadTIFF(String filename)
    • saveTIFF

      public boolean saveTIFF(String filename)
    • loadTIFFs

      public static JFImage[] loadTIFFs(InputStream in)
    • saveTIFFs

      public static boolean saveTIFFs(OutputStream out, JFImage[] imgs)
    • putJFImage

      public void putJFImage(JFImage img, int x, int y)
      Puts pixels .
    • putJFImageKeyClr

      public void putJFImageKeyClr(JFImage img, int x, int y, int keyClr)
      Puts pixels unless src pixel == keyclr
    • putJFImageBlend

      public void putJFImageBlend(JFImage img, int x, int y, boolean keepAlpha)
      Puts pixels blending using img alpha (dest alpha is ignored)
    • putJFImageScale

      public void putJFImageScale(JFImage img, int x, int y, int width, int height)
      Puts pixels scaling image to fit
    • getJFImage

      public JFImage getJFImage(int x, int y, int w, int h)
      Returns an area of this image as a new JFImage.
    • putPixel

      public void putPixel(int x, int y, int r, int g, int b)
      Draws one pixel using r,g,b values (alpha assumed opaque)
    • putPixel

      public void putPixel(int x, int y, int c)
      Draws one pixel using rgb value (alpha assumed opaque)
    • getPixel

      public int getPixel(int x, int y)
      Returns rgb value of pixel at x,y
    • getAlpha

      public int getAlpha(int x, int y)
      Returns alpha value of pixel at x,y
    • putAlpha

      public void putAlpha(int x, int y, int lvl)
      Sets alpha value at x,y
    • putPixels

      public void putPixels(int[] src, int x, int y, int w, int h, int srcOffset)
      Puts pixels
    • putPixels

      public void putPixels(int[] src, int x, int y, int w, int h, int srcOffset, int srcScanSize)
      Puts pixels (supports padding at end of each scan line)
    • putPixelsKeyClr

      public void putPixelsKeyClr(int[] px, int x, int y, int w, int h, int offset, int keyclr)
      Put Pixels unless src pixel == keyclr
    • putPixelsBlend

      public void putPixelsBlend(int[] px, int x, int y, int w, int h, int srcOffset, int srcScansize, boolean keepAlpha)
      Puts pixels blending using src alpha (dest alpha is ignored). if keepAlpha is true then dest alpha is preserved. if keepAlpha is false then src alpha is copied to dest.
    • putPixelsBlendKeyClr

      public void putPixelsBlendKeyClr(int[] px, int x, int y, int w, int h, int srcOffset, int srcScansize, boolean keepAlpha, int keyclr)
      Puts pixels blending using src alpha (dest alpha is ignored) unless src pixel == keyclr. if keepAlpha is true then dest alpha is preserved. if keepAlpha is false then src alpha is copied to dest.
    • getPixels

      public int[] getPixels(int x, int y, int w, int h)
      Gets a rectangle of pixels (including alpha)
    • getPixels

      public int[] getPixels()
      Returns a copy of the buffer
    • getBuffer

      public int[] getBuffer()
      Returns the data buffer
    • clear

      public void clear()
      Clears the image to black with opaque alpha.
    • fill

      public void fill(int x, int y, int w, int h, int clr)
      Fills a rectangle with clr (assumes OPAQUE alpha)
    • fill

      public void fill(int x, int y, int w, int h, int clr, boolean hasAlpha)
      Fills a rectangle with clr
    • fillAlpha

      public void fillAlpha(int x, int y, int w, int h, int lvl)
      Fills the alpha channel with lvl (doesn't touch rgb values)
    • fillAlphaKeyClr

      public void fillAlphaKeyClr(int x, int y, int w, int h, int lvl, int keyClr)
      Fills alpha channel with lvl ONLY where dest pixel == keyClr
    • box

      public void box(int x, int y, int w, int h, int clr)
      Draw a rectangle outline in clr (assumes opaque).
    • hline

      public void hline(int x1, int x2, int y, int clr)
      Draw a horizontal line
    • vline

      public void vline(int x, int y1, int y2, int clr)
      Draw a vertical line
    • line

      public void line(int x1, int y1, int x2, int y2, int clr)
      Draw a line
    • oval

      public void oval(int x, int y, int w, int h, int clr)
      Draw a circle/oval
    • arc

      public void arc(int x, int y, int w, int h, int startAngle, int arcAngle, int clr)
      Draw an arc
    • fillOval

      public void fillOval(int x, int y, int w, int h, int clr)
      Draw a filled circle/oval
    • fillArc

      public void fillArc(int x, int y, int w, int h, int startAngle, int arcAngle, int clr)
      Draw a filled arc
    • getFontMetrics

      public int[] getFontMetrics(Font fnt, String txt)
      Returns font metrics for a given font/text.
      Parameters:
      fnt - - Font
      txt - - sample text
      Returns:
      [0] = width required to draw text in font [1] = ascent [2] = descent NOTE : total height required = ascent + descent Note : add ascent to y coordinate of print() to start printing below your coordinates For a static version see JF.java
    • print

      public void print(Font fnt, int x, int y, String txt, int clr)
      Draws text in font at x,y in clr
    • setFont

      public void setFont(Font font)
      Sets the font in the Graphics object (if this JFImage is used as a JComponent)
      Overrides:
      setFont in class JComponent
    • getIconHeight

      public int getIconHeight()
      Specified by:
      getIconHeight in interface Icon
    • getIconWidth

      public int getIconWidth()
      Specified by:
      getIconWidth in interface Icon
    • paintIcon

      public void paintIcon(Component c, Graphics g, int x, int y)
      Specified by:
      paintIcon in interface Icon
    • createScreenCapture

      public static JFImage createScreenCapture()
      Uses java.awt.Robot to capture and return a screen image.
    • createScreenCapture

      public static JFImage createScreenCapture(GraphicsDevice device)
      Uses java.awt.Robot to capture and return a screen image.
    • createScreenCapture

      public static JFImage createScreenCapture(Rectangle rect)
      Uses java.awt.Robot to capture and return a screen image of specified rectangle.
    • createScreenCapture

      public static JFImage createScreenCapture(GraphicsDevice device, Rectangle rect)
      Uses java.awt.Robot to capture and return a screen image of specified rectangle.
    • getLayer

      public int[] getLayer(int bits)
      Gets color Layer (RGB) : pixels AND bits
    • putLayer

      public void putLayer(int[] px, int bits)
      Puts color Layer (RGB) : (pixels OR bits)
    • getAlphaLayer

      public int[] getAlphaLayer()
      Gets alpha Layer as grey scale
    • putAlphaLayer

      public void putAlphaLayer(int[] px)
      Puts alpha Layer from grey scale
    • transform

      public void transform(AffineTransform at)
    • flipHorizontal

      public void flipHorizontal()
    • flipVertical

      public void flipVertical()
    • flipBoth

      public void flipBoth()
    • rotate

      public void rotate(double angle)
    • negative

      public void negative()