List of usage examples for java.awt.image BufferedImage getHeight
public int getHeight()
From source file:doge.photo.DogePhotoManipulator.java
private void renderOverlay(BufferedImage image, Graphics2D graphics) { getRandomText().render(image, graphics); int y = image.getHeight() - this.dogeLogo.getHeight(); graphics.drawImage(this.dogeLogo, 0, y, null); }
From source file:com.trailmagic.image.util.ReplaceImageManifestation.java
public void replaceManifestations(final String ownerName, final String rollName, final String importDir) { hibernateTemplate.execute(new HibernateCallback() { public Object doInHibernate(Session session) { try { User owner = userRepository.getByScreenName(ownerName); ImageGroup roll = imageGroupRepository.getRollByOwnerAndName(owner, rollName); s_log.info("Processing roll: " + roll.getName()); for (ImageFrame frame : roll.getFrames()) { Image image = frame.getImage(); for (ImageManifestation mf : image.getManifestations()) { String filename = importDir + File.separator + mf.getName(); File srcFile = new File(filename); s_log.info("Importing " + srcFile.getPath()); if (srcFile.length() > Integer.MAX_VALUE) { s_log.info("File is too big...skipping " + srcFile.getPath()); throw new RuntimeException("File too big"); }//from w w w .j av a2 s. c o m // first read the file to get the size FileInputStream fis = new FileInputStream(srcFile); BufferedImage bi = ImageIO.read(fis); mf.setHeight(bi.getHeight()); mf.setWidth(bi.getWidth()); s_log.info("New size is " + mf.getHeight() + "x" + mf.getWidth()); session.saveOrUpdate(mf); fis.close(); fis = new FileInputStream(srcFile); HeavyImageManifestation heavyMf = imfFactory.getHeavyById(mf.getId()); heavyMf.setData(Hibernate.createBlob(fis)); session.saveOrUpdate(heavyMf); // open the file again to get the size :( s_log.info("ImageManifestation saved: " + heavyMf.getName() + " (" + heavyMf.getId() + ")" + "...flushing session and evicting " + "manifestation."); synchronized (session) { session.flush(); session.evict(heavyMf); } // looks like fis has to be open for the flush fis.close(); } } } catch (Exception e) { s_log.error("Error replacing manifestations ", e); } return null; } }); }
From source file:org.nekorp.workflow.desktop.servicio.imp.ImageServiceImp.java
@Override public BufferedImage resizeToStandarSize(BufferedImage image) { Dimension boundary = new Dimension(imageWidth, imageHeight); Dimension originalDimension = new Dimension(image.getWidth(), image.getHeight()); Dimension newDimension = ImageServiceImp.getScaledDimension(originalDimension, boundary); ResampleOp resampleOp = new ResampleOp((int) newDimension.getWidth(), (int) newDimension.getHeight()); resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal); BufferedImage rescaled = resampleOp.filter(image, null); return rescaled; }
From source file:org.nekorp.workflow.desktop.servicio.imp.ImageServiceImp.java
@Override public BufferedImage getThumbnail(BufferedImage image) { Dimension boundary = new Dimension(thumbWidth, thumbHeight); Dimension originalDimension = new Dimension(image.getWidth(), image.getHeight()); Dimension newDimension = ImageServiceImp.getScaledDimension(originalDimension, boundary); ResampleOp resampleOp = new ResampleOp((int) newDimension.getWidth(), (int) newDimension.getHeight()); resampleOp.setUnsharpenMask(AdvancedResizeOp.UnsharpenMask.Normal); BufferedImage rescaled = resampleOp.filter(image, null); return rescaled; }
From source file:com.buddycloud.mediaserver.MediaServerTest.java
protected Media buildMedia(String mediaId, String filePath) throws Exception { File file = new File(filePath); String fileName = file.getName(); String extension = fileName.substring(fileName.indexOf(".") + 1); Media media = new Media(); media.setId(mediaId);//from www.j av a2 s . c om media.setFileName(fileName); media.setEntityId(BASE_CHANNEL); media.setAuthor(BASE_USER); media.setDescription("A description"); media.setTitle("A title"); media.setFileSize(file.length()); media.setShaChecksum(getFileShaChecksum(file)); media.setFileExtension(extension); media.setMimeType(MimeTypeMapping.lookupMimeType(extension)); if (ImageUtils.isImage(extension)) { BufferedImage img = ImageIO.read(file); media.setHeight(img.getHeight()); media.setWidth(img.getWidth()); } else if (VideoUtils.isVideo(extension)) { VideoUtils videoUtils = new VideoUtils(file); media.setLength(videoUtils.getVideoLength()); media.setHeight(videoUtils.getVideoHeight()); media.setWidth(videoUtils.getVideoWidth()); } else if (AudioUtils.isAudio(extension)) { media.setLength(AudioUtils.getAudioLength(file)); } return media; }
From source file:de.ep3.ftpc.view.designer.UIDesigner.java
/** * Loads an icon image from the resources directory provided. * * The icon will be recolored according to the UI default color * (with respect to its alpha values).//from w w w . ja v a 2 s. c o m * * @param dirName The directory name under the resource/drawable directory. * @param fileName The file name under the directory name provided before. * @return The icom ready to be displayed within the GUI. */ public Icon getDefaultIcon(String dirName, String fileName) { BufferedImage image = getDefaultImage(dirName, fileName); /* Change icon color according to UI color */ int imageHeight = image.getHeight(); int imageWidth = image.getWidth(); int defaultRGBA = getDefaultBorderColor().getRGB(); int defaultRGB = defaultRGBA & 0x00FFFFFF; for (int y = 0; y < imageHeight; y++) { for (int x = 0; x < imageWidth; x++) { int imageRGBA = image.getRGB(x, y); int imageA = imageRGBA & 0xFF000000; int newRGBA = defaultRGB | imageA; // I'm quite proud of this little bitwise color calculation ^-^ image.setRGB(x, y, newRGBA); } } return new ImageIcon(image); }
From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.ImageUploadThumbnailer.java
private CropRectangle limitCropRectangleToImageBounds(BufferedImage image, CropRectangle crop) { int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); // Ensure that x and y are at least zero, but not big enough to push the // crop rectangle out of the image. int greatestX = imageWidth - MINIMUM_CROP_SIZE; int greatestY = imageHeight - MINIMUM_CROP_SIZE; int x = Math.max(0, Math.min(greatestX, Math.abs(crop.x))); int y = Math.max(0, Math.min(greatestY, Math.abs(crop.y))); // Ensure that width and height are at least as big as the minimum, but // no so big as to extend beyond the image. int greatestW = imageWidth - x; int greatestH = imageHeight - y; int w = Math.max(MINIMUM_CROP_SIZE, Math.min(greatestW, crop.width)); int h = Math.max(MINIMUM_CROP_SIZE, Math.min(greatestH, crop.height)); return new CropRectangle(x, y, h, w); }
From source file:DBScan.java
private double minDistance(int x, int y, BufferedImage img1, BufferedImage img2) { if (!(x < img1.getWidth() && y < img1.getHeight())) return 0; int colour = img1.getRGB(x, y); // if (colour != Image.BLACK) // return 0; if (x < img2.getWidth() && y < img2.getHeight() && img2.getRGB(x, y) == colour) return 0; int distance = 6; final int RANGE = 1; for (int x1 = x - RANGE; x1 <= x + RANGE; x1++) { if (distance == 1) break; if (x1 < 0 || x1 >= img2.getWidth()) continue; for (int y1 = y - (x1 - x); y1 <= y + RANGE; y1++) { if (y1 >= 0 && y1 < img2.getHeight() && img2.getRGB(x1, y1) == colour) { distance = Math.min(distance, Math.min(Math.abs(x - x1), Math.abs(y - y1))); }//from ww w . j av a 2s . c om } } return (distance * distance) / 2; }
From source file:net.rptools.maptool.util.PersistenceUtil.java
public static void saveToken(Token token, File file, boolean doWait) throws IOException { // Thumbnail/*from w w w . java 2 s .c om*/ BufferedImage image = null; if (doWait) image = ImageManager.getImageAndWait(token.getImageAssetId()); else image = ImageManager.getImage(token.getImageAssetId()); Dimension sz = new Dimension(image.getWidth(), image.getHeight()); SwingUtil.constrainTo(sz, 50); BufferedImage thumb = new BufferedImage(sz.width, sz.height, BufferedImage.TRANSLUCENT); Graphics2D g = thumb.createGraphics(); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.drawImage(image, 0, 0, sz.width, sz.height, null); g.dispose(); PackedFile pakFile = null; try { pakFile = new PackedFile(file); saveAssets(token.getAllImageAssets(), pakFile); pakFile.putFile(Token.FILE_THUMBNAIL, ImageUtil.imageToBytes(thumb, "png")); pakFile.setContent(token); pakFile.setProperty(PROP_VERSION, MapTool.getVersion()); pakFile.save(); } finally { if (pakFile != null) pakFile.close(); } }
From source file:com.neophob.sematrix.core.generator.Image.java
/** * load a new file.//from w w w . j a v a 2 s . c o m * * @param filename the filename */ public synchronized void loadFile(String filename) { if (StringUtils.isBlank(filename)) { LOG.log(Level.INFO, "Empty filename provided, call ignored!"); return; } //only load if needed if (StringUtils.equals(filename, this.filename)) { LOG.log(Level.INFO, "new filename does not differ from old: " + filename); return; } try { String fileToLoad = fileUtils.getImageDir() + File.separator + filename; LOG.log(Level.INFO, "load image " + fileToLoad); BufferedImage img = ImageIO.read(new File(fileToLoad)); if (img == null || img.getHeight() < 2) { LOG.log(Level.WARNING, "Invalid image, image height is < 2!"); return; } //convert to RGB colorspace int w = img.getWidth(); int h = img.getHeight(); int[] dataBuffInt = img.getRGB(0, 0, w, h, null, 0, w); LOG.log(Level.INFO, "resize to img " + filename + " " + internalBufferXSize + ", " + internalBufferYSize + " using " + resize.getName()); this.internalBuffer = resize.getBuffer(dataBuffInt, internalBufferXSize, internalBufferYSize, w, h); this.filename = filename; short r, g, b; int rgbColor; //greyscale it for (int i = 0; i < internalBuffer.length; i++) { rgbColor = internalBuffer[i]; r = (short) ((rgbColor >> 16) & 255); g = (short) ((rgbColor >> 8) & 255); b = (short) (rgbColor & 255); int val = (int) (r * 0.3f + g * 0.59f + b * 0.11f); internalBuffer[i] = val; } } catch (Exception e) { LOG.log(Level.WARNING, "Failed to load image " + filename, e); } }