List of usage examples for java.awt Image getHeight
public abstract int getHeight(ImageObserver observer);
From source file:com.jflyfox.modules.filemanager.FileManager.java
private Dimension getImageSize(String path) { Dimension imgData = new Dimension(); Image img = new ImageIcon(path).getImage(); imgData.height = img.getHeight(null); imgData.width = img.getWidth(null);/*from w w w . ja v a 2s . c om*/ return imgData; }
From source file:edu.ku.brc.ui.ImageDisplay.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); boolean doScale = true; int w = getWidth(); int h = getHeight(); Image dspImg = image; boolean doDisplayImage = (image != null && (!isNoAttachment && status == kImageOK)) || isLoading; if (isLoading) { doDisplayImage = true;// w w w .ja v a2 s. co m dspImg = IconManager.getImage("Loading").getImage(); } if (doDisplayImage && dspImg != null) { int imgW = dspImg.getWidth(null); int imgH = dspImg.getHeight(null); if (doScale && (imgW > w || imgH > h)) { double scaleW = 1.0; double scaleH = 1.0; double scale = 1.0; if (imgW > w) { scaleW = (double) w / imgW; } if (imgH > h) { scaleH = (double) h / imgH; } scale = Math.min(scaleW, scaleH); imgW = (int) (imgW * scale); imgH = (int) (imgH * scale); } int x = 0; int y = 0; if (imgW < w) { x = (w - imgW) / 2; } if (imgH < h) { y = (h - imgH) / 2; } g.drawImage(dspImg, x, y, imgW, imgH, null); } else if (doShowText) { GraphicsUtils.turnOnAntialiasedDrawing(g); String[] label = this.isNoAttachment ? (isFullImage ? noAttachmentStr : noThumnailStr) : loadingAttachmentStr; FontMetrics fm = g.getFontMetrics(); int spacing = 2; int yOffset = (h - (fm.getHeight() + spacing) * label.length) / 2; if (yOffset < 0) yOffset = 0; int y = yOffset + fm.getHeight(); for (String str : label) { g.drawString(str, (w - fm.stringWidth(str)) / 2, y); y += fm.getHeight() + 2; } } }
From source file:msi.gama.outputs.layers.charts.StandardXYItemRenderer.java
/** * 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// w w w .j a va 2s . com * 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(final Plot plot, final int series, final int item, final double x, final double y, final Image image) { final int height = image.getHeight(null); final int width = image.getWidth(null); return new Point(width / 2, height / 2); }
From source file:com.tur0kk.facebook.FacebookClient.java
public String publishPicture(String msg, Image image, String placeId) throws IOException { OAuthRequest request = new OAuthRequest(Verb.POST, "https://graph.facebook.com/v2.2/me/photos"); // request node request.addHeader("Authorization", "Bearer " + accesTokenString); // authentificate // check input to avoid error responses if (msg != null && image != null) { // facebook requires multipart post structure MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody("message", msg); // description if (placeId != null && !"".equals(placeId)) { builder.addTextBody("place", placeId); // add link to FabLab site if property is set in preferences }//from w w w . j av a2 s . co m // convert image to bytearray and append to multipart BufferedImage bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D bGr = bimage.createGraphics(); bGr.drawImage(image, 0, 0, null); bGr.dispose(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(bimage, "png", baos); builder.addBinaryBody(msg, baos.toByteArray(), ContentType.MULTIPART_FORM_DATA, "test.png"); // generate multipart byte stream and add to payload of post package HttpEntity multipart = builder.build(); ByteArrayOutputStream multipartOutStream = new ByteArrayOutputStream( (int) multipart.getContentLength()); multipart.writeTo(multipartOutStream); request.addPayload(multipartOutStream.toByteArray()); // set header of post package Header contentType = multipart.getContentType(); request.addHeader(contentType.getName(), contentType.getValue()); // send and response answer Response response = request.send(); return response.getBody(); } else { throw new RuntimeException("message and image needed"); } }
From source file:de.mpg.imeji.logic.storage.util.ImageUtils.java
/** * Scale a {@link BufferedImage} to new size. Is faster than the basic {@link ImageUtils}.scaleImage method, has the * same quality. If it is a thumbnail, cut the images to fit into the raster * /*from www . ja v a 2s . co m*/ * @param image original image * @param size the size to be resized to * @param resolution the type of the image. Might be thumb or web * @return the resized images * @throws Exception */ public static BufferedImage scaleImageFast(BufferedImage image, int size, FileResolution resolution) throws Exception { int width = image.getWidth(null); int height = image.getHeight(null); BufferedImage newImg = null; Image rescaledImage; if (width > height) { if (FileResolution.THUMBNAIL.equals(resolution)) { newImg = new BufferedImage(height, height, BufferedImage.TYPE_INT_RGB); Graphics g1 = newImg.createGraphics(); g1.drawImage(image, (height - width) / 2, 0, null); if (height > size) rescaledImage = getScaledInstance(newImg, size, size, RenderingHints.VALUE_INTERPOLATION_BILINEAR, RESCALE_HIGH_QUALITY); else rescaledImage = newImg; } else rescaledImage = getScaledInstance(image, size, height * size / width, RenderingHints.VALUE_INTERPOLATION_BILINEAR, RESCALE_HIGH_QUALITY); } else { if (FileResolution.THUMBNAIL.equals(resolution)) { newImg = new BufferedImage(width, width, BufferedImage.TYPE_INT_RGB); Graphics g1 = newImg.createGraphics(); g1.drawImage(image, 0, (width - height) / 2, null); if (width > size) rescaledImage = getScaledInstance(newImg, size, size, RenderingHints.VALUE_INTERPOLATION_BILINEAR, RESCALE_HIGH_QUALITY); else rescaledImage = newImg; } else rescaledImage = getScaledInstance(image, width * size / height, size, RenderingHints.VALUE_INTERPOLATION_BILINEAR, RESCALE_HIGH_QUALITY); } BufferedImage rescaledBufferedImage = new BufferedImage(rescaledImage.getWidth(null), rescaledImage.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics g2 = rescaledBufferedImage.getGraphics(); g2.drawImage(rescaledImage, 0, 0, null); return rescaledBufferedImage; }
From source file:de.tuttas.restful.SchuelerManager.java
/** * Bild eines Schlers hochladen//from w w w . j a va 2 s . c om * @param idschueler ID des Schlers (wird zum Filenamen) * @param uploadedInputStream InputStream * @param fileDetail Original File Name etc. * @return Ergebnisobjekt mit Meldungen */ @POST @Path("/bild/{idschueler}") @Consumes(MediaType.MULTIPART_FORM_DATA) public ResultObject uploadFile(@PathParam("idschueler") int idschueler, @FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) { ResultObject r = new ResultObject(); String fileLocation = Config.getInstance().IMAGE_FILE_PATH + idschueler + ".jpg"; Log.d("upload File for " + idschueler); try { byte[] imageBytes = IOUtils.toByteArray(uploadedInputStream); int i = uploadedInputStream.read(imageBytes); Log.d("habe " + i + " bytes gelesen!"); InputStream myInputStream = new ByteArrayInputStream(imageBytes); Image image = ImageIO.read(myInputStream); Log.d("Image gelesen =" + image); InputStream myExifInputStream = new ByteArrayInputStream(imageBytes); int orientation = ImageUtil.getImageOrientation(myExifInputStream); BufferedImage bImage = ImageUtil.toBufferedImage(image); Log.d("Image hat w=" + bImage.getWidth() + " h=" + bImage.getHeight()); bImage = ImageUtil.transformImage(bImage, ImageUtil.getExifTransformation(orientation, image.getWidth(null), image.getHeight(null))); Log.d("Image hat nach Transformation w=" + bImage.getWidth() + " h=" + bImage.getHeight()); if (image != null) { int originalWidth = bImage.getWidth(); int originalHeight = bImage.getHeight(); int newWidth = 200; int newHeight = Math.round(newWidth * ((float) originalHeight / originalWidth)); BufferedImage bi = this.createResizedCopy(bImage, newWidth, newHeight, true); ImageIO.write(bi, "jpg", new File(Config.getInstance().IMAGE_FILE_PATH + idschueler + ".jpg")); r.setMsg("Bild erfolgreich hochgeladen!"); r.setSuccess(true); } else { r.setMsg("Fehler beim Hochladen des Bildes!"); r.setSuccess(false); } } catch (IOException e) { Log.d("Error"); r.setMsg(e.getMessage()); r.setSuccess(false); } catch (MetadataException ex) { Logger.getLogger(SchuelerManager.class.getName()).log(Level.SEVERE, null, ex); } catch (ImageProcessingException ex) { Logger.getLogger(SchuelerManager.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(SchuelerManager.class.getName()).log(Level.SEVERE, null, ex); } return r; }
From source file:org.sbs.util.ImageCompress.java
public String compressPic() { try {//from www .j ava 2s .c om // ? file = new File(inputDir + inputFileName); if (!file.exists()) { return ""; } Image img = ImageIO.read(file); // ?? if (img.getWidth(null) == -1) { System.out.println(" can't read,retry!" + "<BR>"); return "no"; } else { int newWidth; int newHeight; // ? if (this.proportion == true) { // ? double rate1 = ((double) img.getWidth(null)) / (double) outputWidth + 0.1; double rate2 = ((double) img.getHeight(null)) / (double) outputHeight + 0.1; // ? double rate = rate1 > rate2 ? rate1 : rate2; newWidth = (int) (((double) img.getWidth(null)) / rate); newHeight = (int) (((double) img.getHeight(null)) / rate); } else { newWidth = outputWidth; // newHeight = outputHeight; // } BufferedImage tag = new BufferedImage((int) newWidth, (int) newHeight, BufferedImage.TYPE_INT_RGB); /* * Image.SCALE_SMOOTH ? ?? */ tag.getGraphics().drawImage(img.getScaledInstance(newWidth, newHeight, Image.SCALE_SMOOTH), 0, 0, null); FileOutputStream out = new FileOutputStream(outputDir + outputFileName); // JPEGImageEncoder?? JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } } catch (IOException ex) { ex.printStackTrace(); } return "ok"; }
From source file:com.frochr123.fabqr.gui.FabQRUploadDialog.java
private void btnPhotoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPhotoActionPerformed // Get latest full camera image (without resize) latestFullCameraImage = null;/*from w w w . j a v a2 s .com*/ if (cameraThread != null) { Image image = cameraThread.getLatestRawImage(); // Convert image to bufferedimage if (image != null) { BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = bufferedImage.createGraphics(); graphics.drawImage(image, 0, 0, null); graphics.dispose(); latestFullCameraImage = bufferedImage; } } // Stop camera, freeze image closeCamera(); // Set correct UI button states btnPhoto.setEnabled(false); btnPhotoRedo.setEnabled(true); btnPublish.setEnabled(true); }
From source file:com.celements.photo.image.GenerateThumbnail.java
public BufferedImage createThumbnail(BufferedImage img, OutputStream out, ImageDimensions imgSize, String watermark, String copyright, String type, Color defaultBg) { Image thumbImg = img; // Only generates a thumbnail if the image is larger than the desired thumbnail. mLogger.debug("img: " + img + " - imgSize: " + imgSize); if ((img.getWidth() > (int) imgSize.getWidth()) || (img.getHeight() > (int) imgSize.getHeight())) { // The "-1" is used to resize maintaining the aspect ratio. thumbImg = img.getScaledInstance((int) imgSize.getWidth(), -1, Image.SCALE_SMOOTH); }//from www . j a va 2 s . co m mLogger.debug("width ziel: " + imgSize.getWidth() + ", height ziel: " + imgSize.getHeight() + "; width: " + thumbImg.getWidth(null) + ", height: " + thumbImg.getHeight(null)); BufferedImage buffThumb = convertImageToBufferedImage(thumbImg, watermark, copyright, defaultBg); encodeImage(out, buffThumb, img, type); return buffThumb; }
From source file:org.trade.ui.chart.renderer.MACDItemRenderer.java
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, double x0, double y0, double x1, double y1, int lastItem, int series, int item, CrosshairState crosshairState, int pass, int numX, double minX, double maxX, Paint color, XYDataset dataset) { boolean itemVisible = getItemVisible(series, item); // setup for collecting optional entity info... Shape entityArea = null;/*w w w .jav a 2s.c om*/ EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } PlotOrientation orientation = plot.getOrientation(); Paint paint = getItemPaint(series, item); paint = color; Stroke seriesStroke = getItemStroke(series, item); g2.setPaint(paint); g2.setStroke(seriesStroke); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getPlotLines()) { if (this.drawSeriesLineAsPath) { State s = (State) state; if (s.getSeriesIndex() != series) { // we are starting a new series path s.seriesPath.reset(); s.lastPointGood = false; s.setSeriesIndex(series); } // update path to reflect latest point if (itemVisible && !Double.isNaN(transX1) && !Double.isNaN(transY1)) { float x = (float) transX1; float y = (float) transY1; if (orientation == PlotOrientation.HORIZONTAL) { x = (float) transY1; y = (float) transX1; } if (s.isLastPointGood()) { // TODO: check threshold s.seriesPath.lineTo(x, y); } else { s.seriesPath.moveTo(x, y); } s.setLastPointGood(true); } else { s.setLastPointGood(false); } if (item == lastItem) { if (s.seriesIndex == series) { // draw path g2.setStroke(lookupSeriesStroke(series)); g2.setPaint(lookupSeriesPaint(series)); g2.draw(s.seriesPath); } } } else if (item != 0 && itemVisible) { // get the previous data point... if (!Double.isNaN(x0) && !Double.isNaN(y0)) { boolean drawLine = true; if (getPlotDiscontinuous()) { // only draw a line if the gap between the current and // previous data point is within the threshold if (this.gapThresholdType == UnitType.ABSOLUTE) { drawLine = Math.abs(x1 - x0) <= this.gapThreshold; } else { drawLine = Math.abs(x1 - x0) <= ((maxX - minX) / numX * getGapThreshold()); } } if (drawLine) { double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } if (state.workingLine.intersects(dataArea)) { g2.draw(state.workingLine); } } } } } // we needed to get this far even for invisible items, to ensure that // seriesPath updates happened, but now there is nothing more we need // to do for non-visible items... if (!itemVisible) { return; } if (getBaseShapesVisible()) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { g2.fill(shape); } else { g2.draw(shape); } } entityArea = shape; } if (getPlotImages()) { Image image = getImage(plot, series, item, transX1, transY1); if (image != null) { Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image); g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null); entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(), image.getWidth(null), image.getHeight(null)); } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } // draw the item label if there is one... if (isItemLabelVisible(series, item)) { drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation); // add an entity for the item... if (entities != null && isPointInRect(dataArea, xx, yy)) { addEntity(entities, entityArea, dataset, series, item, xx, yy); } }