Java Code Examples for java.awt.image.AffineTransformOp#TYPE_BILINEAR
The following examples show how to use
java.awt.image.AffineTransformOp#TYPE_BILINEAR .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageServices.java From M2Doc with Eclipse Public License 1.0 | 6 votes |
@Documentation( value = "Resizes the Image by the given factor.", params = { @Param(name = "image", value = "The Image"), @Param(name = "factor", value = "The resize factor"), }, result = "resize the image", examples = { @Example(expression = "myImage.resize(0.5)", result = "will resize the image by a factor 0.5"), } ) // @formatter:on public MImage resize(MImage image, Double factor) throws IOException { final BufferedImage bufferedImage = MImageAWTImpl.getBufferedImage(image); final BufferedImage resized = new BufferedImage((int) (bufferedImage.getWidth() * factor), (int) (bufferedImage.getHeight() * factor), bufferedImage.getType()); final AffineTransform zoomTransfort = AffineTransform.getScaleInstance(factor, factor); final AffineTransformOp retaillerImage = new AffineTransformOp(zoomTransfort, AffineTransformOp.TYPE_BILINEAR); retaillerImage.filter(bufferedImage, resized); return new MImageAWTImpl(resized, image.getURI()); }
Example 2
Source File: Gem.java From Path-of-Leveling with MIT License | 6 votes |
public void resizeImage(){ BufferedImage before = SwingFXUtils.fromFXImage(gemIcon, null); int w = before.getWidth(); int h = before.getHeight(); // Create a new image of the proper size int w2 = (int) (w * 0.7); int h2 = (int) (h * 0.7); BufferedImage after = new BufferedImage(w2, h2, BufferedImage.TYPE_INT_ARGB); AffineTransform scaleInstance = AffineTransform.getScaleInstance(0.7, 0.7); AffineTransformOp scaleOp = new AffineTransformOp(scaleInstance, AffineTransformOp.TYPE_BILINEAR); after = scaleOp.filter(before, after); smallGemIcon = SwingFXUtils.toFXImage(after, null); //ImageIcon imageIcon = new ImageIcon(dimg); }
Example 3
Source File: Html5AttachmentGenerator.java From JGiven with Apache License 2.0 | 6 votes |
static BufferedImage scaleDown( BufferedImage before ) { double xFactor = Math.min(1.0, MINIMAL_THUMBNAIL_SIZE / (double) before.getWidth()); double yFactor = Math.min(1.0, MINIMAL_THUMBNAIL_SIZE / (double) before.getHeight()); double factor = Math.max(xFactor, yFactor); int width = (int) Math.round(before.getWidth() * factor); int height = (int) Math.round(before.getHeight() * factor); BufferedImage after = new BufferedImage( width, height, BufferedImage.TYPE_INT_ARGB ); AffineTransform at = new AffineTransform(); at.scale( factor, factor ); AffineTransformOp scaleOp = new AffineTransformOp( at, AffineTransformOp.TYPE_BILINEAR ); return scaleOp.filter( before, after ); }
Example 4
Source File: BaseSanselanTest.java From java-image-processing-survival-guide with Apache License 2.0 | 6 votes |
/** * Some quick and dirty image scaling - please note that for best performance * and quality you should use image rescaling libraries. */ @Override public BufferedImage resample(BufferedImage bufferedImage, int width, int height) { Dimension imageDimension = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight()); Dimension boundaryDimension = new Dimension(width, height); Dimension scaledDimension = BufferedImageUtils.getScaledDimension(imageDimension, boundaryDimension); double scaleX = scaledDimension.getWidth() / bufferedImage.getWidth(); double scaleY = scaledDimension.getHeight() / bufferedImage.getHeight(); AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY); AffineTransformOp biLinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR); return biLinearScaleOp.filter( bufferedImage, new BufferedImage(scaledDimension.width, scaledDimension.height, bufferedImage.getType())); }
Example 5
Source File: ImageUtils.java From markdown-image-kit with MIT License | 6 votes |
/** * Scale image buffered image. * * @param sourceImage the source image * @param newWidth the new width * @param newHeight the new height * @return the buffered image */ @Contract("null, _, _ -> null") public static BufferedImage scaleImage(BufferedImage sourceImage, int newWidth, int newHeight) { if (sourceImage == null) { return null; } if (newWidth == 0 || newHeight == 0) { return null; } AffineTransform at = AffineTransform.getScaleInstance((double) newWidth / sourceImage.getWidth(null), (double) newHeight / sourceImage.getHeight(null)); // http://nickyguides.digital-digest.com/bilinear-vs-bicubic.htm AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); return op.filter(sourceImage, null); }
Example 6
Source File: BaseImageIoTest.java From java-image-processing-survival-guide with Apache License 2.0 | 6 votes |
/** * Some quick and dirty image scaling - please note that for best performance * and quality you should use image rescaling libraries. */ @Override public BufferedImage resample(BufferedImage bufferedImage, int width, int height) { Dimension imageDimension = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight()); Dimension boundaryDimension = new Dimension(width, height); Dimension scaledDimension = BufferedImageUtils.getScaledDimension(imageDimension, boundaryDimension); double scaleX = scaledDimension.getWidth() / bufferedImage.getWidth(); double scaleY = scaledDimension.getHeight() / bufferedImage.getHeight(); AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY); AffineTransformOp biLinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR); return biLinearScaleOp.filter( bufferedImage, new BufferedImage(scaledDimension.width, scaledDimension.height, bufferedImage.getType())); }
Example 7
Source File: AnalogClock.java From DroidUIBuilder with Apache License 2.0 | 5 votes |
@Override public void apply() { super.apply(); if (face != null) { double scale_x = getWidth() / 154.0; double scale_y = getHeight() / 154.0; AffineTransform at = AffineTransform.getScaleInstance(scale_x, scale_y); AffineTransformOp op = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); face_scale = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR); op.filter(face, face_scale); hour_scale = new BufferedImage((int) (hour.getWidth() * scale_x), (int) (hour.getHeight() * scale_y), BufferedImage.TYPE_4BYTE_ABGR); op.filter(hour, hour_scale); minute_scale = new BufferedImage( (int) (minute.getWidth() * scale_x), (int) (minute .getHeight() * scale_y), BufferedImage.TYPE_4BYTE_ABGR); op.filter(minute, minute_scale); offx = (int) (14 * scale_x); } }
Example 8
Source File: ImageFilter.java From JewelCrawler with GNU General Public License v3.0 | 5 votes |
/** 平滑缩放 */ public BufferedImage scaling(double s) { AffineTransform tx = new AffineTransform(); tx.scale(s, s); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); return op.filter(image, null); }
Example 9
Source File: InvalidTransformParameterTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static Raster testRasterTransform(Raster src, WritableRaster dst, AffineTransform transform) { AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); return op.filter(src, dst); }
Example 10
Source File: InvalidTransformParameterTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static BufferedImage testImageTransform(BufferedImage image, AffineTransform transform) { AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); BufferedImage transformedImage = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); return op.filter(image, transformedImage); }
Example 11
Source File: MeterPanel.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Draw arrow curved. * @param g */ protected final void paintArrowRotated(Graphics g) { Graphics2D g2d = (Graphics2D)g; int size = (this.getWidth() > this.getHeight()) ? this.getHeight() : this.getWidth(); // Arrow rotated. BufferedImage image = (this.getState().getRotation() == State.Rotation.COUNTER_CLOCKWISE) ? this.getImageArrowRotatedCounterClockwise() : this.getImageArrowRotatedClockwise(); int imageWidth = image.getWidth(); int imageHeight = image.getHeight(); double imagePreferredSize = this.getConfiguration().getDouble("arrow-rotated.size") * size; double imageScaleFactor = (imageWidth > imageHeight) ? imagePreferredSize / imageWidth : imagePreferredSize / imageHeight; int imageNewWidth = (int)Math.floor(imageWidth * imageScaleFactor); int imageNewHeight = (int)Math.floor(imageHeight * imageScaleFactor); // Determine offset. double offset = this.getConfiguration().getDouble("arrow-rotated.offset"); double imageOffset = (this.getState().getRotation() == State.Rotation.COUNTER_CLOCKWISE) ? -imageNewWidth - offset * size : offset * size; AffineTransform transform = new AffineTransform(); transform.scale(imageScaleFactor, imageScaleFactor); AffineTransformOp operation = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); image = operation.filter(image, null); g2d.drawImage(image, (int)(this.getWidth() / 2 + imageOffset), (int)((this.getHeight() - image.getHeight()) / 2), null); }
Example 12
Source File: InvalidTransformParameterTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public static Raster testRasterTransform(Raster src, WritableRaster dst, AffineTransform transform) { AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); return op.filter(src, dst); }
Example 13
Source File: InvalidTransformParameterTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public static Raster testRasterTransform(Raster src, WritableRaster dst, AffineTransform transform) { AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); return op.filter(src, dst); }
Example 14
Source File: ImageHelper.java From mcaselector with MIT License | 5 votes |
public static BufferedImage scaleImage(BufferedImage before, double newSize) { double w = before.getWidth(); double h = before.getHeight(); BufferedImage after = new BufferedImage((int) newSize, (int) newSize, BufferedImage.TYPE_INT_ARGB); AffineTransform at = new AffineTransform(); at.scale(newSize / w, newSize / h); AffineTransformOp scaleOp = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR); return scaleOp.filter(before, after); }
Example 15
Source File: InvalidTransformParameterTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static Raster testRasterTransform(Raster src, WritableRaster dst, AffineTransform transform) { AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); return op.filter(src, dst); }
Example 16
Source File: InvalidTransformParameterTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static BufferedImage testImageTransform(BufferedImage image, AffineTransform transform) { AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); BufferedImage transformedImage = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); return op.filter(image, transformedImage); }
Example 17
Source File: InvalidTransformParameterTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static Raster testRasterTransform(Raster src, WritableRaster dst, AffineTransform transform) { AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); return op.filter(src, dst); }
Example 18
Source File: InvalidTransformParameterTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static BufferedImage testImageTransform(BufferedImage image, AffineTransform transform) { AffineTransformOp op = new AffineTransformOp(transform, AffineTransformOp.TYPE_BILINEAR); BufferedImage transformedImage = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); return op.filter(image, transformedImage); }
Example 19
Source File: CursorLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 4 votes |
CursorImageData(BufferedImage[] bi, int delay, int hsX, int hsY, int curType) { // cursor type // 0 - Undefined (an array of images inside an ICO) // 1 - ICO // 2 - CUR IntBuffer singleCursor = null; ArrayList<IntBuffer> cursors = new ArrayList<IntBuffer>(); int bwidth = 0; int bheight = 0; boolean multIcons = false; // make the cursor image for (int i = 0; i < bi.length; i++) { BufferedImage img = bi[i]; bwidth = img.getWidth(); bheight = img.getHeight(); if (curType == 1) { hsX = 0; hsY = bheight - 1; } else if (curType == 2) { if (hsY == 0) { // make sure we flip if 0 hsY = bheight - 1; } } else { // We force to choose 32x32 icon from // the array of icons in that ICO file. if (bwidth != 32 && bheight != 32) { multIcons = true; continue; } else { if (img.getType() != 2) { continue; } else { // force hotspot hsY = bheight - 1; } } } // We flip our image because .ICO and .CUR will always be reversed. AffineTransform trans = AffineTransform.getScaleInstance(1, -1); trans.translate(0, -img.getHeight(null)); AffineTransformOp op = new AffineTransformOp(trans, AffineTransformOp.TYPE_BILINEAR); img = op.filter(img, null); singleCursor = BufferUtils.createIntBuffer(img.getWidth() * img.getHeight()); DataBufferInt dataIntBuf = (DataBufferInt) img.getData().getDataBuffer(); singleCursor = IntBuffer.wrap(dataIntBuf.getData()); cursors.add(singleCursor); } int count; if (multIcons) { bwidth = 32; bheight = 32; count = 1; } else { count = cursors.size(); } // put the image in the IntBuffer data = BufferUtils.createIntBuffer(bwidth * bheight); imgDelay = BufferUtils.createIntBuffer(bi.length); for (int i = 0; i < count; i++) { data.put(cursors.get(i)); if (delay > 0) { imgDelay.put(delay); } } width = bwidth; height = bheight; xHotSpot = hsX; yHotSpot = hsY; numImages = count; data.rewind(); if (imgDelay != null) { imgDelay.rewind(); } }
Example 20
Source File: JPanel_ScreenCapture.java From MobyDroid with Apache License 2.0 | 4 votes |
private void drawImage() { // check first if (iconBytes == null || iconBytes.length == 0) { return; } // load bufered image BufferedImage bi; try { bi = ImageIO.read(new ByteArrayInputStream(iconBytes)); } catch (IOException ex) { return; } // rotate if (rotationAngle != 0) { AffineTransform tx = new AffineTransform(); tx.rotate(Math.PI * rotationAngle / 2.0, bi.getWidth() / 2.0, bi.getHeight() / 2.0); if (rotationAngle == 1 || rotationAngle == 3) { double offset; if (rotationAngle == 1) { offset = (bi.getWidth() - bi.getHeight()) / 2.0; } else { offset = (bi.getHeight() - bi.getWidth()) / 2.0; } tx.translate(offset, offset); } AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); bi = op.filter(bi, null); } // get width and height int width = bi.getWidth(); int height = bi.getHeight(); // first check if we need to scale width if (bi.getWidth() > jLabel_ScreenShot.getWidth()) { //scale width to fit width = jLabel_ScreenShot.getWidth(); //scale height to maintain aspect ratio height = (width * bi.getHeight()) / bi.getWidth(); } // then check if we need to scale even with the new height if (height > jLabel_ScreenShot.getHeight()) { //scale height to fit instead height = jLabel_ScreenShot.getHeight(); //scale width to maintain aspect ratio width = (height * bi.getWidth()) / bi.getHeight(); } // set image jLabel_ScreenShot.setIcon(new ImageIcon(bi.getScaledInstance(width, height, Image.SCALE_DEFAULT))); }