bufferedimage

How can I more quickly render my array?

我们两清 提交于 2019-12-10 15:55:07
问题 I have been working on a nonogram solver in Java, and all of my algorithm works fine, but I have been struggling with the visualization a little bit. During the execution of the algorithm, I have access to two "solution-arrays". One is of type int[][] , and contains values -1 for "certainly white", 0 for "uncertain" and 1 for "certainly black". Another array is of type float[][] which contains values between 0 and 1 , here 0 is for certainly white, 1 is for certainly black and a value of .2

Java exception “Exception in thread ”main“ java.lang.ClassCastException: [B cannot be cast to [I” when calling java.awt.image.BufferedImage.copyData()

江枫思渺然 提交于 2019-12-10 15:33:39
问题 In the following code, I'm trying to combine some 1024*1024 png into several larger pngs. The code fails with this exception: Exception in thread "main" java.lang.ClassCastException: [B cannot be cast to [I at sun.awt.image.IntegerInterleavedRaster.setDataElements(Unknown Source) at java.awt.image.BufferedImage.copyData(Unknown Source) at mloc.bs12.mapimagemerger.Merger.main(Merger.java:27) It's probably something small and silly which I overlooked, but I can't find anything wrong with the

How can i find out where a BufferedImage has Alpha in Java?

蓝咒 提交于 2019-12-10 13:36:09
问题 I've got a BuferredImage and a boolean[][] array. I want to set the array to true where the image is completely transparant. Something like: for(int x = 0; x < width; x++) { for(int y = 0; y < height; y++) { alphaArray[x][y] = bufferedImage.getAlpha(x, y) == 0; } } But the getAlpha(x, y) method does not exist, and I did not find anything else I can use. There is a getRGB(x, y) method, but I'm not sure if it contains the alpha value or how to extract it. Can anyone help me? Thank you! 回答1:

Can I tell what the file type of a BufferedImage originally was?

假如想象 提交于 2019-12-10 13:22:31
问题 In my code, I have a BufferedImage that was loaded with the ImageIO class like so: BufferedImage image = ImageIO.read(new File (filePath); Later on, I want to save it to a byte array, but the ImageIO.write method requires me to pick either a GIF, PNG, or JPG format to write my image as (as described in the tutorial here). I want to pick the same file type as the original image. If the image was originally a GIF, I don't want the extra overhead of saving it as a PNG. But if the image was

How do ColorModels and WritableRasters work in java BufferedImages?

社会主义新天地 提交于 2019-12-10 12:21:45
问题 When working with the BufferedImage class in Java, I usually use the constructor with parameters int width, int height, int type . For a certain application, though, I wanted an image which would store the color data using bytes in the order ARGB, which can't be done in that way (it has only TYPE_4BYTE_ABGR ). I found the following solution, which worked fine: WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, 4, null); ColorModel colorModel = new

Get buffered image from byte array of raw data

泄露秘密 提交于 2019-12-10 10:23:24
问题 I am using JNA. and i am getting byte array of raw data from my c++ method. Now i am stuck how to get buffered image in java using this raw data byte array. I had tried few things to get it as tiff image but i dint get success. this are the code i tried so far. here my byte array contains data for 16 bit gray scale image. i get this data from x-sensor device. and now i need to get image from this byte array. FIRST TRY byte[] byteArray = myVar1.getByteArray(0, 3318000);//array of raw data

Part 2 - How do I get consistent rendering when scaling a JTextPane?

落花浮王杯 提交于 2019-12-10 10:22:58
问题 I submitted another version of this question and a sample program before: How do I get consistent rendering when scaling a JTextPane? Recapitulating the problem: I would like to allow users to zoom into or out of a non-editable JTextPane. Running the example program submitted in the earlier question, which simply scaled the Graphics object, resulted in inconsistent spacing between runs of bold text and non-bold text. The sample program below attempts to solve the problem by drawing the text

Java BufferedImage how to know if a pixel is transparent

有些话、适合烂在心里 提交于 2019-12-10 04:08:06
问题 I'm going to use the getRGB method of BufferedImage. I want to check the pixels of an image and see which of them have transparency (in general the pixels I will have that are transparent will be totaly transparent). How can I get it from the int that getRGB returns? 回答1: BufferedImage img = .... public boolean isTransparent( int x, int y ) { int pixel = img.getRGB(x,y); if( (pixel>>24) == 0x00 ) { return true; } return false; } Of course img has to be in the correct format TYPE_4BYTE_ABGR or

How to get scaled instance of a bufferedImage

大城市里の小女人 提交于 2019-12-09 05:59:58
问题 I wanted to get scaled instance of a buffered image and I did: public void analyzePosition(BufferedImage img, int x, int y){ img = (BufferedImage) img.getScaledInstance(getWidth(), getHeight(), Image.SCALE_SMOOTH); .... } but I do get an exception: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: sun.awt.image.ToolkitImage cannot be cast to java.awt.image.BufferedImage at ImagePanel.analyzePosition(ImagePanel.java:43) I wanted then to cast to ToolkitImage then use the

How to calculate java BufferedImage filesize

ぐ巨炮叔叔 提交于 2019-12-09 00:25:56
问题 I have a servlet based application that is serving images from files stored locally. I have added logic that will allow the application to load the image file to a BufferedImage and then resize the image, add watermark text over the top of the image, or both. I would like to set the content length before writing out the image. Apart from writing the image to a temporary file or byte array, is there a way to find the size of the BufferedImage? All files are being written as jpg if that helps