• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I display an int[] of RBG value in Swing?  RSS feed

 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If I have an int[] of RBG value of an image, how can I display that in Swing?

Thank you.
 
David McCombs
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you want to display it? As a color, or just print out the numeric values?
 
arulk pillai
Author
Ranch Hand
Posts: 3417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Look at the API for java.awt.Color and there should be other constructors to construct the color object.


http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Color.html
 
ying lam
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. But what if I have a rgb int [] of an image?

In J2me, there is a function like this, I want to do the same in j2SE:

public static Image createRGBImage(int[] rgb,
int width,
int height,
boolean processAlpha)

Creates an immutable image from a sequence of ARGB values, specified as 0xAARRGGBB. The ARGB data within the rgb array is arranged horizontally from left to right within each row, row by row from top to bottom. If processAlpha is true, the high-order byte specifies opacity; that is, 0x00RRGGBB specifies a fully transparent pixel and 0xFFRRGGBB specifies a fully opaque pixel. Intermediate alpha values specify semitransparency. If the implementation does not support alpha blending for image rendering operations, it must replace any semitransparent pixels with fully transparent pixels. (See Alpha Processing for further discussion.) If processAlpha is false, the alpha values are ignored and all pixels must be treated as fully opaque.

Consider P(a,b) to be the value of the pixel located at column a and row b of the Image, where rows and columns are numbered downward from the top starting at zero, and columns are numbered rightward from the left starting at zero. This operation can then be defined as:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!