• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with image files

 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in my program i can save an image file. if i open it using my program it looks fine, but when using microsoft paint or window picture viewer they do not. .jpg often looks like you are looking at the picture through an orange stained glass window. images with transparent backgrounds sometimes have black backgrounds. they all look fine in my program. here is some code if it helps
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

here is some code if it helps



No it doesn't help. You post code that shows how you use a JFileChooser.

We have no idea how you actually create your BufferedImage.

Once again, if you want help post a SSCCE that demonstrates the problem!!!
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Randall,

contrary to Rob, I find your code clear enough.

The problem is that the JP(E)G format does not support transparency. If you have a bufferedimage, say of TYPE_INT_ARGB, and if some of
your pixels are (partly) transparent, then if you save this BI as a jpg you see all those distorted colors. I have experienced this same problem,
and the only way out for me was to always save such a BI as a PNG, accepting the much larger file size.

In your code, you take the save-filetype from the file that the user selects, so you have to change that in some way.

Greetings,
Piet

PS: if you load a picture with a transparent background into Paint, then you do see this background in black. That's just Paints way of showing it.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for the answers. i noticed the browser also shows the colors distorted. in one case, all i did was open a .jpg, crop it, then save as .jpg
i probably did set the type as ARGB though. i will test it some more. so far it looks like save as .png and/or only use type ARGB when necessary
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, i have it mostly fixed. i had to make a change to DrawingArea's creatImage() method to determine which type of BufferedImage to create. and i changed FileHelper's save() method to check the type of the image passed to it, and if it is TYPE_ARGB, i make the user save it as a png. this all works just fine as far as it goes. i could open a jpg, make its background transparent and when i try to save it, it insists on png. however, if i then open that png file and try to save it as jpg, the program lets me do it. same problem with copy/paste.
 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what exactly you are doing.

First: if I load an image, I do not describe some particular type of BufferedImage; I just let that being handled by whatever mechanism Java uses for this. For instance, part of some of my code is:



As you can see, there's nothing specific about the bufferedimage I'm using here. I have no idea whether it's a 'TYPE_INT_ARGB'
or whatever.

The second way that I use in this program is in the method 'creeer_origineel' (see line 16):



I use a BI called 'bi_EchteOrigineel', which I either set to the just loaded
tempBuf, so I have no idea what actual type of BI this is, or else
I create a TYPE_INT_ARGB, and use this to paint some other BI
into it.

Now, when using transparency and then saving it as JPG, is asking for trouble; so in that case
I save it as PNG; otherwise, saving it as JPG works perfectly for me.

You write:

i could open a jpg, make its background transparent and when i try to save it, it insists on png. however,
if i then open that png file and try to save it as jpg, the program lets me do it. same problem with copy/paste.



Are you saying there's a bug in your program? If not, what exactly is the problem you're having?

Piet

PS: Shouldn't you start any new sentence with a capitalized letter? Not doing this makes the reading rather unpleasant, IMHO.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no real problem anymore. i only have to create a BufferedImage when drawing, cropping, or superimposing one image on another. here is the code

then when saving i have this code

i also added a help menu item

i am now wondering about transparent gif's though. i have been kind of ignoring gif's. but i can figure that out i think.
 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Randall,

nice coding.

One remark: if your BI is of TYPE_INT_ARGB, then saving it as jpg is okay if there are no transparent pixels.
You might want to keep track of this, and then the error message dialog wouldn't be always necessary.

I don't know anything of GIF files, other than that you can import them in Java, that the format is old fashioned
and that PNG's should be used. If you discover any problems with GIF's I would be interested to hear.

Greetings,
Piet
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hmm...this is kind of strange. if i make a transparent background and save as gif or png it works ok. if i fade an image, it saves good as png but when saving as gif the entire image is blank
well i already jarred it up so i am done for the time being. you can get it if you want from a thread i started in the meaningless drivel forum
 
reply
    Bookmark Topic Watch Topic
  • New Topic