getRGB(x,y) in Java awt returns for each pixel same valueIs Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?How does the Java 'for each' loop work?How to get an enum value from a string value in Java?Does Java support default parameter values?How do I determine whether an array contains a particular value in Java?BufferedImage pixel value issueCan't start Eclipse - Java was started but returned exit code=13java Buffered image gray levelTinting pixels in Java - Need a faster method

Improving an O(N^2) function (all entities iterating over all other entities)

How many opportunity attacks can you make per turn before becoming exhausted?

Last-minute canceled work-trip mean I'll lose thousands of dollars on planned vacation

How do I reproduce this layout and typography?

Detecting existence of a class member

Why don't humans perceive waves as twice the frequency they are?

Demographic consequences of closed loop reincarnation

Do pedestrians imitate auto traffic?

Manager asking me to eat breakfast from now on

Why did my "seldom" get corrected?

Can error correction and detection be done without adding extra bits?

How would you say "Sorry, that was a mistake on my part"?

Is it possible to have a career in SciComp without contributing to arms research?

Applying for jobs with an obvious scar

What is a Romeo Word™?

What could make large expeditions ineffective for exploring territory full of dangers and valuable resources?

"Je suis petite, moi?", purpose of the "moi"?

Left crank keeps coming loose

I have found a mistake on someone's code published online: what is the protocol?

Why do space operations use "nominal" to mean "working correctly"?

Inscriptio Labyrinthica

How did Jayne know when to shoot?

Data visualisation: Pie charts with really small values

What happens if a company buys back all of its shares?



getRGB(x,y) in Java awt returns for each pixel same value


Is Java “pass-by-reference” or “pass-by-value”?How do I efficiently iterate over each entry in a Java Map?How does the Java 'for each' loop work?How to get an enum value from a string value in Java?Does Java support default parameter values?How do I determine whether an array contains a particular value in Java?BufferedImage pixel value issueCan't start Eclipse - Java was started but returned exit code=13java Buffered image gray levelTinting pixels in Java - Need a faster method






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-5















I tried to walk through an image and take each RGB color value from all pixels and process them. But I get for all pixels the same RGB value. So obviously that is wrong.



I used the getRGB(x,y) method of an bufferedimage object in Java awt.
Know anyone what's the problem here?



Edit:



I got the problem, there were some mistakes by converting the image to an buffered image. I didn't draw the image in the in the buffered image.
The Following code working now as intended.



 public void printImgDetails(Image img) 

// get the sizes of the image
long heigth = img.getHeight(null);
long width = img.getWidth(null);

// hashSet to hold all brightness values
HashSet<Float> set = new HashSet<Float>(0);

BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_BYTE_GRAY);
int rgb;
float[] hsv = new float[3];

// Draw the image on to the buffered image
Graphics2D bGr = bimage.createGraphics();
bGr.drawImage(img, 0, 0, null);
bGr.dispose();

for (int i = 0; i < width; i++)
for (int j = 0; j < heigth; j++)
Color c = new Color(bimage.getRGB(j, i));

int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();

Color.RGBtoHSB(r, g, b, hsv);
System.out.println("r: " + r + " g: " + g + " b: " + b);
set.add(hsv[2]);



// calculate the average brightness
double sum = 0;
for (float x : set)
sum += x;

double avg = sum / set.size();

// print the results
System.out.println("avg --> " + avg);




Thanks in advance.










share|improve this question



















  • 5





    A guess: the problem is somewhere in your code ... right there, see it? Seriously: how are we supposed to help if you don't even show any code? And did you step through your code with a debugger yet?

    – Thomas
    Mar 26 at 10:40












  • please read How to Ask

    – Piglet
    Mar 26 at 10:47











  • first thanks for your answer, here is the code and of corse Id step trough with a debugger. But now it is working

    – Sebastian T
    Mar 26 at 19:53

















-5















I tried to walk through an image and take each RGB color value from all pixels and process them. But I get for all pixels the same RGB value. So obviously that is wrong.



I used the getRGB(x,y) method of an bufferedimage object in Java awt.
Know anyone what's the problem here?



Edit:



I got the problem, there were some mistakes by converting the image to an buffered image. I didn't draw the image in the in the buffered image.
The Following code working now as intended.



 public void printImgDetails(Image img) 

// get the sizes of the image
long heigth = img.getHeight(null);
long width = img.getWidth(null);

// hashSet to hold all brightness values
HashSet<Float> set = new HashSet<Float>(0);

BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_BYTE_GRAY);
int rgb;
float[] hsv = new float[3];

// Draw the image on to the buffered image
Graphics2D bGr = bimage.createGraphics();
bGr.drawImage(img, 0, 0, null);
bGr.dispose();

