List of usage examples for java.awt.image BufferedImage getHeight
public int getHeight()
From source file:io.bci.BitcoinSTLGenerator.java
private static void drawSTL(File qrFile, String filename) { int height = 0; int width = 0; float PLATFORM_RATIO = 2.3f; float PLATFORM_HEIGHT = 1.0f; boolean printPlatform = false; boolean printQRbottom = true; STLDrawer drawer = null;//from ww w . j ava 2s . c om float[] pofloat1 = new float[3]; float[] pofloat2 = new float[3]; float[] pofloat3 = new float[3]; float[] pofloat4 = new float[3]; Color color; int count; BufferedImage image = null; try { drawer = new STLDrawer("STLs/" + filename + ".stl"); } catch (FileNotFoundException e) { System.out.println("ERROR: Unable to create stl file! - " + filename + ".stl"); e.printStackTrace(); } try { image = javax.imageio.ImageIO.read(qrFile); height = image.getHeight(); width = image.getWidth(); } catch (IOException e) { System.out.println("ERROR: Unable to open picture file! - " + qrFile.toString()); e.printStackTrace(); } if (printPlatform) { //Base background pofloat1[0] = 0.0f; pofloat1[1] = 0.0f; pofloat1[2] = 0; pofloat2[0] = 0.0f + (float) width; pofloat2[1] = 0.0f + 0.0f; pofloat2[2] = 0; pofloat3[0] = 0.0f + (float) width; pofloat3[1] = 0.0f + (float) height; pofloat3[2] = 0; pofloat4[0] = 0.0f + 0.0f; pofloat4[1] = 0.0f + (float) height; pofloat4[2] = 0; drawer.drawCube(pofloat1, pofloat2, pofloat3, pofloat4, PLATFORM_HEIGHT); //end base background } int[][] drawArray = new int[width + 2][height + 2]; for (int jj = 0; jj < height; jj++) { for (int ii = 0; ii < width; ii++) { color = new Color(image.getRGB(ii, jj)); if (color.equals(Color.BLACK)) { drawArray[ii + 1][height - jj + 1] = 1; //PNG origin starts at top left of image, my origin is bottom left } } } count = 0; for (int jj = 1; jj < height + 2; jj++) //drawTop { for (int ii = 1; ii < width + 2; ii++) { if (drawArray[ii][jj] == 1) { while ((ii + count < width + 2) && (drawArray[ii + count][jj] == 1) && (drawArray[ii + count][jj + 1] == 0)) { count++; } pofloat1[0] = (float) ii; pofloat1[1] = (float) jj; pofloat1[2] = PLATFORM_HEIGHT; pofloat4[0] = (float) ii + 0.0f; pofloat4[1] = (float) jj + 1.0f; pofloat4[2] = PLATFORM_HEIGHT; pofloat3[0] = (float) ii + count;//1.0f; pofloat3[1] = (float) jj + 1.0f; pofloat3[2] = PLATFORM_HEIGHT; pofloat2[0] = (float) ii + 1.0f; pofloat2[1] = (float) jj + 0.0f; pofloat2[2] = PLATFORM_HEIGHT; ii = ii + count; if (count != 0) { drawer.drawTop(pofloat1, pofloat2, pofloat3, pofloat4, PLATFORM_RATIO); } count = 0; } } } count = 0; for (int jj = 1; jj < height + 2; jj++) //bottom { for (int ii = 1; ii < width + 2; ii++) { if (drawArray[ii][jj] == 1) { while ((ii + count < width + 2) && (drawArray[ii + count][jj] == 1) && (drawArray[ii + count][jj - 1] == 0)) { count++; } pofloat1[0] = (float) ii; pofloat1[1] = (float) jj; pofloat1[2] = PLATFORM_HEIGHT; pofloat4[0] = (float) ii + 0.0f; pofloat4[1] = (float) jj + 1.0f; pofloat4[2] = PLATFORM_HEIGHT; pofloat3[0] = (float) ii + 1.0f; pofloat3[1] = (float) jj + 1.0f; pofloat3[2] = PLATFORM_HEIGHT; pofloat2[0] = (float) ii + count;//1.0f; pofloat2[1] = (float) jj + 0.0f; pofloat2[2] = PLATFORM_HEIGHT; if (count != 0) { drawer.drawBottom(pofloat1, pofloat2, pofloat3, pofloat4, PLATFORM_RATIO); } ii = ii + count; count = 0; } } } for (int ii = 1; ii < width + 2; ii++) //draw right { for (int jj = 1; jj < height + 2; jj++) { if (drawArray[ii][jj] == 1) { while ((jj + count < height + 2) && (drawArray[ii][jj + count] == 1) && (drawArray[ii + 1][jj + count] == 0)) { count++; } pofloat1[0] = (float) ii; pofloat1[1] = (float) jj; pofloat1[2] = PLATFORM_HEIGHT; pofloat4[0] = (float) ii + 0.0f; pofloat4[1] = (float) jj + 1.0f; pofloat4[2] = PLATFORM_HEIGHT; pofloat3[0] = (float) ii + 1.0f; pofloat3[1] = (float) jj + count;//1.0f; pofloat3[2] = PLATFORM_HEIGHT; pofloat2[0] = (float) ii + 1.0f; pofloat2[1] = (float) jj + 0.0f; pofloat2[2] = PLATFORM_HEIGHT; if (count != 0) { drawer.drawRight(pofloat1, pofloat2, pofloat3, pofloat4, PLATFORM_RATIO); } jj = jj + count; count = 0; } } } for (int ii = 1; ii < width + 2; ii++) //draw left { for (int jj = 1; jj < height + 2; jj++) { if (drawArray[ii][jj] == 1) { while ((jj + count < height + 2) && (drawArray[ii][jj + count] == 1) && (drawArray[ii - 1][jj + count] == 0)) { count++; } pofloat1[0] = (float) ii; pofloat1[1] = (float) jj; pofloat1[2] = PLATFORM_HEIGHT; pofloat4[0] = (float) ii + 0.0f; pofloat4[1] = (float) jj + count;//1.0f; pofloat4[2] = PLATFORM_HEIGHT; pofloat3[0] = (float) ii + 1.0f; pofloat3[1] = (float) jj + 1.0f; pofloat3[2] = PLATFORM_HEIGHT; pofloat2[0] = (float) ii + 1.0f; pofloat2[1] = (float) jj + 0.0f; pofloat2[2] = PLATFORM_HEIGHT; if (count != 0) { drawer.drawLeft(pofloat1, pofloat2, pofloat3, pofloat4, PLATFORM_RATIO); } jj = jj + count; count = 0; } } } for (int jj = 1; jj < height + 2; jj++) //draw back { for (int ii = 1; ii < width + 2; ii++) { if (drawArray[ii][jj] == 1) { while ((ii + count < width + 2) && (drawArray[ii + count][jj] == 1)) { count++; } pofloat1[0] = (float) ii; pofloat1[1] = (float) jj; pofloat1[2] = PLATFORM_HEIGHT; pofloat4[0] = (float) ii + 0.0f; pofloat4[1] = (float) jj + 1.0f; pofloat4[2] = PLATFORM_HEIGHT; pofloat3[0] = (float) ii + count;//1.0f; pofloat3[1] = (float) jj + 1.0f; pofloat3[2] = PLATFORM_HEIGHT; pofloat2[0] = (float) ii + count;//1.0f; pofloat2[1] = (float) jj + 0.0f; pofloat2[2] = PLATFORM_HEIGHT; if (count != 0) { drawer.drawBack(pofloat1, pofloat2, pofloat3, pofloat4, PLATFORM_RATIO); } ii = ii + count; count = 0; } } } if (printQRbottom) { for (int jj = 1; jj < height + 2; jj++) //draw front { for (int ii = 1; ii < width + 2; ii++) { if (drawArray[ii][jj] == 1) { while ((ii + count < width + 2) && (drawArray[ii + count][jj] == 1)) { count++; } pofloat1[0] = (float) ii; pofloat1[1] = (float) jj; pofloat1[2] = PLATFORM_HEIGHT; pofloat4[0] = (float) ii + 0.0f; pofloat4[1] = (float) jj + 1.0f; pofloat4[2] = PLATFORM_HEIGHT; pofloat3[0] = (float) ii + count;//1.0f; pofloat3[1] = (float) jj + 1.0f; pofloat3[2] = PLATFORM_HEIGHT; pofloat2[0] = (float) ii + count;//1.0f; pofloat2[1] = (float) jj + 0.0f; pofloat2[2] = PLATFORM_HEIGHT; if (count != 0) { drawer.drawFront(pofloat1, pofloat2, pofloat3, pofloat4, PLATFORM_RATIO); } ii = ii + count; count = 0; } } } } drawer.resizeNumTriangles(); System.out.println("STL drawn: " + filename + ".stl"); drawer.closeFile(); }
From source file:net.d53dev.dslfy.web.service.GifService.java
public BufferedImage convertRGBAToGIF(BufferedImage src, int transColor) { BufferedImage dst = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_BYTE_INDEXED); Graphics g = dst.getGraphics(); g.setColor(new Color(transColor)); g.fillRect(0, 0, dst.getWidth(), dst.getHeight()); {//ww w . j a v a2 s.c o m IndexColorModel indexedModel = (IndexColorModel) dst.getColorModel(); WritableRaster raster = dst.getRaster(); int sample = raster.getSample(0, 0, 0); int size = indexedModel.getMapSize(); byte[] rr = new byte[size]; byte[] gg = new byte[size]; byte[] bb = new byte[size]; indexedModel.getReds(rr); indexedModel.getGreens(gg); indexedModel.getBlues(bb); IndexColorModel newModel = new IndexColorModel(8, size, rr, gg, bb, sample); dst = new BufferedImage(newModel, raster, dst.isAlphaPremultiplied(), null); } dst.createGraphics().drawImage(src, 0, 0, null); return dst; }
From source file:doge.photo.DogePhotoManipulator.java
private BufferedImage manipulate(BufferedImage sourceImage) { double aspectRatio = sourceImage.getHeight() / (double) sourceImage.getWidth(); int height = (int) Math.floor(IMAGE_WIDTH * aspectRatio); BufferedImage destinationImage = new BufferedImage(IMAGE_WIDTH, height, BufferedImage.TYPE_INT_RGB); render(sourceImage, destinationImage); return destinationImage; }
From source file:edu.csun.ecs.cs.multitouchj.ui.control.Canvas.java
protected Image getBufferedImageImage(BufferedImage bufferedImage) { byte[] bytes = (byte[]) bufferedImage.getRaster().getDataElements(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight(), null); return new Image(bufferedImage.getWidth(), bufferedImage.getHeight(), bytes, true); }
From source file:dk.netdesign.common.osgi.config.osgi.OCD.java
public BufferedImage scaleImage(BufferedImage img, int width, int height, Color background) { int imgWidth = img.getWidth(); int imgHeight = img.getHeight(); if (imgWidth * height < imgHeight * width) { width = imgWidth * height / imgHeight; } else {/*from w w w . jav a 2 s .co m*/ height = imgHeight * width / imgWidth; } BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = newImage.createGraphics(); try { g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.setBackground(background); g.clearRect(0, 0, width, height); g.drawImage(img, 0, 0, width, height, null); } finally { g.dispose(); } return newImage; }
From source file:jadx.core.utils.android.Res9patchStreamDecoder.java
public void decode(InputStream in, OutputStream out) throws JadxException { try {// w ww. ja v a2 s. c o m byte[] data = IOUtils.toByteArray(in); BufferedImage im = ImageIO.read(new ByteArrayInputStream(data)); int w = im.getWidth(), h = im.getHeight(); BufferedImage im2 = new BufferedImage(w + 2, h + 2, BufferedImage.TYPE_INT_ARGB); im2.createGraphics().drawImage(im, 1, 1, w, h, null); NinePatch np = getNinePatch(data); drawHLine(im2, h + 1, np.padLeft + 1, w - np.padRight); drawVLine(im2, w + 1, np.padTop + 1, h - np.padBottom); int[] xDivs = np.xDivs; for (int i = 0; i < xDivs.length; i += 2) { drawHLine(im2, 0, xDivs[i] + 1, xDivs[i + 1]); } int[] yDivs = np.yDivs; for (int i = 0; i < yDivs.length; i += 2) { drawVLine(im2, 0, yDivs[i] + 1, yDivs[i + 1]); } ImageIO.write(im2, "png", out); } catch (IOException | NullPointerException ex) { throw new JadxException(ex.toString()); } }
From source file:com.github.pitzcarraldo.dissimilar.Dissimilar.java
/** * Calculate the PSNR between two files//from w w w . j a va2 s .c o m * @param pOne first image to compare * @param pTwo second image to compare * @return calculated psnr */ public static double calcPSNR(final File pOne, final File pTwo) { BufferedImage imageOne = null; try { imageOne = Imaging.getBufferedImage(pOne); } catch (IOException e) { printError(pOne, false, false, pTwo, false); return -1; } catch (NullPointerException e) { printError(pOne, false, false, pTwo, false); return -1; } catch (ImageReadException e) { printError(pOne, false, false, pTwo, false); return -1; } //getRGB only returns 8 bits per component, so what about 16-bit images? final int[] oneA = imageOne.getRGB(0, 0, imageOne.getWidth(), imageOne.getHeight(), null, 0, imageOne.getWidth()); final boolean greyscale = (imageOne.getType() == BufferedImage.TYPE_BYTE_GRAY || imageOne.getType() == BufferedImage.TYPE_USHORT_GRAY); imageOne = null; BufferedImage imageTwo = null; try { imageTwo = Imaging.getBufferedImage(pTwo); } catch (IOException e) { printError(pOne, true, true, pTwo, false); return -1; } catch (NullPointerException e) { printError(pOne, true, true, pTwo, false); return -1; } catch (ImageReadException e) { printError(pOne, true, true, pTwo, false); return -1; } //getRGB only returns 8 bits per component, so what about 16-bit images? final int[] twoA = imageTwo.getRGB(0, 0, imageTwo.getWidth(), imageTwo.getHeight(), null, 0, imageTwo.getWidth()); imageTwo = null; final double psnr = calcPSNR(oneA, twoA, greyscale); return psnr; }
From source file:ch.admin.isb.hermes5.util.ImageUtilsTest.java
@Test public void testScaleByWidth() { byte[] gifStream = getResourceAsStream("logo.jpg"); BufferedImage bufferedImage = imageUtil.toBufferedImage(gifStream); BufferedImage makeSmallerToMax = imageUtil.makeSmallerToMax(bufferedImage, 100, 90); assertEquals(100, makeSmallerToMax.getWidth()); assertEquals((int) (10300.0 / 241), makeSmallerToMax.getHeight()); }
From source file:com.silverpeas.thumbnail.control.ThumbnailController.java
protected static void cropFromPath(String pathOriginalFile, ThumbnailDetail thumbDetailComplete, int thumbnailHeight, int thumbnailWidth) throws IOException, ThumbnailException { File originalFile = new File(pathOriginalFile); BufferedImage bufferOriginal = ImageIO.read(originalFile); if (bufferOriginal == null) { SilverTrace.error("thumbnail", "ThumbnailController.cropFromPath(int thumbnailWidth, " + "int thumbnailHeight,ThumbnailDetail thumbDetailComplete)", "thumbnail.EX_MSG_NOT_AN_IMAGE", "pathOriginalFile=" + pathOriginalFile); throw new ThumbnailException("ThumbnailBmImpl.cropFromPath()", SilverpeasException.ERROR, "thumbnail.EX_MSG_NOT_AN_IMAGE"); } else {/*from w w w.j a v a 2s . c o m*/ thumbDetailComplete.setXStart(0); thumbDetailComplete.setYStart(0); thumbDetailComplete.setXLength(bufferOriginal.getWidth()); thumbDetailComplete.setYLength(bufferOriginal.getHeight()); String pathCropFile = getImageDirectory(thumbDetailComplete.getInstanceId()) + thumbDetailComplete.getCropFileName(); createCropThumbnailFileOnServer(pathOriginalFile, getImageDirectory(thumbDetailComplete.getInstanceId()), pathCropFile, thumbDetailComplete, thumbnailWidth, thumbnailHeight); getThumbnailService().updateThumbnail(thumbDetailComplete); } }
From source file:org.opennms.netmgt.charts.ChartUtilsTest.java
@Test public void testGetChartAsBufferedImage() throws MarshalException, ValidationException, IOException, SQLException { BufferedImage bi = ChartUtils.getChartAsBufferedImage("sample-bar-chart"); assertEquals(300, bi.getHeight()); }