bufferedimage

How to convert a BufferedImage to black and white?

☆樱花仙子☆ 提交于 2020-01-12 08:26:10
问题 How can I convert an existing colored BufferedImage to monochrome? I want the image to be completely split between only two rgb codes, black and white. So if there's a border around the image which is a lighter or darker shade of the background, and the background is being converted to white, then I want the border to be converted to white as well, and so on. How can I do this? If its necessary to save the image / load it from disk, I can do that if necessary. Edit: Code to test this: package

Can a BufferedImage be written to file any format?

让人想犯罪 __ 提交于 2020-01-11 14:18:19
问题 Is it correct that if we have a BufferedImage object in java, we could potentially write it out in ANY format using ImageIO.write (if we have a Writer object for the same)? I tried writing a BufferedImage object into a jpg file, it outputted an empty image file however when i tried writing it in to a png file, it worked fine. 回答1: A BufferedImage can be written into any format that ImageIO.write supports (that is, has an ImageWriter available), yes. Please show the code if you can't get it to

Can a BufferedImage be written to file any format?

半腔热情 提交于 2020-01-11 14:16:46
问题 Is it correct that if we have a BufferedImage object in java, we could potentially write it out in ANY format using ImageIO.write (if we have a Writer object for the same)? I tried writing a BufferedImage object into a jpg file, it outputted an empty image file however when i tried writing it in to a png file, it worked fine. 回答1: A BufferedImage can be written into any format that ImageIO.write supports (that is, has an ImageWriter available), yes. Please show the code if you can't get it to

Create a buffered image from rgb pixel values

女生的网名这么多〃 提交于 2020-01-10 14:58:08
问题 I have an integer array of RGB pixels that looks something like: pixels[0] = <rgb-value of pixel(0,0)> pixels[1] = <rgb-value of pixel(1,0)> pixels[2] = <rgb-value of pixel(2,0)> pixels[3] = <rgb-value of pixel(0,1)> ...etc... And I'm trying to create a BufferedImage from it. I tried the following: BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); img.getRaster().setPixels(0, 0, width, height, pixels); But the resulting image has problems with the color bands.

IllegalArgumentException: Numbers of source Raster bands and source color space components do not match For a color image Exception

青春壹個敷衍的年華 提交于 2020-01-10 10:15:32
问题 The above answer that someone has suggest, converts my colored image to a black and white one. So it's not appropriate for my question. File file = new File("path"); BufferedImage bufferedImage = ImageIO.read( file ); here is the code and below is the image. Download the image and save in your pc. And try to run the above code with a correct value of path, it will throw an exception in the topic Download image: https://skydrive.live.com/?cid=19547371C4F3B839&id=19547371C4F3B839%21105 Simply

Write text into a JTextPane with an image background

旧时模样 提交于 2020-01-10 06:07:52
问题 I have a JTextPane with an image for its background. prevWords = new JTextPane() { public void paint(Graphics g) { BufferedImage img; try { img = ImageIO.read(new File("Images/logo.png")); img.getGraphics().setColor(new Color(Color.TRANSLUCENT)); g.drawImage(img, 0, 0, null); } catch (IOException e) { System.out.println("Failed to load logo."); } super.paintComponents(g); } }; When I write text to the the pane, it I cannot see it. I have set the text in pane to be white as well. 回答1: This is

Write text into a JTextPane with an image background

无人久伴 提交于 2020-01-10 06:07:20
问题 I have a JTextPane with an image for its background. prevWords = new JTextPane() { public void paint(Graphics g) { BufferedImage img; try { img = ImageIO.read(new File("Images/logo.png")); img.getGraphics().setColor(new Color(Color.TRANSLUCENT)); g.drawImage(img, 0, 0, null); } catch (IOException e) { System.out.println("Failed to load logo."); } super.paintComponents(g); } }; When I write text to the the pane, it I cannot see it. I have set the text in pane to be white as well. 回答1: This is

How to draw a BufferedImage with a color tint

白昼怎懂夜的黑 提交于 2020-01-10 05:31:05
问题 I'm trying to draw a BufferedImage to my Canvas with a varying color tint, but can't find any real working examples. I don't want to generate a new tinted BufferedImage , but repeatedly draw a BufferedImage to my GUI in real time with varying color tints, depending on various conditions. An image drawn with a tint color of 0xFF0000 will be drawn as a red-only image, while a tint color of 0xFFFFFF won't affect the image. How would I accomplish such a thing using the Graphics2D instance of my

How to convert BufferedImage to InputStream? [duplicate]

◇◆丶佛笑我妖孽 提交于 2020-01-10 01:15:11
问题 This question already has answers here : How to get an InputStream from a BufferedImage? (3 answers) Closed 2 months ago . I am uploading images using servlet. To perform resize operations i am converting InputStream to BufferedImage. Now i want to save it in mongoDB. Since, i am new to mongoDB as far as i know, GridFS takes InputStream. So, is there any way to convert BufferedImage to InputStream? 回答1: You need to save the BufferedImage to a ByteArrayOutputStream using the ImageIO class,

Manipulate an image without deleting its EXIF data

一个人想着一个人 提交于 2020-01-09 09:09:42
问题 Using imageIO, I usually have the problem of transforming an image file, and after overwriting it, it loses all of its EXIF data. Is there any way to preserve it without first extracting it, caching it, and then resetting it? 回答1: ImageIO do have this functionality itself, but instead of ImageIO.read you will need to use ImageReader: ImageReader reader = ImageIO.getImageReadersBySuffix("jpg").next(); (you may want to also check if such reader exists). Then you need to set the input: reader