for (int i = 0; i < width; i++)
for (int j = 0; j < heigth; j++)
Color c = new Color(bimage.getRGB(j, i));

int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();

Color.RGBtoHSB(r, g, b, hsv);
System.out.println("r: " + r + " g: " + g + " b: " + b);
set.add(hsv[2]);



// calculate the average brightness
double sum = 0;
for (float x : set)
sum += x;

double avg = sum / set.size();

// print the results
System.out.println("avg --> " + avg);




Thanks in advance.










share|improve this question



















  • 5





    A guess: the problem is somewhere in your code ... right there, see it? Seriously: how are we supposed to help if you don't even show any code? And did you step through your code with a debugger yet?

    – Thomas
    Mar 26 at 10:40












  • please read How to Ask

    – Piglet
    Mar 26 at 10:47











  • first thanks for your answer, here is the code and of corse Id step trough with a debugger. But now it is working

    – Sebastian T
    Mar 26 at 19:53













-5












-5








-5








I tried to walk through an image and take each RGB color value from all pixels and process them. But I get for all pixels the same RGB value. So obviously that is wrong.



I used the getRGB(x,y) method of an bufferedimage object in Java awt.
Know anyone what's the problem here?



Edit:



I got the problem, there were some mistakes by converting the image to an buffered image. I didn't draw the image in the in the buffered image.
The Following code working now as intended.



 public void printImgDetails(Image img) 

// get the sizes of the image
long heigth = img.getHeight(null);
long width = img.getWidth(null);

// hashSet to hold all brightness values
HashSet<Float> set = new HashSet<Float>(0);

BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_BYTE_GRAY);
int rgb;
float[] hsv = new float[3];

// Draw the image on to the buffered image
Graphics2D bGr = bimage.createGraphics();
bGr.drawImage(img, 0, 0, null);
bGr.dispose();

for (int i = 0; i < width; i++)
for (int j = 0; j < heigth; j++)
Color c = new Color(bimage.getRGB(j, i));

int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();

Color.RGBtoHSB(r, g, b, hsv);
System.out.println("r: " + r + " g: " + g + " b: " + b);
set.add(hsv[2]);



// calculate the average brightness
double sum = 0;
for (float x : set)
sum += x;

double avg = sum / set.size();

// print the results
System.out.println("avg --> " + avg);




Thanks in advance.










share|improve this question
















I tried to walk through an image and take each RGB color value from all pixels and process them. But I get for all pixels the same RGB value. So obviously that is wrong.



I used the getRGB(x,y) method of an bufferedimage object in Java awt.
Know anyone what's the problem here?



Edit:



I got the problem, there were some mistakes by converting the image to an buffered image. I didn't draw the image in the in the buffered image.
The Following code working now as intended.



 public void printImgDetails(Image img) 

// get the sizes of the image
long heigth = img.getHeight(null);
long width = img.getWidth(null);

// hashSet to hold all brightness values
HashSet<Float> set = new HashSet<Float>(0);

BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_BYTE_GRAY);
int rgb;
float[] hsv = new float[3];

// Draw the image on to the buffered image
Graphics2D bGr = bimage.createGraphics();
bGr.drawImage(img, 0, 0, null);
bGr.dispose();

for (int i = 0; i < width; i++)
for (int j = 0; j < heigth; j++)
Color c = new Color(bimage.getRGB(j, i));

int r = c.getRed();
int g = c.getGreen();
int b = c.getBlue();

Color.RGBtoHSB(r, g, b, hsv);
System.out.println("r: " + r + " g: " + g + " b: " + b);
set.add(hsv[2]);



// calculate the average brightness
double sum = 0;
for (float x : set)
sum += x;

double avg = sum / set.size();

// print the results
System.out.println("avg --> " + avg);




Thanks in advance.







java image-processing awt rgb






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 19:56







Sebastian T

















asked Mar 26 at 10:38









Sebastian TSebastian T

234 bronze badges




234 bronze badges







  • 5





    A guess: the problem is somewhere in your code ... right there, see it? Seriously: how are we supposed to help if you don't even show any code? And did you step through your code with a debugger yet?

    – Thomas
    Mar 26 at 10:40












  • please read How to Ask

    – Piglet
    Mar 26 at 10:47











  • first thanks for your answer, here is the code and of corse Id step trough with a debugger. But now it is working

    – Sebastian T
    Mar 26 at 19:53












  • 5





    A guess: the problem is somewhere in your code ... right there, see it? Seriously: how are we supposed to help if you don't even show any code? And did you step through your code with a debugger yet?

    – Thomas
    Mar 26 at 10:40












  • please read How to Ask

    – Piglet
    Mar 26 at 10:47











  • first thanks for your answer, here is the code and of corse Id step trough with a debugger. But now it is working

    – Sebastian T
    Mar 26 at 19:53







