• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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++;
}
 
Rancher
Posts: 43026
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic