bufferedimage

Rotate BufferedImage with transparent background

柔情痞子 提交于 2020-11-29 10:46:15
问题 I have an image with transparent background. I'd like to rotate this image to a specific angle and keep the transparent background for the resulting image. For this purpose I use the following method: public static BufferedImage rotateImage(BufferedImage image, double angle, Color backgroundColor) { System.out.println(image.getType()); double theta = Math.toRadians(angle); double sin = Math.abs(Math.sin(theta)); double cos = Math.abs(Math.cos(theta)); int w = image.getWidth(); int h = image

Rotate BufferedImage with transparent background

拟墨画扇 提交于 2020-11-29 10:45:06
问题 I have an image with transparent background. I'd like to rotate this image to a specific angle and keep the transparent background for the resulting image. For this purpose I use the following method: public static BufferedImage rotateImage(BufferedImage image, double angle, Color backgroundColor) { System.out.println(image.getType()); double theta = Math.toRadians(angle); double sin = Math.abs(Math.sin(theta)); double cos = Math.abs(Math.cos(theta)); int w = image.getWidth(); int h = image

Why does this code displaying an image give an “”error“” when build into jar?

♀尐吖头ヾ 提交于 2020-11-29 09:46:52
问题 I want to display an Image in a JLabel by drawing a BufferedImage on it. The x/yOffset is to draw a smaller image in the middel of the JLabel. If I run the code in my IDE it works fine and displays the image on my JFrame. If I now build the Class into a jar file it does not work anymore. I tried it with setting the Image as an icon for the JLabel without using BufferedImage but thats not what I want to do. Here is the Code of my Image Class: public class ImageHQ extends JLabel { BufferedImage

Copy two BufferedImages into one image side by side

大憨熊 提交于 2020-04-05 08:18:55
问题 I have two images and I'd like to copy these two images to a new image where the second image is beside the first image and not on top of it. BufferedImage imgb1 = img1; BufferedImage imgb2 = img2; BufferedImage imgResult = new BufferedImage(...); where imgResult contains the first and the second image next to each other. 回答1: I created a demo for you and also a unit test, hope it works! Code: import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java

Copy two BufferedImages into one image side by side

安稳与你 提交于 2020-04-05 08:17:27
问题 I have two images and I'd like to copy these two images to a new image where the second image is beside the first image and not on top of it. BufferedImage imgb1 = img1; BufferedImage imgb2 = img2; BufferedImage imgResult = new BufferedImage(...); where imgResult contains the first and the second image next to each other. 回答1: I created a demo for you and also a unit test, hope it works! Code: import java.awt.Color; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java

Jcrop not cropping properly the images

落爺英雄遲暮 提交于 2020-02-20 07:55:06
问题 My jcrop code $(function(){ // Create variables (in this scope) to hold the API and image size var jcrop_api, boundx, boundy, // Grab some information about the preview pane $preview = $('#preview-pane'), $pcnt = $('#preview-pane .preview-container'), $pimg = $('#preview-pane .preview-container img'), xsize = $pcnt.width(), ysize = $pcnt.height(); //console.log('init',[xsize,ysize]); $('#target').Jcrop({ onChange: updateInfo, onSelect: updateInfo, onRelease: clearInfo, setSelect: [0, 0, 150,

Resizing TYPE_CUSTOM BufferedImages?

偶尔善良 提交于 2020-01-24 08:48:00
问题 When I read a JPEG from disk, Java sometimes gives me a BufferedImage whose getType() returns TYPE_CUSTOM -- that is, it has a custom color model. I'd like to resize this BufferedImage but I'm not sure how to construct the destination object. Can someone please provide sample code for using the following constructor? BufferedImage(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable properties) I would like to create a BufferedImage of the same type as the source,

Resizing TYPE_CUSTOM BufferedImages?

守給你的承諾、 提交于 2020-01-24 08:46:48
问题 When I read a JPEG from disk, Java sometimes gives me a BufferedImage whose getType() returns TYPE_CUSTOM -- that is, it has a custom color model. I'd like to resize this BufferedImage but I'm not sure how to construct the destination object. Can someone please provide sample code for using the following constructor? BufferedImage(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable properties) I would like to create a BufferedImage of the same type as the source,

Getting filename from BufferedImage

扶醉桌前 提交于 2020-01-24 05:21:24
问题 Is there a way to get the filename from a BufferedImage? I don't seem to see any methods for it. 回答1: A BufferedImage doesn't necessarily have to be backed by a file. It could be a byte array in a database, or even backed by a stream. 回答2: A BufferedImage is not necessarily associated with a file. Just as you can read a String from a file, but there is no getFilename() method on String objects, there is no such method on BufferedImage . 来源: https://stackoverflow.com/questions/4611303/getting

Reliable way to check if image is Grey scale

為{幸葍}努か 提交于 2020-01-24 04:27:07
问题 I am currently working on one use case where i need to determine if uploaded image is Grey Scale or RGB. I found couple of ways to identify this, but not sure if they are reliable and can be used collectively to confirm image is grey scale or not. Part 1: Read Image and get NumberDataElements using Raster. BufferedImage image = ImageIO.read(file); Raster ras = image.getRaster(); int elem = ras.getNumDataElements(); I observed value of elem is "1" in some cases, but not in all. Part 2: Check