aspose file tools*
The moose likes Applets and the fly likes getting the color of a particular pixel from an image loaded in applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "getting the color of a particular pixel from an image loaded in applet" Watch "getting the color of a particular pixel from an image loaded in applet" New topic
Author

getting the color of a particular pixel from an image loaded in applet

vartika srivastava
Greenhorn

Joined: Mar 08, 2007
Posts: 3
i have used the class PixelGrabber and been able to get the RGB componenet in to an array pixels...i want to b able to compare the color of a particular pixel with black...if the color is same then it must add to the array arr...can somebody help me? ihave pasted the code


private Image logo1;

int pixels[];
Color col[];
String msg;
int arr[];
int k=0;
public void init()
{
logo1=getImage(getDocumentBase(),"trial2.jpg");
int width=getWidth();
int height=getHeight();
pixels = new int[width*height];
PixelGrabber pg =
new PixelGrabber(logo1, 0, 0, width, height, pixels, 0, width);
try
{
pg.grabPixels();
}
catch (InterruptedException e) { }

col=new Color[width*height];
arr=new int[width*height];

for(int i=0;i<width*height;i++)
{
int c=pixels[i];
int red = (c & 0x00ff0000) >> 16;
int green = (c & 0x0000ff00) >> 8;
int blue = c & 0x000000ff;
col[i] = new Color(red,blue,green);
if(col[i]==Color.black)
{
arr[k]=i;
k++;
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
Welcome to JavaRanch.

The color black has r=0, g=0 and b=0. Since you already know how to access the RGB color components, comparing a color to black should be easy.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting the color of a particular pixel from an image loaded in applet