• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

pixels and RGB of a .png file

 
Greenhorn
Posts: 4
VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 233
1
Eclipse IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



hello!

kind regards
 
Mano Wilk
Greenhorn
Posts: 4
VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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�
 
Rancher
Posts: 43081
77
  • 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 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.
 
Mano Wilk
Greenhorn
Posts: 4
VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic