| | |
|
Working with RGB (Red,Green, Blue) to create
Image that is created by setting R, G, B
value in a array bits.
By creating ColorModel and changing image bits
to MemoryImageSource for creating an image in
memory and displaying this on Applet.
|
Steps includes:
1. creating a ColorModel as follows:
ColorModel colorModel=ColorModel.getRGBdefault();
2. Creating values of different colors such as red, green,
red, white, black.
int r=new Color(255,0,0).getRGB();
int g=new Color(0,255,0).getRGB();
int b=new Color(0,0,255).getRGB();
int w=new Color(255,255,255).getRGB();
int bl=new Color(0,0,0).getRGB();
3. Creating the image bits in an array as follows:
int[] imageBits = new int[] {
w,w,w,w,w,w,w,w,w,w,w,w,w,
w,w,w,w,w,w,w,w,w,w,w,w,w,
w,w,w,w,b,b,b,b,b,w,w,w,w,
w,w,w,w,b,b,b,b,b,w,w,w,w,
w,w,w,w,b,b,b,b,b,w,w,w,w,
w,w,g,g,g,g,b,b,b,w,w,w,w,
w,w,g,g,g,g,b,b,b,w,w,w,w,
w,w,g,g,g,g,w,w,w,w,w,w,w,
r,r,g,g,g,g,w,w,w,w,w,w,w,
r,r,r,w,w,w,w,w,w,w,w,w,w,
r,r,r,w,w,w,w,w,w,w,w,w,w,
w,w,w,w,w,w,w,w,w,w,w,w,w,
w,w,w,w,w,w,w,w,w,w,w,w,w,
};
4. Creating MemoryImageSource by passing ColorModel
and imageBits as,
MemoryImageSource mis = new MemoryImageSource
(13,12,colorModel,imageBits, 0,13);
5. creating Image by using MemoryImageSource.
img = createImage(mis);
6. Displaying this image on Applet
public void paint(Graphics g)
{
g.drawImage(img,10,10,40,40,this);
}
| |