private void blitSymbol(double x, double y, int size, int symbol, boolean fill) { Image[][][] images = (Image[][][]) symbols.get(webColor); if (images == null) { images = new Image[2][NUMBER_OF_SYMBOLS][MAX_BLIT_SIZE]; symbols.put(webColor, images); } Image image = images[fill ? 1 : 0][symbol][size - 1]; int imageSize = size + 1; double imageSize2 = imageSize / 2.0; if (image == null) { image = getDeviceConfiguration() .createCompatibleImage(imageSize + 1, imageSize + 1, Transparency.BITMASK); VectorGraphics imageGraphics = VectorGraphics.create(image.getGraphics()); Composite composite = imageGraphics.getComposite(); imageGraphics.setComposite(AlphaComposite.Clear); imageGraphics.fillRect(0, 0, size, size); imageGraphics.setComposite(composite); imageGraphics.setColor(getColor()); if (fill) { fillSymbol(imageGraphics, imageSize2, imageSize2, size, symbol); } else { drawSymbol(imageGraphics, imageSize2, imageSize2, size, symbol); } images[fill ? 1 : 0][symbol][size - 1] = image; } drawImage(image, (int) (x - imageSize2), (int) (y - imageSize2), null); }
/** * Renders the image at the proper size into <code>bgImage</code>. This method assumes that <code> * bgImage</code> is not <code>null</code>. * * @param width The width of the volatile image to render into. * @param height The height of the volatile image to render into. * @param hint The scaling hint to use. */ protected void renderImage(int width, int height, int hint) { Image master = getMasterImage(); if (master != null) { do { Image i = master.getScaledInstance(width, height, hint); tracker.addImage(i, 1); try { tracker.waitForID(1); } catch (InterruptedException e) { e.printStackTrace(); bgImage = null; return; } finally { tracker.removeImage(i, 1); } bgImage.getGraphics().drawImage(i, 0, 0, null); tracker.addImage(bgImage, 0); try { tracker.waitForID(0); } catch (InterruptedException e) { e.printStackTrace(); bgImage = null; return; } finally { tracker.removeImage(bgImage, 0); } } while (bgImage.contentsLost()); } // End of if (master!=null). else { bgImage = null; } }
protected Icon buildInactiveImageIcon(ImageIcon imageIcon) { Image image = imageIcon.getImage(); Image inactiveImage = Toolkit.getDefaultToolkit() .createImage(new FilteredImageSource(image.getSource(), INACTIVE_ICON_FILTER)); return new ImageIcon(inactiveImage); }
public Icon getIcon(File f) { if (isDirLink(f)) { /* all of this nonsense is to get to the default file view */ System.out.println("get icon for: " + f); JFileChooser chooser = new JFileChooser(); ComponentUI ui = UIManager.getUI(chooser); System.out.println("got : " + ui); FileChooserUI fcui = (FileChooserUI) ui; fcui.installUI(chooser); FileView def = fcui.getFileView(chooser); // get the standard icon for a folder File tmp = new File("C:\\windows"); Icon folder = def.getIcon(tmp); int w = folder.getIconWidth(); int h = folder.getIconHeight(); // create a buffered image the same size as the icon Image img = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR); Graphics g = img.getGraphics(); // draw the normal icon folder.paintIcon(chooser, g, 0, 0); Image shortcut = new ImageIcon("shortcut.png").getImage(); g.drawImage(shortcut, 0, 0, null); g.dispose(); return new ImageIcon(img); } return super.getIcon(f); }
private void initialise() { Toolkit toolkit = Toolkit.getDefaultToolkit(); backBuffer = worldMap.getGraphics(); // Make the image buffer as large as could possibly be used (screensize) if (backBufferImage == null) { logger.debug( "Creating backBufferImage of dimensions " + toolkit.getScreenSize().width + "," + toolkit.getScreenSize().height + "."); backBufferImage = createImage(toolkit.getScreenSize().width, toolkit.getScreenSize().height); backBuffer = backBufferImage.getGraphics(); } else { backBufferImage.flush(); backBufferImage = createImage(toolkit.getScreenSize().width, toolkit.getScreenSize().height); backBuffer.dispose(); backBuffer = backBufferImage.getGraphics(); } setupWindow(worldMap.getWidth(), worldMap.getHeight()); initialise = false; logger.debug( "initialised backBufferImage with size " + worldMap.getWidth() + "," + worldMap.getHeight() + "."); }
final void initHuman() { String sql = "Select * from tblHuman where id = ?"; try (Connection cn = Tools.getConn(); PreparedStatement pst = cn.prepareStatement(sql); ) { pst.setInt(1, Integer.parseInt(vRow.get(0).toString())); ResultSet rs = pst.executeQuery(); if (rs.next()) { txtUserName.setText(rs.getString(2)); txtBirthDay.setDate(rs.getDate(3)); txtGender.setText(rs.getString(4)); txtBirthPlace.setText(rs.getString(5)); txtNativeCountry.setText(rs.getString(6)); txtNation.setText(rs.getString(7)); txtReligion.setText(rs.getString(8)); txtOccupation.setText(rs.getString(9)); txtWorkPlace.setText(rs.getString(10)); txtIDCard.setText(rs.getString(11)); txtArrivalDate.setDate(rs.getDate(12)); byte[] b = rs.getBytes(13); ImageIcon icon = new ImageIcon(b); Image img = icon.getImage(); img = img.getScaledInstance(lblImage.getWidth(), lblImage.getHeight(), Image.SCALE_SMOOTH); lblImage.setIcon(new ImageIcon(img)); txtRoomID.setText(rs.getString(14)); txtEmail.setText(rs.getString(15)); } } catch (SQLException ex) { Logger.getLogger(EditHumanDialog.class.getName()).log(Level.SEVERE, null, ex); } }
/** * Returns the specified image as icon. * * @param name name of icon * @return icon */ public static ImageIcon icon(final String name) { ImageIcon ii = ICONS.get(name); if (ii != null) return ii; Image img; if (GUIConstants.scale > 1) { // choose large image or none final URL url = GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null; if (url == null) { // resize low-res image if no hi-res image exists img = get(url(name)); final int w = (int) (img.getWidth(null) * GUIConstants.scale); final int h = (int) (img.getHeight(null) * GUIConstants.scale); final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.drawImage(img, 0, 0, w, h, null); g2.dispose(); img = tmp; } else { img = get(url); } } else { img = get(name); } ii = new ImageIcon(img); ICONS.put(name, ii); return ii; }
/** * Returns a scaled instance of the tile image. Using a MediaTracker instance, this function waits * until the scaling operation is done. * * <p>Internally it caches the scaled image in order to optimize the common case, where the same * scale is requested as the last time. * * @param zo * @return Image */ public Image getScaledImage(double zo) { Image scaledImage = null; if (zo == 1.0) { return getImage(); } else if (zo == zoom && scaledImage != null) { return scaledImage; } else { Image img = getImage(); // System.out.println(getWidth()); if (img != null) { scaledImage = img.getScaledInstance( (int) (getWidth() * zo), (int) (getHeight() * zo), BufferedImage.SCALE_SMOOTH); MediaTracker mediaTracker = new MediaTracker(new Canvas()); mediaTracker.addImage(scaledImage, 0); try { mediaTracker.waitForID(0); } catch (InterruptedException ie) { System.err.println(ie); } mediaTracker.removeImage(scaledImage); zoom = zo; return scaledImage; } } return null; }
/** * Construct a GIFEncoder. The constructor will convert the image to an indexed color array. * <B>This may take some time.</B> * * <p> * * @param image The image to encode. The image <B>must</B> be completely loaded. * @exception AWTException Will be thrown if the pixel grab fails. This can happen if Java runs * out of memory. It may also indicate that the image contains more than 256 colors. */ public GIFEncoder(Image image) throws AWTException { width_ = (short) image.getWidth(null); height_ = (short) image.getHeight(null); int values[] = new int[width_ * height_]; PixelGrabber grabber = new PixelGrabber(image, 0, 0, width_, height_, values, 0, width_); try { if (grabber.grabPixels() != true) throw new AWTException("Grabber returned false: " + grabber.status()); } catch (InterruptedException e) {; } byte r[][] = new byte[width_][height_]; byte g[][] = new byte[width_][height_]; byte b[][] = new byte[width_][height_]; int index = 0; for (int y = 0; y < height_; ++y) for (int x = 0; x < width_; ++x) { r[x][y] = (byte) ((values[index] >> 16) & 0xFF); g[x][y] = (byte) ((values[index] >> 8) & 0xFF); b[x][y] = (byte) ((values[index]) & 0xFF); ++index; } ToIndexedColor(r, g, b); }
public static void stop() { try { Thread.sleep(5000); FrameGrabbingControl fgc = (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl"); Buffer buf = fgc.grabFrame(); BufferToImage btoi = new BufferToImage((VideoFormat) buf.getFormat()); player.stop(); Image img = btoi.createImage(buf); int w = img.getWidth(null); int h = img.getHeight(null); BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bi.createGraphics(); g2.drawImage(img, 0, 0, null); g2.dispose(); try { ImageIO.write(bi, "jpg", new File("C:/ii.jpg")); } catch (IOException ex) { Logger.getLogger(Capture_video.class.getName()).log(Level.SEVERE, null, ex); } } catch (InterruptedException ex) { Logger.getLogger(Capture_video.class.getName()).log(Level.SEVERE, null, ex); } }
/** * Returns the hotspot of the image used to draw a single data item. The hotspot is the point * relative to the top left of the image that should indicate the data item. The default is the * center of the image. * * @param plot the plot (can be used to obtain standard color information etc). * @param image the image (can be used to get size information about the image) * @param series the series index * @param item the item index * @param x the x value of the item * @param y the y value of the item * @return The hotspot used to draw the data item. */ protected Point getImageHotspot( Plot plot, int series, int item, double x, double y, Image image) { int height = image.getHeight(null); int width = image.getWidth(null); return new Point(width / 2, height / 2); }
public void drawMirrorImage(Image img, int x, int y) { if (img != null) { int w = img.getWidth(null); int h = img.getHeight(null); g2d.drawImage(img, x + w, y, x, y + h, 0, 0, w, h, null); } }
public void scaleImage( Image image, int p_width, int p_height, boolean keepaspect) /*throws Exception*/ { int thumbWidth = p_width; int thumbHeight = p_height; // Make sure the aspect ratio is maintained, so the image is not skewed if (keepaspect) { double thumbRatio = (double) thumbWidth / (double) thumbHeight; int imageWidth = image.getWidth(null); int imageHeight = image.getHeight(null); double imageRatio = (double) imageWidth / (double) imageHeight; if (thumbRatio < imageRatio) { thumbHeight = (int) (thumbWidth / imageRatio); } else { thumbWidth = (int) (thumbHeight * imageRatio); } } // Draw the scaled image BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB); Graphics2D graphics2D = thumbImage.createGraphics(); graphics2D.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null); this.img = thumbImage; }
public boolean scaleImage( SunGraphics2D sg, Image img, int x, int y, int width, int height, Color bgColor) { int imgw = img.getWidth(null); int imgh = img.getHeight(null); // Only accelerate scale if: // - w/h positive values // - sg transform integer translate/identity only // - no bgColor in operation if ((width > 0) && (height > 0) && isSimpleTranslate(sg)) { double dx1 = x + sg.transX; double dy1 = y + sg.transY; double dx2 = dx1 + width; double dy2 = dy1 + height; if (renderImageScale( sg, img, bgColor, sg.interpolationType, 0, 0, imgw, imgh, dx1, dy1, dx2, dy2)) { return true; } } AffineTransform atfm = sg.transform; if ((x | y) != 0 || width != imgw || height != imgh) { atfm = new AffineTransform(atfm); atfm.translate(x, y); atfm.scale(((double) width) / imgw, ((double) height) / imgh); } transformImage(sg, img, atfm, sg.interpolationType, 0, 0, imgw, imgh, bgColor); return true; }
public void drawPauseGraph() { // First paint background // Dimension d = getSize(); checkOffscreenImage(); // Graphics offG = mImage.getGraphics(); // offG.setColor(getBackground()); // offG.fillRect(0, 0, m_width, m_height); Graphics g1 = getGraphics(); if (m_state == 1) createGraph(mImage.getGraphics()); else if (m_state == 0) pauseTimeGraph(mImage.getGraphics()); g1.drawImage(mImage, 0, 0, null); // Graphics2D g = (Graphics2D) g1; // Use anti-aliasing to avoid "jaggies" in the lines // g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // RenderingHints.VALUE_ANTIALIAS_ON); // createGraph(g1); // Graphics g1 = getGraphics(); // Graphics2D g = (Graphics2D) g1; // Use anti-aliasing to avoid "jaggies" in the lines // g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // RenderingHints.VALUE_ANTIALIAS_ON); // pauseTimeGraph(g); } //
DisplayCanvas() { setBackground(Color.white); setSize(450, 400); addMouseMotionListener(new MouseMotionHandler()); Image image = getToolkit().getImage("D:\\Workspaces\\ADTJunoWorkspace\\Snippets\\images\\qr.png"); MediaTracker mt = new MediaTracker(this); mt.addImage(image, 1); try { mt.waitForAll(); } catch (Exception e) { System.out.println("Exception while loading image."); } if (image.getWidth(this) == -1) { System.out.println("no gif file"); System.exit(0); } bi = new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_ARGB); Graphics2D big = bi.createGraphics(); big.drawImage(image, 0, 0, this); }
public void paint(Graphics g1) { // Dimension d = getSize(); checkOffscreenImage(); // Graphics offG = mImage.getGraphics(); // offG.setColor(getBackground()); // offG.fillRect(0, 0, m_width, m_height); if (m_state == 1) createGraph(mImage.getGraphics()); else if (m_state == 0) pauseTimeGraph(mImage.getGraphics()); g1.drawImage(mImage, 0, 0, null); // //Graphics2D g2d = (Graphics2D)g; // Graphics2D g = (Graphics2D) g1; // // Use anti-aliasing to avoid "jaggies" in the lines // // g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // // RenderingHints.VALUE_ANTIALIAS_ON); // // g.setColor(m_Bkg_color); // //g.draw3DRect(5, 5, m_width-10, m_height-10, true); // g.fillRect(0, 0, m_width-1, m_height+200); // // if(m_state==1) // createGraph(g); // else if(m_state==0) // pauseTimeGraph(g); // labelTheAxis(g); }
/** * Setter for property image. * * @param image New value of property image. */ public void setImage(final Image image) { mImage = image; if (null != image) { width = image.getWidth(null); height = image.getHeight(null); } }
/** Draw a line for the text eval area. */ public void paintTaggedLine( Segment lineText, int lineIndex, Graphics g, int x, int y, MoeSyntaxDocument document, Color def, Element line, TabExpander tx) { if (hasTag(line, OUTPUT)) { g.setColor(outputColor); Utilities.drawTabbedText(lineText, x, y, g, tx, 0); } else if (hasTag(line, ERROR)) { g.setColor(errorColor); Utilities.drawTabbedText(lineText, x, y, g, tx, 0); } else if (hasObject(line, OBJECT)) { g.drawImage(objectImage, x - 1 - LEFT_MARGIN, y + 3 - objectImage.getHeight(null), null); g.setColor(outputColor); Utilities.drawTabbedText(lineText, x, y, g, tx, 0); } else if (hasTag(line, CONTINUE)) { g.drawImage(continueImage, x - 1 - LEFT_MARGIN, y + 3 - continueImage.getHeight(null), null); paintSyntaxLine(lineText, lineIndex, x, y, g, document, def, tx); } else { g.drawImage(promptImage, x - 1 - LEFT_MARGIN, y + 3 - promptImage.getHeight(null), null); paintSyntaxLine(lineText, lineIndex, x, y, g, document, def, tx); } }
private void paintSprites(List<Sprite> sprites) { if (sprites != null) { for (int i = 0; i < sprites.size(); i++) { // get all sprites with getresource URL imagePath = this.getClass().getResource(sprites.get(i).getImageName().toString()); ImageIcon icon = new ImageIcon(imagePath); JLabel picLabel = new JLabel(icon); picLabel.setBounds( sprites.get(i).getX(), sprites.get(i).getY(), icon.getIconWidth(), icon.getIconHeight()); this.add(picLabel); } ImageIcon bgImageIcon = new ImageIcon(this.getClass().getResource(controller.getGameModel().getBkgURL())); Image reImage = bgImageIcon.getImage(); reImage = reImage.getScaledInstance( Dimensions.GAME_MAKER_RIGHT_PANEL_WIDTH, Dimensions.GAME_MAKER_RIGHT_PANEL_HEIGHT, Image.SCALE_SMOOTH); bgImageIcon = new ImageIcon(reImage); JLabel bkgImageLabel = new JLabel(bgImageIcon); bkgImageLabel.setBounds( 0, Dimensions.GAME_MAKER_RIGHT_PANEL_Y, Dimensions.GAME_MAKER_RIGHT_PANEL_WIDTH, Dimensions.GAME_MAKER_RIGHT_PANEL_HEIGHT); this.add(bkgImageLabel); } }
/** * 插入LOGO * * @param source 二维码图片 * @param imgPath LOGO图片地址 * @param needCompress 是否压缩 * @throws Exception */ private static void insertImage(BufferedImage source, String imgPath, boolean needCompress) throws Exception { File file = new File(imgPath); if (!file.exists()) { System.err.println("" + imgPath + " 该文件不存在!"); return; } Image src = ImageIO.read(new File(imgPath)); int width = src.getWidth(null); int height = src.getHeight(null); if (needCompress) { // 压缩LOGO if (width > WIDTH) { width = WIDTH; } if (height > HEIGHT) { height = HEIGHT; } Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH); BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = tag.getGraphics(); g.drawImage(image, 0, 0, null); // 绘制缩小后的图 g.dispose(); src = image; } // 插入LOGO Graphics2D graph = source.createGraphics(); int x = (QRCODE_WIDTH - width) / 2; int y = (QRCODE_HEIGHT - height) / 2; graph.drawImage(src, x, y, width, height, null); Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6); graph.setStroke(new BasicStroke(3f)); graph.draw(shape); graph.dispose(); }
/*Add button to master panel*/ private void addHistoryButton(JFrame frame, JPanel panel) { ImageIcon buttonImage = new ImageIcon("assets\\other\\button.png"); ImageIcon buttonPressedImage = new ImageIcon("assets\\other\\buttonPressed.png"); // button JPanel buttonHolder = new JPanel(); this.searchButton = new JButton("MATCH HISTORY"); this.searchButton.setPreferredSize(new Dimension(222, 50)); this.searchButton.setFont(new Font("Sen-Regular", Font.CENTER_BASELINE, 10)); // custom font this.searchButton.setForeground(Color.WHITE); // text color this.searchButton.setBackground(Color.DARK_GRAY); this.searchButton.setBorder(BorderFactory.createLineBorder(Color.BLACK)); this.searchButton.setHorizontalTextPosition(AbstractButton.CENTER); // search button background image // regular button Image tempImage = buttonImage.getImage(); Image newTempImg = tempImage.getScaledInstance(222, 50, Image.SCALE_SMOOTH); buttonImage = new ImageIcon(newTempImg); // pressed button Image tempImage2 = buttonPressedImage.getImage(); Image newTempImg2 = tempImage2.getScaledInstance(222, 50, Image.SCALE_SMOOTH); buttonPressedImage = new ImageIcon(newTempImg2); this.searchButton.setIcon(buttonImage); this.searchButton.setRolloverIcon(buttonPressedImage); this.searchButton.addActionListener(this); buttonHolder.add(this.searchButton); buttonHolder.setOpaque(false); panel.add(buttonHolder); }
private Image createAuctionIcon(int width, int height) { Image buffer = createImage(width, height); Graphics canvas = buffer.getGraphics(); ArrayList<Integer> auctionColours = ((CTWorld) Simulator.pworld).getAuctionColours(); if ((auctionColours != null) && !auctionColours.isEmpty()) { int blockWidth = width / auctionColours.size(); int offset = 0; Iterator<Integer> iterator = auctionColours.iterator(); while (iterator.hasNext()) { Integer auctionColour = iterator.next(); Color color = getColor(auctionColour); canvas.setColor(color); canvas.fillRect(offset, 0, blockWidth, height); offset = offset + blockWidth; } } else { canvas.setColor(getColor(CTWorld.NEUTRAL)); canvas.fillRect(0, 0, width, height); } return buffer; }
public GifEncoder(Image image) throws AWTException { this.width_ = (short) image.getWidth(null); this.height_ = (short) image.getHeight(null); int[] values = new int[this.width_ * this.height_]; PixelGrabber grabber = new PixelGrabber(image, 0, 0, this.width_, this.height_, values, 0, this.width_); try { if (!grabber.grabPixels()) { throw new AWTException("Grabber returned false: " + grabber.status()); } } catch (InterruptedException e) { byte[][] r = new byte[this.width_][this.height_]; byte[][] g = new byte[this.width_][this.height_]; byte[][] b = new byte[this.width_][this.height_]; int index = 0; for (int y = 0; y < this.height_; y++) for (int x = 0; x < this.width_; x++) { r[x][y] = (byte) (values[index] >> 16 & 0xFF); g[x][y] = (byte) (values[index] >> 8 & 0xFF); b[x][y] = (byte) (values[index] & 0xFF); index++; } ToIndexedColor(r, g, b); } }
public void createGUI() { setLayout(new BorderLayout()); buttonPanel.add(submitButton); buttonPanel.setSize(400, 400); hostPanel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); ImageIcon imageIcon = new ImageIcon("images/logo.png"); // load the image to a imageIcon Image image = imageIcon.getImage(); // transform it Image newimg = image.getScaledInstance(600, 120, java.awt.Image.SCALE_SMOOTH); // scale it the smooth way imageIcon = new ImageIcon(newimg); // transform it back JLabel scrabbleLabel = new JLabel(imageIcon, SwingConstants.CENTER); add(scrabbleLabel, BorderLayout.NORTH); gbc.gridx = 0; gbc.gridy = 0; hostPanel.add(hostLabel, gbc); gbc.gridx = 0; gbc.insets = new Insets(46, 0, 46, 0); gbc.gridy = 1; hostPanel.add(portLabel, gbc); gbc.gridx = 1; gbc.gridy = 1; gbc.anchor = GridBagConstraints.EAST; hostPanel.add(portTF, gbc); gbc.anchor = GridBagConstraints.CENTER; gbc.gridx = 0; gbc.gridy = 2; gbc.gridwidth = 2; hostPanel.add(buttonPanel, gbc); add(hostPanel, BorderLayout.CENTER); }
/** * Renders an image on the device * * @param tx the image location on the screen, x coordinate * @param ty the image location on the screen, y coordinate * @param img the image * @param rotation the image rotatation */ private static void renderImage( Graphics2D graphics, double x, double y, Image image, double rotation, float opacity) { AffineTransform temp = graphics.getTransform(); AffineTransform markAT = new AffineTransform(); Point2D mapCentre = new java.awt.geom.Point2D.Double(x, y); Point2D graphicCentre = new java.awt.geom.Point2D.Double(); temp.transform(mapCentre, graphicCentre); markAT.translate(graphicCentre.getX(), graphicCentre.getY()); double shearY = temp.getShearY(); double scaleY = temp.getScaleY(); double originalRotation = Math.atan(shearY / scaleY); markAT.rotate(rotation); graphics.setTransform(markAT); graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity)); // we moved the origin to the centre of the image. graphics.drawImage(image, -image.getWidth(null) / 2, -image.getHeight(null) / 2, null); graphics.setTransform(temp); return; }
private void scaleImage() { width = image.getWidth(this); height = image.getHeight(this); double ratio = 1.0; /* * Determine how to scale the image. Since the accessory can expand * vertically make sure we don't go larger than 150 when scaling * vertically. */ if (width >= height) { ratio = (double) (ACCSIZE - 5) / width; width = ACCSIZE - 5; height = (int) (height * ratio); } else { if (getHeight() > 150) { ratio = (double) (ACCSIZE - 5) / height; height = ACCSIZE - 5; width = (int) (width * ratio); } else { ratio = (double) getHeight() / height; height = getHeight(); width = (int) (width * ratio); } } image = image.getScaledInstance(width, height, Image.SCALE_DEFAULT); }
public void paint(Graphics gg) { int faceSize = Math.min(getWidth() - 4, getHeight() - 4); if (face == null) face = new PADFaceMapped( Math.max(2, (getWidth() - faceSize) / 2), Math.max(2, (getHeight() - faceSize) / 2), faceSize); if (buffer == null) { im = this.createImage(getWidth(), getHeight()); buffer = im.getGraphics(); } super.paint(buffer); buffer.setColor(new Color(255, 255, 255, 0)); buffer.fillRect(0, 0, im.getWidth(null), im.getHeight(null)); face.setDimensions( Math.max(2, (getWidth() - faceSize) / 2), Math.max(2, (getHeight() - faceSize) / 2), faceSize); face.paint(buffer); // draw buffer to screen gg.drawImage(im, 0, 0, null, null); }
private void setup() throws IOException, UnsupportedAudioFileException, LineUnavailableException { startSounds(); tracker = new MediaTracker(this); fishImages[0] = ImageIO.read(getClass().getResourceAsStream("fish1.gif")); tracker.addImage(fishImages[0], 0); fishImages[1] = ImageIO.read(getClass().getResourceAsStream("fish2.gif")); tracker.addImage(fishImages[1], 0); aquariumImage = ImageIO.read(getClass().getResourceAsStream("tank.png")); tracker.addImage(aquariumImage, 0); try { tracker.waitForID(0); } catch (Exception ex) { System.out.println(ex.getMessage()); } setSize(aquariumImage.getWidth(this), aquariumImage.getHeight(this)); setResizable(true); setVisible(true); memoryImage = createImage(getSize().width, getSize().height); memoryGraphics = memoryImage.getGraphics(); }
/** * 打印文字水印图片 * * @param pressText --文字 * @param targetImg -- 目标图片 * @param fontName -- 字体名 * @param fontStyle -- 字体样式 * @param color -- 字体颜色 * @param fontSize -- 字体大小 * @param x -- 偏移量 * @param y */ public static void pressText( String pressText, String targetImg, String fontName, int fontStyle, int color, int fontSize, int x, int y) { try { File _file = new File(targetImg); Image src = ImageIO.read(_file); int wideth = src.getWidth(null); int height = src.getHeight(null); BufferedImage image = new BufferedImage(wideth, height, BufferedImage.TYPE_INT_RGB); Graphics g = image.createGraphics(); g.drawImage(src, 0, 0, wideth, height, null); // String s="www.qhd.com.cn"; g.setColor(Color.RED); g.setFont(new Font(fontName, fontStyle, fontSize)); g.drawString(pressText, wideth - fontSize - x, height - fontSize / 2 - y); g.dispose(); FileOutputStream out = new FileOutputStream(targetImg); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(image); out.close(); } catch (Exception e) { System.out.println(e); } }