5




5





A guess: the problem is somewhere in your code ... right there, see it? Seriously: how are we supposed to help if you don't even show any code? And did you step through your code with a debugger yet?

– Thomas
Mar 26 at 10:40






A guess: the problem is somewhere in your code ... right there, see it? Seriously: how are we supposed to help if you don't even show any code? And did you step through your code with a debugger yet?

– Thomas
Mar 26 at 10:40














please read How to Ask

– Piglet
Mar 26 at 10:47





please read How to Ask

– Piglet
Mar 26 at 10:47













first thanks for your answer, here is the code and of corse Id step trough with a debugger. But now it is working

– Sebastian T
Mar 26 at 19:53





first thanks for your answer, here is the code and of corse Id step trough with a debugger. But now it is working

– Sebastian T
Mar 26 at 19:53












2 Answers
2






active

oldest

votes


















0














If you get the same values for every pixel there are several possible reasons.



a) your image has the same values in every pixel



b) you do not change x and y between your calls to getRGB



c) you read something else but the return value of getRGB






share|improve this answer






























    0














    As I wirte in the edit, there was an problem by converting between image and bufferedimage. I forgot to draw image into the bufferediamge. Thats it.






    share|improve this answer


















    • 2





      consider deleting your question. I doubt it's of any use to anyone

      – Piglet
      Mar 26 at 22:10













    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55355074%2fgetrgbx-y-in-java-awt-returns-for-each-pixel-same-value%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    If you get the same values for every pixel there are several possible reasons.



    a) your image has the same values in every pixel



    b) you do not change x and y between your calls to getRGB



    c) you read something else but the return value of getRGB






    share|improve this answer



























      0














      If you get the same values for every pixel there are several possible reasons.



      a) your image has the same values in every pixel



      b) you do not change x and y between your calls to getRGB



      c) you read something else but the return value of getRGB






      share|improve this answer

























        0












        0








        0







        If you get the same values for every pixel there are several possible reasons.



        a) your image has the same values in every pixel



        b) you do not change x and y between your calls to getRGB



        c) you read something else but the return value of getRGB






        share|improve this answer













        If you get the same values for every pixel there are several possible reasons.



        a) your image has the same values in every pixel



        b) you do not change x and y between your calls to getRGB



        c) you read something else but the return value of getRGB







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 10:45









        PigletPiglet

        9,0982 gold badges11 silver badges23 bronze badges




        9,0982 gold badges11 silver badges23 bronze badges























            0














            As I wirte in the edit, there was an problem by converting between image and bufferedimage. I forgot to draw image into the bufferediamge. Thats it.






            share|improve this answer


















            • 2





              consider deleting your question. I doubt it's of any use to anyone

              – Piglet
              Mar 26 at 22:10















            0














            As I wirte in the edit, there was an problem by converting between image and bufferedimage. I forgot to draw image into the bufferediamge. Thats it.






            share|improve this answer


















            • 2





              consider deleting your question. I doubt it's of any use to anyone

              – Piglet
              Mar 26 at 22:10













            0












            0








            0







            As I wirte in the edit, there was an problem by converting between image and bufferedimage. I forgot to draw image into the bufferediamge. Thats it.






            share|improve this answer













            As I wirte in the edit, there was an problem by converting between image and bufferedimage. I forgot to draw image into the bufferediamge. Thats it.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 26 at 20:02









            Sebastian TSebastian T

            234 bronze badges




            234 bronze badges







            • 2





              consider deleting your question. I doubt it's of any use to anyone

              – Piglet
              Mar 26 at 22:10












            • 2





              consider deleting your question. I doubt it's of any use to anyone

              – Piglet
              Mar 26 at 22:10







            2




            2





            consider deleting your question. I doubt it's of any use to anyone

            – Piglet
            Mar 26 at 22:10





            consider deleting your question. I doubt it's of any use to anyone

            – Piglet
            Mar 26 at 22:10

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55355074%2fgetrgbx-y-in-java-awt-returns-for-each-pixel-same-value%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Obelisk of Theodosius Contents History Description Notes Bibliography Further reading External links Navigation menuAge of spirituality : late antique and early Christian art, third to seventh centuryOver 60 picturesObelisks of the World41°00′21.24″N 28°58′31.43″E / 41.0059000°N 28.9753972°E / 41.0059000; 28.97539727724550-7235741376235741376

            밀양 대씨 역사 각주 함께 보기 둘러보기 메뉴밀양 대씨

            1973년 목차 사건 문화 탄생 사망 노벨상 달력 둘러보기 메뉴