List of usage examples for java.awt Image getHeight
public abstract int getHeight(ImageObserver observer);
From source file:com.pureinfo.tgirls.servlet.TestServlet.java
private BufferedImage getImg(File _temp, float _i) throws IOException { BufferedImage output;/*from w w w .j ava 2 s . c o m*/ Image img = ImageIO.read(_temp); int width = img.getWidth(null); int height = img.getHeight(null); Float f = width * _i; width = f.intValue(); f = height * _i; height = f.intValue(); output = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = output.getGraphics(); g.drawImage(img, 0, 0, width, height, null); g.dispose(); return output; }
From source file:ImageOps.java
public void init() { setBackground(Color.white);//from ww w .java 2s . c om bi = new BufferedImage[4]; String s[] = { "bld.jpg", "bld.jpg", "boat.gif", "boat.gif" }; for (int i = 0; i < bi.length; i++) { Image img = getImage(getURL("images/" + s[i])); try { MediaTracker tracker = new MediaTracker(this); tracker.addImage(img, 0); tracker.waitForID(0); } catch (Exception e) { } int iw = img.getWidth(this); int ih = img.getHeight(this); bi[i] = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB); Graphics2D big = bi[i].createGraphics(); big.drawImage(img, 0, 0, this); } }
From source file:net.sradonia.gui.SplashScreen.java
/** * @param image//from ww w. java 2 s .c o m * the new splash screen image */ public void setImage(Image image) { if (image == null) throw new IllegalArgumentException("null image"); this.image = image; window.setSize(image.getWidth(window), image.getHeight(window)); window.setLocationRelativeTo(null); log.debug("image set. dimensions: " + window.getBounds()); }
From source file:com.chinarewards.gwt.license.util.FileUploadServlet.java
/** * @param imgsrc//from ww w . ja v a 2 s . c o m * * @param imgdist * ? * @param widthdist * * @param heightdist * * @param int benchmark :0,12 * */ public void reduceImg(InputStream inputStream, String outputFilePath, String imgdist, int widthdist, int heightdist, int benchmark) { try { // File srcfile = new File(srcFile); // if (!srcfile.exists()) { // return; // } boolean flag = true; Image srcImage = javax.imageio.ImageIO.read(inputStream); if (srcImage != null) { int width = srcImage.getWidth(null); int height = srcImage.getHeight(null); if (width <= widthdist && height <= heightdist) {// ?? BufferedOutputStream outputStream = new BufferedOutputStream( new FileOutputStream(new File(outputFilePath))); Streams.copy(inputStream, outputStream, true); flag = false; } if (flag) { // float wh = (float) width / (float) height; if (benchmark == 0) { if (wh > 1) { float tmp_heigth = (float) widthdist / wh; BufferedImage tag = new BufferedImage(widthdist, (int) tmp_heigth, BufferedImage.TYPE_INT_RGB); tag.getGraphics().drawImage(srcImage, 0, 0, widthdist, (int) tmp_heigth, null); FileOutputStream out = new FileOutputStream(imgdist); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } else { float tmp_width = (float) heightdist * wh; BufferedImage tag = new BufferedImage((int) tmp_width, heightdist, BufferedImage.TYPE_INT_RGB); tag.getGraphics().drawImage(srcImage, 0, 0, (int) tmp_width, heightdist, null); FileOutputStream out = new FileOutputStream(imgdist); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } } if (benchmark == 1) { float tmp_heigth = (float) widthdist / wh; BufferedImage tag = new BufferedImage(widthdist, (int) tmp_heigth, BufferedImage.TYPE_INT_RGB); tag.getGraphics().drawImage(srcImage, 0, 0, widthdist, (int) tmp_heigth, null); FileOutputStream out = new FileOutputStream(imgdist); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } if (benchmark == 2) { float tmp_width = (float) heightdist * wh; BufferedImage tag = new BufferedImage((int) tmp_width, heightdist, BufferedImage.TYPE_INT_RGB); tag.getGraphics().drawImage(srcImage, 0, 0, (int) tmp_width, heightdist, null); FileOutputStream out = new FileOutputStream(imgdist); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } } } } catch (IOException ex) { ex.printStackTrace(); } }
From source file:org.mili.core.graphics.GraphicsUtilTest.java
@Test public void test_Image_readImage_File() { // negativ//from www .j a v a 2 s.c om try { GraphicsUtil.readImage(null); fail("here was null given, but method works !"); } catch (IllegalArgumentException e) { assertTrue(true); } catch (IOException e) { fail(); } try { GraphicsUtil.readImage(new File(this.dir, "/xyz/test.jpg")); fail("file not exists here, but method works !"); } catch (IOException e) { assertTrue(true); } // positiv try { Image i = GraphicsUtil.readImage(new File(this.dir, "test.jpg")); assertTrue(i != null); assertEquals(100, i.getHeight(null)); assertEquals(100, i.getWidth(null)); } catch (IOException e) { e.printStackTrace(); fail(); } return; }
From source file:com.pureinfo.tgirls.servlet.TestServlet.java
private int[] getimgSize(FileItem _fileItem) { try {//w w w . j av a2 s . co m logger.debug("to calc img width and height."); Image image = ImageIO.read(_fileItem.getInputStream()); int[] s = new int[2]; s[0] = image.getWidth(null); s[1] = image.getHeight(null); logger.debug("width[" + s[0] + "] height[" + s[1] + "]"); return s; } catch (Exception e) { logger.error("error when calc image size.", e); return new int[] { -1, -1 }; } }
From source file:TexturedPanel.java
/** * Creates a new TexturePaint using the provided image. *//* w ww . j ava 2 s . c o m*/ private void setupImagePainter(Image texture) { if (texture == null) { ourPainter = null; return; } int w = texture.getWidth(this); int h = texture.getHeight(this); if (w <= 0 || h <= 0) { ourPainter = null; return; } BufferedImage buff = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); Graphics2D g2 = buff.createGraphics(); g2.drawImage(texture, 0, 0, this); ourPainter = new TexturePaint(buff, new Rectangle(0, 0, w, h)); g2.dispose(); }
From source file:org.openstreetmap.josm.tools.ImageProvider.java
/** * Creates a rotated version of the input image. * * @param c The component to get properties useful for painting, e.g. the foreground or * background color.//from w ww . j a v a 2 s . c o m * @param img the image to be rotated. * @param rotatedAngle the rotated angle, in degree, clockwise. It could be any double but we * will mod it with 360 before using it. * * @return the image after rotating. */ public static Image createRotatedImage(Component c, Image img, double rotatedAngle) { // convert rotatedAngle to a value from 0 to 360 double originalAngle = rotatedAngle % 360; if (rotatedAngle != 0 && originalAngle == 0) { originalAngle = 360.0; } // convert originalAngle to a value from 0 to 90 double angle = originalAngle % 90; if (originalAngle != 0.0 && angle == 0.0) { angle = 90.0; } double radian = Math.toRadians(angle); new ImageIcon(img); // load completely int iw = img.getWidth(null); int ih = img.getHeight(null); int w; int h; if ((originalAngle >= 0 && originalAngle <= 90) || (originalAngle > 180 && originalAngle <= 270)) { w = (int) (iw * Math.sin(DEGREE_90 - radian) + ih * Math.sin(radian)); h = (int) (iw * Math.sin(radian) + ih * Math.sin(DEGREE_90 - radian)); } else { w = (int) (ih * Math.sin(DEGREE_90 - radian) + iw * Math.sin(radian)); h = (int) (ih * Math.sin(radian) + iw * Math.sin(DEGREE_90 - radian)); } BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics g = image.getGraphics(); Graphics2D g2d = (Graphics2D) g.create(); // calculate the center of the icon. int cx = iw / 2; int cy = ih / 2; // move the graphics center point to the center of the icon. g2d.translate(w / 2, h / 2); // rotate the graphics about the center point of the icon g2d.rotate(Math.toRadians(originalAngle)); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.drawImage(img, -cx, -cy, c); g2d.dispose(); new ImageIcon(image); // load completely return image; }
From source file:ucar.unidata.idv.flythrough.ChartDecorator.java
/** * _more_/* ww w . j ava 2 s . c o m*/ * * @param g2 _more_ * @param comp _more_ * * @return _more_ */ public boolean paintDashboard(Graphics2D g2, JComponent comp) { try { List<SampleInfo> infos = new ArrayList<SampleInfo>(sampleInfos); if (infos.size() == 0) { return false; } Rectangle b = comp.getBounds(); JFrame dummyFrame = new JFrame(""); XYSeriesCollection dataset = new XYSeriesCollection(); JFreeChart chart = Flythrough.createChart(dataset); XYPlot xyPlot = (XYPlot) chart.getPlot(); int chartHeight = b.height - flythrough.getDashboardImage().getHeight(null); chartHeight = Math.max(chartHeight, 50); int chartWidth = Math.min(chartHeight * 4, b.width); int dx = b.width / 2 - chartWidth / 2; int dy = 0; Image lastImage = lastChartImage; if ((lastImage != null) && (lastImage.getWidth(null) == chartWidth) && (lastImage.getHeight(null) == chartHeight)) { g2.translate(dx, dy); g2.drawImage(lastImage, 0, 0, null); g2.translate(-dx, -dy); return false; } for (int i = 0; i < infos.size(); i++) { SampleInfo info = infos.get(i); ValueAxis rangeAxis = new NumberAxis(info.getName()); if (info.getRange() != null) { rangeAxis .setRange(new org.jfree.data.Range(info.getRange().getMin(), info.getRange().getMax())); } dataset = new XYSeriesCollection(); dataset.addSeries(info.getSeries()); xyPlot.setRangeAxis(i, rangeAxis, false); xyPlot.setDataset(i, dataset); xyPlot.mapDatasetToRangeAxis(i, i); final Color color = COLORS[i % COLORS.length]; XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false) { public Paint xgetItemPaint(final int row, final int column) { return color; } }; renderer.setSeriesPaint(0, color); xyPlot.setRenderer(i, renderer); } ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new Dimension(chartWidth, chartHeight)); dummyFrame.setContentPane(chartPanel); dummyFrame.pack(); Image image = ImageUtils.getImage(chartPanel); lastChartImage = image; g2.translate(dx, dy); g2.drawImage(image, 0, 0, null); g2.translate(-dx, -dy); } catch (Exception exc) { logException("Painting chart", exc); } return false; }
From source file:org.shredzone.cilla.admin.AbstractImageBean.java
/** * Scales a {@link BufferedImage} to the given size, keeping the aspect ratio. If the * image is smaller than the resulting size, it will be magnified. * * @param image//from w w w .j a v a 2 s. c om * {@link BufferedImage} to scale * @param width * Maximum result width * @param height * Maximum result height * @return {@link BufferedImage} with the scaled image */ private BufferedImage scale(BufferedImage image, int width, int height) { ImageObserver observer = null; Image scaled = null; if (image.getWidth() > image.getHeight()) { scaled = image.getScaledInstance(width, -1, Image.SCALE_SMOOTH); } else { scaled = image.getScaledInstance(-1, height, Image.SCALE_SMOOTH); } BufferedImage result = new BufferedImage(scaled.getWidth(observer), scaled.getHeight(observer), BufferedImage.TYPE_INT_RGB); result.createGraphics().drawImage(scaled, 0, 0, observer); return result; }