bufferedimage

Create a BufferedImage from file and make it TYPE_INT_ARGB

徘徊边缘 提交于 2019-12-17 17:39:51
问题 I have a PNG file with transparency that is loaded and stored in a BufferedImage . I need this BufferedImage to be of TYPE_INT_ARGB . However, when I use getType() the returned value is 0 ( TYPE_CUSTOM ) instead of 2 ( TYPE_INT_ARGB ). This is how I load the .png : public File img = new File("imagen.png"); public BufferedImage buffImg = new BufferedImage(240, 240, BufferedImage.TYPE_INT_ARGB); try { buffImg = ImageIO.read(img ); } catch (IOException e) { } System.out.Println(buffImg.getType()

How to convert Icon from JLabel into BufferedImage?

早过忘川 提交于 2019-12-17 16:49:08
问题 Simple, very straight forward but seems uncle google and me getting confused. I have single JLabel that already has its own Icon . How do I convert the Icon obtained from JLabel into a BufferedImage ? Is there any way around: I tried to multiple casting like this .. final BufferedImage bf1 = (BufferedImage)((Image)jll_img.getIcon()); ..but it failed. 回答1: To amplify on @Andrew Thompson's answer, note that an object that implements the Icon interface knows how to paint something, but it may

Quality loss using ImageIO.write

删除回忆录丶 提交于 2019-12-17 16:48:28
问题 I have noticied significant quality loss using ImageIO.write, how I can disable automatic compression ? val baos: ByteArrayOutputStream = new ByteArrayOutputStream val newBi = new BufferedImage(img.getWidth, img.getHeight, BufferedImage.TYPE_INT_RGB) val gr = newBi.createGraphics() gr.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), Color.WHITE, null) ImageIO.write(newBi, "jpeg", baos) val b = baos.toByteArray baos.close() 回答1: Use ImageWriter. ImageWriter writer = ImageIO

Understanding BufferedImage.getRGB output values

a 夏天 提交于 2019-12-17 10:52:51
问题 I'm getting an integer value for the pixel in an image using this method: int colour = img.getRGB(x, y); Then I'm printing out the values and I see that black pixels correspond to a value like "-16777216", a kind of blue to something like "-16755216", etc. Can someone please explain me the logic behind this value? 回答1: getRGB(int x, int y) return you the value of color pixel at location (x,y) . You are misinterpreting the returned value. It is in the binary format. like 11...11010101 and that

How to convert a byte[] to a BufferedImage in Java?

南楼画角 提交于 2019-12-17 10:47:11
问题 I'm posting this thread because I have some difficulties to deal with pictures in Java. I would like to be able to convert a picture into a byte[] array, and then to be able to do the reverse operation, so I can change the RGB of each pixel, then make a new picture. I want to use this solution because setRGB() and getRGB() of BufferedImage may be too slow for huge pictures (correct me if I'm wrong). I read some posts here to obtain a byte[] array (such as here) so that each pixel is

Converting BufferedImage to Mat in opencv

本小妞迷上赌 提交于 2019-12-17 06:39:08
问题 How can I convert a BufferedImage to a Mat in OpenCV? Im using the java wrapper for OpenCV(not JavaCV). As I am new to OpenCV I have some problems understanding how Mat works. I want to do something like this. (Based on Ted W. reply): BufferedImage image = ImageIO.read(b.getClass().getResource("Lena.png")); int rows = image.getWidth(); int cols = image.getHeight(); int type = CvType.CV_16UC1; Mat newMat = new Mat(rows,cols,type); for(int r=0; r<rows; r++){ for(int c=0; c<cols; c++){ newMat

Bufferedimage resize

守給你的承諾、 提交于 2019-12-17 06:38:59
问题 I am trying to resized a bufferedimage. I am able to store it and show up on a jframe no problems but I can't seem to resize it. Any tips on how I can change this to make it work and show the image as a 200*200 file would be great private void profPic(){ String path = factory.getString("bottle"); BufferedImage img = ImageIO.read(new File(path)); } public static BufferedImage resize(BufferedImage img, int newW, int newH) { int w = img.getWidth(); int h = img.getHeight(); BufferedImage dimg =

Rotate an image in java

北城余情 提交于 2019-12-17 05:11:12
问题 I am looking to rotate an image. I have a JInternalFrame which contains a JLabel . The label contains the image. After the image has been rotated, I need to resize the internal frame. The code I have currently rotates the image, but there is black around the edges of the image and it is off centered. Any suggestions on how to fix this? public void rotateIcon(int angle) { int w = theLabel.getIcon().getIconWidth(); int h = theLabel.getIcon().getIconHeight(); int type = BufferedImage.TYPE_INT

Java BufferedImage getting red, green and blue individually

瘦欲@ 提交于 2019-12-17 04:24:49
问题 The getRGB() method returns a single int. How can I get individually the red, green and blue colors all as the values between 0 and 255? 回答1: Java's Color class can do the conversion: Color c = new Color(image.getRGB()); int red = c.getRed(); int green = c.getGreen(); int blue = c.getBlue(); 回答2: A pixel is represented by a 4-byte (32 bit) integer, like so: 00000000 00000000 00000000 11111111 ^ Alpha ^Red ^Green ^Blue So, to get the individual color components, you just need a bit of binary

Convert RGB values to Integer

心不动则不痛 提交于 2019-12-17 03:57:02
问题 So in a BufferedImage , you receive a single integer that has the RGB values represented in it. So far I use the following to get the RGB values from it: // rgbs is an array of integers, every single integer represents the // RGB values combined in some way int r = (int) ((Math.pow(256,3) + rgbs[k]) / 65536); int g = (int) (((Math.pow(256,3) + rgbs[k]) / 256 ) % 256 ); int b = (int) ((Math.pow(256,3) + rgbs[k]) % 256); And so far, it works. What I need to do is figure out how to get an