Hello Iffi,

the following is some code which i use to extract the pixels from a buffered
image. This may be of use to you. The parameters are the buffered image, a
set of ranges for each of the red, green and blue components, and a default
colour. The function is a filter operation on each of the red , green and
blue components of the pixel,

regards,
sean
--
Honours Student,
Computer Vision Group,
Dept. of Computer Science,
Adelaide University, South Australia.

public static BufferedImage filterHSB(BufferedImage b,
                                        boolean filterWithin,
                                        float h1, float h2,
                                        float s1, float s2,
                                        float b1, float b2,
                                        int[] defaultRGBColor) {

      // store the image data in the raster
    Raster r = b.getData();
    int width = b.getWidth();
    int height = b.getHeight();
    int[] pixel = new int[3];
    float[] hsb = new float[3];
    BufferedImage buff2 = new BufferedImage(width, height,
                                            BufferedImage.TYPE_INT_RGB);
    WritableRaster w = buff2.getData().createCompatibleWritableRaster();


    if(filterWithin) {

      for (int x =0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            // pixel is an array of 3 entries, one for each of the rgb pixel
components
          pixel = r.getPixel(x,y,pixel);

          // hsb is an array of 3 entries
          hsb = Color.RGBtoHSB(pixel[0],pixel[1],pixel[2],hsb);
          if (hsb[0] >= h1) {
            if (hsb[0] <= h2)
              if (hsb[1] >= s1)
                if(hsb[1] <= s2)
                  if(hsb[2] >= b1)
                    if(hsb[2] <= b2)
                      w.setPixel(x,y,defaultRGBColor);
          }else {
            w.setPixel(x,y,pixel);
          }
        }
      }
    } else {

      for (int x =0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          pixel = r.getPixel(x,y,pixel);
          hsb = Color.RGBtoHSB(pixel[0],pixel[1],pixel[2],hsb);
          if (hsb[0] >= h1) {
            if (hsb[0] <= h2)
              if (hsb[1] >= s1)
                if(hsb[1] <= s2)
                  if(hsb[2] >= b1)
                    if(hsb[2] <= b2)
                      w.setPixel(x,y,pixel);
          }else {
            w.setPixel(x,y,defaultRGBColor);
          }
        }
      }
    }

    buff2.setData(w);
    return buff2;
  }


> -----Original Message-----
> From: Discussion list for Java 2D API
> [mailto:[EMAIL PROTECTED]]On Behalf Of Muhammad Irfan Paracha
> Sent: Saturday, September 16, 2000 12:12 PM
> To: [EMAIL PROTECTED]
> Subject: [JAVA2D] Pixels of Text!
>
>
> Hello,
>
>
> How can I get Pixels on which a String is Drawn ?
>
> regards,
> Iffi
>
> ==================================================================
> =========
> To unsubscribe, send email to [EMAIL PROTECTED] and include
> in the body
> of the message "signoff JAVA2D-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to