List of utility methods to do Image
Image | createTiledImage(Image img, int width, int height) Crea un 'tiled image' con un objeto image con una anchura y altura Image image = null; BufferedImage bimg = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); int imageWidth = img.getWidth(null); int imageHeight = img.getHeight(null); int numX = (width / imageWidth) + 2; int numY = (height / imageHeight) + 2; Graphics2D bGr = bimg.createGraphics(); for (int y = 0; y < numY; y++) { ... |
Image | crop(Image source, int x1, int y1, int x2, int y2) crop BufferedImage bi = toBufferedImage(source);
BufferedImage img = bi.getSubimage(x1, y1, x2, y2);
return img;
|
void | displayImage(Image image) display Image ImageIcon icon = new ImageIcon(image); JFrame frame = new JFrame(); frame.setLayout(new FlowLayout()); frame.setSize(image.getWidth(null) + 25, image.getHeight(null) + 50); JLabel lbl = new JLabel(); lbl.setIcon(icon); frame.add(lbl); frame.setVisible(true); ... |
void | displayImage(Image img) display Image JFrame f = new JFrame("DEBUG IMG"); JLabel label = new JLabel(new ImageIcon(img)); label.setBorder(BorderFactory.createLineBorder(Color.RED)); f.setLayout(new BorderLayout()); f.add(label, BorderLayout.WEST); f.pack(); f.setVisible(true); f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); ... |
JDialog | displayImage(Image img, String mesg, int locx, int locy, int sizex, int sizey) display Image JDialog imgBox = new JDialog(new java.awt.Frame(), mesg, false); JPanel imgPanel = new JPanel(new BorderLayout()); imgBox.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); imgBox.setLocation(locx, locy); imgBox.setSize(sizex, sizey); imgBox.setContentPane(imgPanel); ImageIcon imgIcon = new ImageIcon(img, ""); JLabel imgLabel = new JLabel(imgIcon); ... |
List | divideImage(Object obj, int rows, int cols) divide Image BufferedImage bi; if (obj instanceof Image) { bi = toBufferedImage((Image) obj); } else if (obj instanceof ImageIcon) { bi = toBufferedImage(((ImageIcon) obj).getImage()); } else { bi = (BufferedImage) obj; int altoBi = bi.getHeight() / rows; int anchoBi = bi.getWidth() / cols; List<BufferedImage> imagenes = new ArrayList<>(); BufferedImage subImagen; for (int f = 0; f < rows; f++) { for (int c = 0; c < cols; c++) { subImagen = bi.getSubimage(c * anchoBi, f * altoBi, anchoBi, altoBi); imagenes.add(subImagen); return imagenes; |
Image | ensureImageLoaded(Image img) Ensures that the image is properly loaded before returning if (img instanceof BufferedImage) { return img; if (img.getWidth(null) > -1) { return img; if (IMAGE_LOADER == null) { IMAGE_LOADER = new ImageIcon(); ... |
Image | findImagefromClasspath(Class relToThisClass, String relImageName) find Imagefrom Classpath Image image = null; String name = relToThisClass.getName(); String path = name.substring(0, name.lastIndexOf('.')); path = path.replace('.', '/'); path = path + relImageName.substring(1); String classpath = System.getProperty(CLASSPATH); StringTokenizer st = new StringTokenizer(classpath, ";:"); while (st.hasMoreTokens()) { ... |
JPanel | generateImageVisualizationPanel(String path, int width, int height, int scaling) generate Image Visualization Panel JPanel panel = new JPanel(new BorderLayout()); try { Image image = ImageIO.read(new File(path)); InputStream is = new BufferedInputStream(new FileInputStream(path)); image = ImageIO.read(is); ImageIcon icon = new ImageIcon(path); icon.setImage(image); JLabel label = new JLabel(icon); ... |
Image | getChatLogoImage(int width, int height) get Chat Logo Image return getChatLogoImage().getScaledInstance(width, height, Image.SCALE_AREA_AVERAGING);
|