Package javaforce.awt
Class JFImage
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javaforce.awt.JFImage
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Icon
Encapsules BufferedImage to provide more functions.
Implements javax.swing.Icon so it can also be used with JLabel.
- Author:
- Peter Quiring
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidarc(int x, int y, int w, int h, int startAngle, int arcAngle, int clr) Draw an arcvoidbox(int x, int y, int w, int h, int clr) Draw a rectangle outline in clr (assumes opaque).voidclear()Clears the image to black with opaque alpha.static JFImageUses java.awt.Robot to capture and return a screen image.static JFImagecreateScreenCapture(GraphicsDevice device) Uses java.awt.Robot to capture and return a screen image.static JFImagecreateScreenCapture(GraphicsDevice device, Rectangle rect) Uses java.awt.Robot to capture and return a screen image of specified rectangle.static JFImagecreateScreenCapture(Rectangle rect) Uses java.awt.Robot to capture and return a screen image of specified rectangle.voidfill(int x, int y, int w, int h, int clr) Fills a rectangle with clr (assumes OPAQUE alpha)voidfill(int x, int y, int w, int h, int clr, boolean hasAlpha) Fills a rectangle with clrvoidfillAlpha(int x, int y, int w, int h, int lvl) Fills the alpha channel with lvl (doesn't touch rgb values)voidfillAlphaKeyClr(int x, int y, int w, int h, int lvl, int keyClr) Fills alpha channel with lvl ONLY where dest pixel == keyClrvoidfillArc(int x, int y, int w, int h, int startAngle, int arcAngle, int clr) Draw a filled arcvoidfillOval(int x, int y, int w, int h, int clr) Draw a filled circle/ovalintgetAlpha(int x, int y) Returns alpha value of pixel at x,yint[]Gets alpha Layer as grey scaleint[]Returns the data bufferint[]getFontMetrics(Font fnt, String txt) Returns font metrics for a given font/text.intintintgetImage()getJFImage(int x, int y, int w, int h) Returns an area of this image as a new JFImage.int[]getLayer(int bits) Gets color Layer (RGB) : pixels AND bitsintgetPixel(int x, int y) Returns rgb value of pixel at x,yint[]Returns a copy of the bufferint[]getPixels(int x, int y, int w, int h) Gets a rectangle of pixels (including alpha)intgetWidth()voidhline(int x1, int x2, int y, int clr) Draw a horizontal linevoidline(int x1, int y1, int x2, int y2, int clr) Draw a linebooleanload(InputStream in) booleanbooleanloadBMP(InputStream in, int index) booleanbooleanloadJPG(InputStream in) booleanstatic JFImage[]loadmulti(InputStream is) booleanloadPNG(InputStream in) booleanbooleanloadSVG(InputStream in, int width, int height) booleanbooleanloadTIFF(InputStream in) booleanstatic JFImage[]loadTIFFs(InputStream in) booleanloadXPM(InputStream in) booleanvoidoval(int x, int y, int w, int h, int clr) Draw a circle/ovalvoidPaint this image onto Graphics.voidvoidDraws text in font at x,y in clrvoidputAlpha(int x, int y, int lvl) Sets alpha value at x,yvoidputAlphaLayer(int[] px) Puts alpha Layer from grey scalevoidputJFImage(JFImage img, int x, int y) Puts pixels .voidputJFImageBlend(JFImage img, int x, int y, boolean keepAlpha) Puts pixels blending using img alpha (dest alpha is ignored)voidputJFImageKeyClr(JFImage img, int x, int y, int keyClr) Puts pixels unless src pixel == keyclrvoidputJFImageScale(JFImage img, int x, int y, int width, int height) Puts pixels scaling image to fitvoidputLayer(int[] px, int bits) Puts color Layer (RGB) : (pixels OR bits)voidputPixel(int x, int y, int c) Draws one pixel using rgb value (alpha assumed opaque)voidputPixel(int x, int y, int r, int g, int b) Draws one pixel using r,g,b values (alpha assumed opaque)voidputPixels(int[] src, int x, int y, int w, int h, int srcOffset) Puts pixelsvoidputPixels(int[] src, int x, int y, int w, int h, int srcOffset, int srcScanSize) Puts pixels (supports padding at end of each scan line)voidputPixelsBlend(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).voidputPixelsBlendKeyClr(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.voidputPixelsKeyClr(int[] px, int x, int y, int w, int h, int offset, int keyclr) Put Pixels unless src pixel == keyclrbooleansave(OutputStream out, String fmt) booleanbooleansaveBMP(OutputStream out) booleanbooleansaveICNS(OutputStream out) save icns (Mac icon)booleansave icns (Mac icon)booleansaveICO(OutputStream out) booleanbooleansaveJPG(OutputStream out) booleanstatic booleansavemulti(OutputStream os, JFImage[] imgs, String format) booleansavePNG(OutputStream out) booleanbooleansaveSVG(OutputStream out) booleanbooleansaveTIFF(OutputStream out) booleanstatic booleansaveTIFFs(OutputStream out, JFImage[] imgs) voidsetBounds(int x, int y, int w, int h) voidReplaced BufferedImage.voidSets the font in the Graphics object (if this JFImage is used as a JComponent)voidsetImageSize(int x, int y) voidControls how this image is resized by layout managers.voidsetSize(int x, int y) voidvoidvline(int x, int y1, int y2, int clr) Draw a vertical lineMethods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUIMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
ALPHA_MASK
public static final int ALPHA_MASK- See Also:
-
OPAQUE
public static final int OPAQUE- See Also:
-
TRANSPARENT
public static final int TRANSPARENT- See Also:
-
RED_MASK
public static final int RED_MASK- See Also:
-
GREEN_MASK
public static final int GREEN_MASK- See Also:
-
BLUE_MASK
public static final int BLUE_MASK- See Also:
-
RGB_MASK
public static final int RGB_MASK- See Also:
-
-
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) -
setSize
public void setSize(int x, int y) -
setSize
-
setResizeOperation
Controls how this image is resized by layout managers. -
getImage
-
getBufferedImage
-
setBufferedImage
Replaced BufferedImage. Must be TYPE_INT_ARGB or TYPE_INT_RGB type.- Parameters:
bi- - new BufferedImage
-
getGraphics
- Overrides:
getGraphicsin classJComponent
-
getGraphics2D
-
paint
Paint this image onto Graphics.- Overrides:
paintin classJComponent
-
getWidth
public int getWidth()- Overrides:
getWidthin classJComponent
-
getHeight
public int getHeight()- Overrides:
getHeightin classJComponent
-
load
-
save
-
load
-
save
-
loadmulti
-
savemulti
-
loadJPG
-
saveJPG
-
loadJPG
-
saveJPG
-
loadPNG
-
savePNG
-
loadPNG
-
savePNG
-
loadBMP
-
saveBMP
-
loadBMP
-
saveBMP
-
saveICO
-
saveICO
-
saveICNS
save icns (Mac icon) -
saveICNS
save icns (Mac icon) -
loadSVG
-
saveSVG
-
loadSVG
-
saveSVG
-
loadXPM
-
loadXPM
-
loadTIFF
-
saveTIFF
-
loadTIFF
-
saveTIFF
-
loadTIFFs
-
saveTIFFs
-
putJFImage
Puts pixels . -
putJFImageKeyClr
Puts pixels unless src pixel == keyclr -
putJFImageBlend
Puts pixels blending using img alpha (dest alpha is ignored) -
putJFImageScale
Puts pixels scaling image to fit -
getJFImage
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
Returns font metrics for a given font/text.- Parameters:
fnt- - Fonttxt- - 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
Draws text in font at x,y in clr -
setFont
Sets the font in the Graphics object (if this JFImage is used as a JComponent)- Overrides:
setFontin classJComponent
-
getIconHeight
public int getIconHeight()- Specified by:
getIconHeightin interfaceIcon
-
getIconWidth
public int getIconWidth()- Specified by:
getIconWidthin interfaceIcon
-
paintIcon
-
createScreenCapture
Uses java.awt.Robot to capture and return a screen image. -
createScreenCapture
Uses java.awt.Robot to capture and return a screen image. -
createScreenCapture
Uses java.awt.Robot to capture and return a screen image of specified rectangle. -
createScreenCapture
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
-