This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes pixels and RGB of a .png file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "pixels and RGB of a .png file" Watch "pixels and RGB of a .png file" New topic
Author

pixels and RGB of a .png file

Mano Wilk
Greenhorn

Joined: Jan 06, 2013
Posts: 4

hello everyone,

i started learning java last night. i had a previous little knowledge with c++, somewhere in the past.

i am doing an exercise where i load a black picture, change its RGB values and then i could see the hidden image. i have read much about filechooser and so...and finally i made it to get a little window asking me to choose a file.
now my ideas are too "loose" yet, and i am confused and dont know what to do.
I have seen many examples that do what i want.
It seems the right way is to count every pixel of the .png file? and using something similar to getRed, getBlue, getGreen for every i (means width) and j (height)?
so the idea is, e.g i have a 4x4 image, i.e 16 pixels (?) then i would use the getRed getBlue getGreen stuff to grab the RGB of each pixel? That means 16 data values?
so i would edit these 16 values, like *0,5 if i want to decrease the RGB level and so?
i cant understand how my code would ordenate all the pixels again at the end...
isnt there a way to get a data like "this is the RGB value of the image" instead of "those are the RGB values of every pixel"?
sorry if this is a too abstract question, but i dont know how to express my problem, as i said, i am rather confused.
and i apologize i dont have a code to post, but this part of the code i dont have yet. All the other parts are: creating object for the picture, loading a picture, showing a picture [here i should add the code to edit the RGB values] and then save this new picture somewhere. and i dont think they would help in this part...
Rajdeep Biswas
Ranch Hand

Joined: Mar 26, 2012
Posts: 186

Welcome to the Ranch. Can you give some pseudocode or dumb text how you have done so far and what are the results?
Mano Wilk
Greenhorn

Joined: Jan 06, 2013
Posts: 4

Rajdeep Biswas wrote:Welcome to the Ranch. Thats all for now!


hello!

kind regards
Mano Wilk
Greenhorn

Joined: Jan 06, 2013
Posts: 4

Rajdeep Biswas wrote:Welcome to the Ranch. Can you give some pseudocode or dumb text how you have done so far and what are the results?


yes, i will try



so, i believe where "here are the things done" i should tell the program to the following:



thank you
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4572
    
    5

Mano Wilk, please BeForthrightWhenCrossPostingToOtherSites <- link
http://www.java-forums.org/new-java/67360-pixels-rgb-png-file.html#post317071
https://forums.oracle.com/forums/thread.jspa?messageID=10777646�


luck, db
There are no new questions, but there may be new answers.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42047
    
  64
I'm not sure what the "Picture" class does, but I would use the javax.imageio.ImageIO class to read and write the image; it provides you with a BufferedImage object that you can use to get and set individual pixel values.

Note that the R, G, B and alpha values of a particular pixel are encoded in a single int value, so you need to do some bitwise arithmetic to extract (and later reassemble) them from the int.


Ping & DNS - my free Android networking tools app
Mano Wilk
Greenhorn

Joined: Jan 06, 2013
Posts: 4

Ulf Dittmer wrote:I'm not sure what the "Picture" class does, but I would use the javax.imageio.ImageIO class to read and write the image; it provides you with a BufferedImage object that you can use to get and set individual pixel values.


thank you for the reply!
these are the methods of Pictures:


other class i think i should use is Pixels:


I am thinking in creating a pixel[i] and while i is smaller than my pixel numbers:



Note that the R, G, B and alpha values of a particular pixel are encoded in a single int value, so you need to do some bitwise arithmetic to extract (and later reassemble) them from the int.

I see. That means my "value" could not be used as i wrote and i should interpret it using arithmetic?

thanks for your time and
kind regards
 
GeeCON Prague 2014
 
subject: pixels and RGB of a .png file