Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Problem with colours when writing BufferedImage to file  (Read 2710 times)
0 Members and 1 Guest are viewing this topic.
Offline King_of_Men

Senior Newbie




EUII player


« Posted 2006-01-08 00:53:44 »

I have made a little Java snippet to load some image files, combine them together into a single image, and write them to file. Now, when I display the BufferedImage that is internal to my application, it looks fine, very nice primary colours. But when I write to file and inspect the resulting jpg, I get a fairly weird set of colours. Does anyone know what the problem might be? Perhaps I need to specify what colour model I am using, to the ImageWriter object? I'm using the ImageIO.write(BufferedImage, String, OutputStream) method.

(Incidentally, has anyone else noticed how easy it is to miss the 'f' key and write BuggeredImage instead?)

To win one hundred victories, in one hundred battles, is not the acme of skill. To subdue the enemy without fighting is the acme of skill.
Offline Grand Poeba

Junior Member





« Reply #1 - Posted 2006-01-08 10:51:34 »

I have made a little Java snippet to load some image files, combine them together into a single image, and write them to file. Now, when I display the BufferedImage that is internal to my application, it looks fine, very nice primary colours. But when I write to file and inspect the resulting jpg, I get a fairly weird set of colours. Does anyone know what the problem might be? Perhaps I need to specify what colour model I am using, to the ImageWriter object? I'm using the ImageIO.write(BufferedImage, String, OutputStream) method.

(Incidentally, has anyone else noticed how easy it is to miss the 'f' key and write BuggeredImage instead?)

maybe something is wrong with ur outputstream?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2006-01-08 12:34:53 »

Well, this might not be very helpful, but I have this too. Writing in PNG format is ok, but in JPG the colors get an orange/pink shade over them. I just write RGB or ARGB BufferedImages, so I that is a pretty standard case.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline g666

Junior Member





« Reply #3 - Posted 2006-01-08 20:42:16 »

Well some image quiality loss in jpg is to be excepected as its lossy compression so u dont get pixel perfect reproduction.

desperately seeking sanity
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2006-01-08 21:46:47 »

Eh............. I didn't think that a pink/orange pic was considered quality-loss.

Have you actually read the thread?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline King_of_Men

Senior Newbie




EUII player


« Reply #5 - Posted 2006-01-09 00:48:47 »

More information : I tried making a png (which indeed works) for comparison. Then I uploaded the png and jpg versions to Photobucket so people could see what the problem was. However, my browser refuses to display the jpeg version; I just get the little red cross. I find this exceedingly weird, since my windows Picture Viewer does display it, even if it is in weird colours.

To win one hundred victories, in one hundred battles, is not the acme of skill. To subdue the enemy without fighting is the acme of skill.
Offline tusaki

Junior Member


Medals: 1


In a mad world only the mad are sane.


« Reply #6 - Posted 2006-01-09 10:19:03 »

The problem is with the image type of your bufferedimage, the ImageIO JPEG compressor needs a BufferedImage.TYPE_INT_RGB image. When you provide a BufferedImage.TYPE_INT_ABGR or BufferedImage.TYPE_INT_ARGB you will get the weird results you are seeing now. If you need to use ABGR or ARGB in your program, just create a new RGB bufferedimage and Graphics.drawImage() the ARGB/ABGR image on that and write the RGB image away.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2006-01-09 10:36:27 »

Doh Grin Embarrassed

There is no point in having A in a JPG anyway... Thanks.

Still a bit weird that ImageIO doesn't take care of this automagicly.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline King_of_Men

Senior Newbie




EUII player


« Reply #8 - Posted 2006-01-10 05:08:20 »

Ah, that was it. Thanks. Oddly enough, though, I manage to run out of heap space when drawing to the Graphics object. Never seen that in a program without bugs. I had to scale my image by 0.5 before it would fit in memory.  Undecided

To win one hundred victories, in one hundred battles, is not the acme of skill. To subdue the enemy without fighting is the acme of skill.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 799
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #9 - Posted 2006-01-10 14:25:21 »

In case you don't know yet, enlarge the maximum heap-space with -mx128M as vm-argument.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (19 views)
2014-09-21 02:42:18

BurntPizza (14 views)
2014-09-21 01:30:30

moogie (14 views)
2014-09-21 00:26:15

UprightPath (25 views)
2014-09-20 20:14:06

BurntPizza (27 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (73 views)
2014-09-10 13:57:51

TehJavaDev (96 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!