11 Replies - 5684 Views - Last Post: 20 July 2010 - 04:52 PM Rate Topic: -----

#1 prelic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 13-February 07

Problem with Buffered Image setRGB

Posted 19 July 2010 - 10:56 AM

Hey all,

So I'm having trouble setting a pixel of a BufferedImage. Here's the basic idea of what's happening:

//newpixel = 0x195f3259
//buffimage.getRGB(0,0) = 0xff5f3529

buffimage.setRGB(0,0,newpixel);

int result = buffimage.getRGB(0,0); //should be 0x195f3259, but its still 0xff5f3529




So basically setRGB is clearly failing. However, I have no idea why...would greatly appreciate some help on this.

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with Buffered Image setRGB

#2 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2111
  • View blog
  • Posts: 8,790
  • Joined: 20-September 08

Re: Problem with Buffered Image setRGB

Posted 19 July 2010 - 01:46 PM

Sorry, that value looks pretty odd. The maximum value allowed would be 0xFF
Was This Post Helpful? 0
  • +
  • -

#3 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 516
  • View blog
  • Posts: 5,588
  • Joined: 20-March 08

Re: Problem with Buffered Image setRGB

Posted 19 July 2010 - 01:53 PM

@g00se, I'm not exactly familiar with this, but shouldn't the max be 0xFFFFFF? Or am I wrong...? :unsure:

Wouldn't it work similarly to the [color] tag here on DIC? With 2 hex digits for each of Red, Green, and Blue, the max of each could be 0xFF?

Edit: Duh. It's still giving prelic over the max, as it's giving him 8 hex digits. :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 9037
  • View blog
  • Posts: 33,523
  • Joined: 27-December 08

Re: Problem with Buffered Image setRGB

Posted 19 July 2010 - 01:55 PM

I agree with Locke here. I think the problem is that an 8-digit hex value is used here: 0xff5f3529, rather than a 6-digit hex value.
Was This Post Helpful? 0
  • +
  • -

#5 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 516
  • View blog
  • Posts: 5,588
  • Joined: 20-March 08

Re: Problem with Buffered Image setRGB

Posted 19 July 2010 - 01:59 PM

I just noticed that. On first glance, I was like, "the value is fine...I don't get it". Then I realized it was 8 digits. :/
Was This Post Helpful? 0
  • +
  • -

#6 g00se  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2111
  • View blog
  • Posts: 8,790
  • Joined: 20-September 08

Re: Problem with Buffered Image setRGB

Posted 19 July 2010 - 02:00 PM

Sorry - you're right 0xFFFFFFFF
Was This Post Helpful? 0
  • +
  • -

#7 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 516
  • View blog
  • Posts: 5,588
  • Joined: 20-March 08

Re: Problem with Buffered Image setRGB

Posted 19 July 2010 - 02:01 PM

6 digits, though...not 8. ;)
Was This Post Helpful? 0
  • +
  • -

#8 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2696
  • View blog
  • Posts: 10,556
  • Joined: 15-July 08

Re: Problem with Buffered Image setRGB

Posted 19 July 2010 - 04:36 PM

View PostLocke, on 19 July 2010 - 04:01 PM, said:

6 digits, though...not 8. ;)


The API says:

Quote

int getRGB(int x, int y)
Returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace.


Notice the constant...ARGB

Quote

static int TYPE_INT_ARGB
Represents an image with 8-bit RGBA color components packed into integer pixels.


8 bits...not 6
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8022
  • View blog
  • Posts: 31,148
  • Joined: 06-March 08

Re: Problem with Buffered Image setRGB

Posted 19 July 2010 - 07:40 PM

8 bits Alpha
8 bits Red
8 bits Green
8 bits Blue

@OP what is your BufferedImage image type ?
Was This Post Helpful? 0
  • +
  • -

#10 prelic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 13-February 07

Re: Problem with Buffered Image setRGB

Posted 20 July 2010 - 10:08 AM

I've been using values where the least significant 6-bits (hex) never change, but after some more testing, I've found that setRGB() is working, but it automatically masks my upper 2 bits (hex) to 0xff, which leads me to believe my bufferedimage doesn't support transparency. Ideally, I'd like my image to not support transparency, allowing me to modify the upper 2 bits without modifying how the image is displayed, but I don't think that's possible. If the buffimage doesn't support transparency (rgb vs argb), then the alpha values are auto-masked to 0xff..unforunately
Was This Post Helpful? 0
  • +
  • -

#11 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2696
  • View blog
  • Posts: 10,556
  • Joined: 15-July 08

Re: Problem with Buffered Image setRGB

Posted 20 July 2010 - 12:21 PM

Look here: http://download.orac...l#field_summary

Those are the different options that you have
Was This Post Helpful? 0
  • +
  • -

#12 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8022
  • View blog
  • Posts: 31,148
  • Joined: 06-March 08

Re: Problem with Buffered Image setRGB

Posted 20 July 2010 - 04:52 PM

View Postprelic, on 20 July 2010 - 11:08 AM, said:

which leads me to believe my bufferedimage doesn't support transparency.

This is why I asked you 2 posts ago: what type of BufferedImage do you use ?

This post has been edited by pbl: 20 July 2010 - 04:53 PM
Reason for edit:: typo

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1