bufferedimage

How to rotate a buffered image without cropping it? Is there any way to rotate a JLayeredPane or JLabel?

折月煮酒 提交于 2019-12-06 13:21:33
I had searched about it but I did not get straight forward answer. I want a buffered image to be rotated but not cropped I knew the new dimensions are gonna be some thing like this int w = originalImage.getWidth(); int h = originalImage.getHeight(); double toRad = Math.toRadians(degree); int hPrime = (int) (w * Math.abs(Math.sin(toRad)) + h * Math.abs(Math.cos(toRad))); int wPrime = (int) (h * Math.abs(Math.sin(toRad)) + w * Math.abs(Math.cos(toRad))); Provide me a method for that. BTW is there any way to rotate a JLabel with an ImageIcon ? Intention: adding to panels and layered pane and also

BufferedImage leaks - are there any alternatives?

ε祈祈猫儿з 提交于 2019-12-06 12:07:09
问题 I am having strange problems with BufferedImage, which in some cases consumes all the free system memory (3GB, 1.5GB free). I have created a simple wrapper and I use it like this: public ImageWrapper(final byte[] bytes) throws ImageWrapperException { this(new ByteArrayInputStream(bytes)); } public ImageWrapper(final ByteArrayInputStream bis) throws ImageWrapperException { try { image = ImageIO.read(bis); bis.close(); } catch (IOException e) { throw new ImageWrapperException(e); } } (I have

Convert buffered image to the 2D byte array with the same data

百般思念 提交于 2019-12-06 07:33:52
I have written one application for image processing in Java. I have processed the image which is the buffered image and now I want to return the byte[] for that processed image that is I should get the byte array of binarized image. Here is my code: public static byte[][] binarizeImage(BufferedImage bfImage){ int red; int newPixel; int h ; int w ; int threshold = otsuTreshold(bfImage); // this function returns the threshold value 199 BufferedImage binarized = new BufferedImage(bfImage.getWidth(), bfImage.getHeight(), bfImage.getType()); for(int i=0; i<bfImage.getWidth(); i++) { for(int j=0; j

Load a PNG image into Java as BufferedImage through JNI C code

左心房为你撑大大i 提交于 2019-12-06 07:26:45
I have the following problem. I have C code that acquires a PNG image as basically raw data and keeps it in memory. I would like this raw data to be translated to a BufferedImage in Java, through the use of JNI. Does anyone know any way of doing this or has done this before? Chad Okere I'll assume you know the basics of how to call functions with JNI. It's not that complicated, although it can be a pain in the ass. If you want to get it done quickly, just write the PNG to a temp file, pass the file name up through JNI and load it using ImageIO. If you want to get more sophisticated, and avoid

Is there any way in Java to take image width and height without transfer or download?

核能气质少年 提交于 2019-12-06 06:35:45
问题 In order to get image's height we can use ImageIO.read(new URL("…")).getHeight() . My questions: Do I understand correctly that this method downloads the image to the local computer prior size calculation? If yes, to where exactly the image is downloaded — to some JVM's cache on HDD or directly to the RAM? Is there any way to take image's height without transfer or download? But with some kind of request to server? 回答1: First, your questions: Kind of. First of all, the ImageIO.read(...)

What are tiles and how are they created in the BufferedImage

萝らか妹 提交于 2019-12-06 04:03:01
问题 I posted a question in sun java forums sometime ago and i am finding it hard to understand the first response i received from the replier though it seems he gave me the correct approach to my problem. The link to the question is: http://forums.sun.com/thread.jspa?threadID=5436562&tstart=0 Someone replied that i should use BufferedImage and make tiles. I don't really understand what the tiles mean in connection with the BufferedImage . I would like someone to explain to me what the tiles are

Java - Red, Green, Blue to getRGB

ぐ巨炮叔叔 提交于 2019-12-05 18:25:27
By calling getRGB(int x, int y) with a BufferedImage object, one gets a single, negative number. How can I convert three different values (a red, a green, and a blue) into this single, negative number? Using the Color class: new Color(r, g, b).getRGB() BufferedImage ends up delegating to java.awt.image.ColorModel which uses the following code: public int getRGB(Object inData) { return (getAlpha(inData) << 24) | (getRed(inData) << 16) | (getGreen(inData) << 8) | (getBlue(inData) << 0); } Modifying this to suit your needs is a trivial exercise. Xar E Ahmer JB Nizet's answer is great , but it can

How to make bmp image from pixel byte array in java

若如初见. 提交于 2019-12-05 14:13:22
I have a byte array containing pixel values from a .bmp file. It was generated by doing this: BufferedImage readImage = ImageIO.read(new File(fileName)); byte imageData[] = ((DataBufferByte)readImage.getData().getDataBuffer()).getData(); Now I need to recreate the .bmp image. I tried to make a BufferedImage and set the pixels of the WritableRaster by calling the setPixels method. But there I have to provide an int[], float[] or double[] array. Maybe I need to convert the byte array into one of these. But I don't know how to do that. I also tried the setDataElements method. But I am not sure

Image vs. BufferedImage

北慕城南 提交于 2019-12-05 14:01:44
问题 Whenever dealing with the loading and rendering of images in Java, I have previously always used BufferedImage s to store and manipulate the images in memory. However, I have recently come across a few different sites that use the Image class instead of BufferedImage and this got me wondering - what are the differences? I'm aware that a BufferedImage has a larger/optimised toolset, but does come at any cost? If so, when does this cost become noticeable? In which situations would you use an

Do certain image file types always correspond with certain BufferedImage constant types?

早过忘川 提交于 2019-12-05 12:36:09
The BufferedImage class in Java contains a getType() method which returns an integer correlating with a BufferedImage constant type variable describing some information about how the image is encoded (you can look at the BufferedImage source to determine what number corresponds to what constant type variable). For instance, if it returns the integer corresponding with BufferedImage.TYPE_3BYTE_BGR , then that means that the BufferedImage is an 8-bit RGB image with no alpha and with blue, green, and yellow each being represented by 3 bits. Some of these image types seem to correlate with certain