PixelGrabber + Import

1. What exactly does the PixelGrabber do? How can I use it(or another technology if better) to differentiate colors on a background for collision pupposes in a game?
2.How do I call methods and variables from one class in another. I know it should be simple, but I can't seem to find it anywhere, and don't know what words to use in a search term.

only for black and white, you could still construct the scenery with 2D and a general path which is pretty flexible and check for intersection. it hasn't to do with 3D.
but if you want to detect the pixel values, you can use the Raster() and DataBuffer classes in java.awt.image. with bufferedImages. check out the java2D forum for examples. I posted a reply exactly doing that a short while ago.
but depending on the size of your scrolling background you should really only check the areas you need (your current ship position for example), otherwise its going to be pretty slow.

Similar Messages

  • PixelGrabber - assistance with code needed

    Hello,
    I have been trying to get the color of a pixel on an image on a program for the past week. I have been advised to use pixelgrabber, and to save results in an array.
    I am trying to understand it by creating a new application just for the purpose of pixelgrabbing, and then coding it properly.
    Following the SUN Documentation, i have this code (no errors):
    package untitled2;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.Image;
    import java.awt.image.PixelGrabber;
    import java.awt.image.ImageObserver;
    import java.util.ArrayList;
    public class Frame1 extends JFrame {
        JPanel contentPane;
        BorderLayout borderLayout1 = new BorderLayout();
        public void handlesinglepixel(int x, int y, int pixel) {
                int alpha = (pixel >> 24) & 0xff;
                int red   = (pixel >> 16) & 0xff;
                int green = (pixel >>  8) & 0xff;
                int blue  = (pixel      ) & 0xff;
              // Deal with the pixel as necessary...
           public Frame1() {
            try {
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                jbInit();
            } catch (Exception exception) {
                exception.printStackTrace();
        private void jbInit() throws Exception {
            contentPane = (JPanel) getContentPane();
            contentPane.setLayout(borderLayout1);
            setSize(new Dimension(400, 300));
            setTitle("Frame Title");
    }Help needed:-
    1-Can some show me where to put the code to produce the appropriate image? (do i use normal/buffered/etc)
    2-Do i make an array and transfer the values of red,green,blue to postion [0][1][2]?
    3-I believe i need to convert the values to an int. How is this done?
    4-The "proper" program where this will be used will create multiple images based on user input. The images will be created via a loop.
    Are there any issues i should be aware of ? As i understand, each pixelgrabber is unique to each image.. If i have 1000 images will that mean 1000 pixelgrabbers? (slow performance).
    Where appropriate, if you could direct me to the relavent tutorial i am happy to read and learn, although i would need help as to the exact location to put the code. For question (1), as i am unsure of the exact image, i would prefer a piece of code (the image is accessed via "temp2.png").
    Regards
    David55

    UPDATE
    This code shows the rgb value of the image at a specific point (entered in code). all that is needed is to find coordinates within image.
    Can anyone help clean code or offer advice?
    package untitled2;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import java.awt.Image;
    import java.awt.image.PixelGrabber;
    import java.awt.image.ImageObserver;
    import java.util.ArrayList;
    import java.awt.*;
    import com.borland.jbcl.layout.XYLayout;
    import com.borland.jbcl.layout.*;
    import javax.swing.JLabel;
    import javax.swing.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseAdapter;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import javax.imageio.ImageIO;
    public class Frame1 extends JFrame {
        JPanel contentPane;
        BorderLayout borderLayout1 = new BorderLayout();
        XYLayout xYLayout1 = new XYLayout();
        private BufferedImage bi[];
        JPanel jPanel1 = new JPanel();
        XYLayout xYLayout2 = new XYLayout();
        public void handlesinglepixel(int x, int y, int pixel) {
                int alpha = (pixel >> 24) & 0xff;
                int red   = (pixel >> 16) & 0xff;
                int green = (pixel >>  8) & 0xff;
                int blue  = (pixel      ) & 0xff;
                // Deal with the pixel as necessary...
        public Frame1() {
            try {
                setDefaultCloseOperation(EXIT_ON_CLOSE);
                jbInit();
            } catch (Exception exception) {
                exception.printStackTrace();
         * Component initialization.
         * @throws java.lang.Exception
        private void jbInit() throws Exception {
            contentPane = (JPanel) getContentPane();
            contentPane.setLayout(borderLayout1);
            setSize(new Dimension(400, 300));
            setTitle("Frame Title");
            jPanel1.setBackground(Color.white);
            jPanel1.addMouseListener(new Frame1_jPanel1_mouseAdapter(this));
            jPanel1.setLayout(xYLayout2);
            contentPane.add(jPanel1, java.awt.BorderLayout.CENTER);
            bi = new BufferedImage[1];
            File f = new File("temp2.png");
                //  Read in a BufferedImage from a file.
                       BufferedImage bufferedImage = ImageIO.read(f);
                       ImageIO.write(bufferedImage, "png", f);
    bi[0] = bufferedImage;
                       //  Convert the image to an RGB style normalized image.
               //        bi[0] = new BufferedImage(bufferedImage.getWidth(),
               //            bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB);
               //       bi[0].getGraphics().drawImage(bufferedImage, 198, 100, this);
        public void paint(Graphics g) {
            Graphics2D g2 = (Graphics2D)g;
            g2.drawImage(bi[0], 110, 110,null);
        public void jPanel1_mouseClicked(MouseEvent e) {
            int mouseX = e.getX();
            int mouseY = e.getY();
            int rgb = bi[0].getRGB(1, 98);
            int red = ((rgb >> 16) & 0xff);
                int green = ((rgb >> 8) & 0xff);
        int blue = ((rgb ) & 0xff);
        rgb = (red << 16) | (green << 8) | blue;
            System.out.println((red ) + " " +  (green ) + " " + blue);
    System.out.print(mouseX + " / " + mouseY + " ");
    class Frame1_jPanel1_mouseAdapter extends MouseAdapter {
        private Frame1 adaptee;
        Frame1_jPanel1_mouseAdapter(Frame1 adaptee) {
            this.adaptee = adaptee;
        public void mouseClicked(MouseEvent e) {
            adaptee.jPanel1_mouseClicked(e);
    }

  • PixelGrabber

    Hi all,
    I'm using the method grabPixel of the class PixelGrabber to get an array of pixels of an image.
    The problem is that the array I'm getting is not correct and the x right pixels(in my case 473 right pixels) in each line of the matrix of the image is shifted to the left part of that line and all of them get the value 0 (which is black).
    How can I avoid this problem?
    The following code is the code of the class using PixelGrabber:
    import javax.swing.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.awt.image.*;
    public class FilePanel extends JPanel {
    protected Image currentImage = null, modImg = null;
    private boolean isFile = false;
    private int pictureWidth, pictureHeight;
    private int count = 0;
    protected int[] pixels, pix;
    private MediaTracker tracker;
    private ColorModel colorModel;
    public FilePanel() {
    setBorder (BorderFactory.createTitledBorder("Picture Area:"));
    tracker = new MediaTracker(this);
    colorModel = ColorModel.getRGBdefault();
    public void setFile(String fileName)
    if (fileName != null)
    currentImage=null;
    isFile = true;
    if (fileName.endsWith(".bmp") || fileName.endsWith(".BMP"))
    BMP bmp = new BMP(new java.io.File(fileName));
    currentImage = bmp.getImage();
    else
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    currentImage = toolkit.getImage(fileName);
    try
    tracker.addImage(currentImage,11);
    tracker.waitForID(11);
    catch(InterruptedException e)
    e.printStackTrace();
    System.err.println("*ERROR* MediaTracker rudely interrupted.");
    currentImage=null;
    tracker.removeImage(currentImage);
    pictureWidth = currentImage.getWidth(this);
    pictureHeight = currentImage.getHeight(this);
    handlepixels(currentImage, (getWidth() - pictureWidth)/2 - 60, 0,
    pictureWidth, pictureHeight);
    isFile = true;
    repaint();
    public void paintComponent(Graphics g)
    if (currentImage != null && currentImage.getHeight(null)>=0)
    super.paintComponent(g);
    g.drawImage(currentImage, (this.getWidth() - 300)/2,
    (this.getHeight() - 90)/2, this);
    public byte[] sendPixel (byte byteArray[])
    int numOfBits = 8, numOfBytesInLine = pictureWidth/8,
    numOfLines = pictureHeight, countPixels = 0, gray,
    currentPixel, bit = -1;
    byte currentByte = 0;
    int j = 0;
    if (currentImage == null)
    System.out.println("Picture has not been loaded yet");
    return null;
    else
    for (int i = 0 ;i < pixels.length; i++)
    currentPixel = manipulatePixel(pixels);
    if (currentPixel > 128)
    currentByte &= 0xfe;
    else
    currentByte |= 0x01;
    bit++;
    if (bit != 7)
    currentByte <<= 1;
    else
    bit = -1;
    byteArray[i/8] = currentByte;
    currentByte = 0;
    return byteArray;
    public int manipulatePixel (int pixel)
    return ((pixel&0xff)+((pixel&0xff00)>>8)+((pixel&0xff0000)>>16))/3;
    public void handlepixels(Image img, int x, int y, int w, int h) {
    System.out.println("w "+w+" h "+h);
    pixels = new int[w * h];
    int red, green, blue;
         PixelGrabber pg = new PixelGrabber (img, x, y, w, h, pixels, 0, w);
         try {
         if (pg.grabPixels()&&((pg.getStatus() & ImageObserver.ALLBITS) != 0))
    else
    System.out.println("Did not succeed to grab pixles");
    catch (InterruptedException e) {
         System.err.println("interrupted waiting for pixels!");
         return;
    repaint();
    public int getNumOfLines () {return pictureHeight;}
    public int getNumOfBytesInLine () {return pictureWidth/8;}
    Thanks,
    gabi

    Method is somethig like this:
    public void handlepixels(Image img, int x, int y, int w, int h)
              int[] pixels = new int[w * h];
              �
              PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
              try
              pg.grabPixels();
              catch (InterruptedException e)
              for (int j = 0; j < h; j++)
    for (int i = 0; i < w; i++)
                   //what do I need to do inside this loop?
         // Ineed to check pixel by pixel if it is certain color and then convert it to
                   //different color.     
                   Image new_image = Toolkit.getDefaultToolkit().createImage(new MemoryImageSource(w, h, image, 0, w));
         }

  • COMMUNICATION BETWEEN JAVASCRIPT AND JAVA APPLET: US$20 AWARD FOR SOLUTION!

    COMMUNICATION BETWEEN JAVASCRIPT AND JAVA APPLET PROBLEM (Easy Filter Java Applet) -
    US$20 TO ANYONE WHO CAN RESOLVE THE PROBLEM
    To forum visitors:
    I am prepared to pay a standard shareware fee of US$20 to a user who can resolve this technical problem.
    If your advice resolves the problem, I'll forward the payment to your postal address (include your
    address with your reply, and also your email address)
    I am attempting to enable a HTML button (using Javascript's onClick command) to directly input a number into one of the parameter text boxes in the Easy Filter Java applet (ie, enter a new color value number in the text field of the standard Colors Multiplicator Filter interface).
    The applet is Freeware and can be downloaded at: http://www.javazoom.net/applets/easyfilter10/EasyFilter10.html
    (It is a very effective bitmap display and editing utility)
    To achieve this, I am trying to access the part of the applet that defines and sets the textbox. The text box is defined in the .class file by accessing the parameter details in the genericfilter.txt file (accompanies the .class files). I need to access 'private String appletInitialize()' and then one of the 'textFieldParameters' which sets the textbox.
    I understand the basic syntax for referencing the applet:
    document.appletname.setString("An example"). However, accessing the text fields in this applet is more complex!!
    Please can you recommend the correct Javascript syntax to achieve communication with the applet.
    Thank you for your kind assistance.
    JM Graham
    [email protected]
    The Java source code for the applet: EasyFilter.class
    # Easy Filter - E.B/JavaZOOM 1999 #
    # Contact: [email protected] #
    # http://javazoom.hypermart.net #
    /* Originally compiled from EasyFilter.java */
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    import java.applet.Applet;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.image.MemoryImageSource;
    import java.awt.image.PixelGrabber;
    import java.util.Vector;
    public synchronized class EasyFilter extends Applet implements KeyListener
    private String paramFileName;
    private Color bgColor;
    private Color fgColor;
    private Color parColor;
    private Color sepColor;
    private Color titleColor;
    private Color helpColor;
    private int WinWidth;
    private int WinHeight;
    private String title;
    private String logoFileName;
    private String originalImageFileName;
    private String filteredCaption;
    private String originalCaption;
    private Vector paramsName;
    private Vector paramsValue;
    private Vector paramsComment;
    private Panel panelParameters[];
    private Label labelParameters[];
    private TextField textFieldParameters[];
    private Label labelComments[];
    private int nbParameters;
    private ScrollPane scrollPaneParams;
    private Panel panelParams;
    private Image theLogo;
    private Image theOriginalImage;
    private Image theFilteredImage;
    private int theOriginalPixelArray[];
    private int logoWidth;
    private int logoHeight;
    private int imageWidth;
    private int imageHeight;
    private drawCanvas canvasTitle;
    private Panel panelTitle;
    private Label labelTitle;
    private Panel panelImages;
    private Panel panelOriginalImage;
    private drawCanvas canvasOriginalImage;
    private Label labelOriginalImage;
    private Panel panelFilteredImage;
    private drawCanvas canvasFilteredImage;
    private Label labelFilteredImage;
    private Panel panelHelp;
    private Label labelHelp;
    private int Yspc;
    private FilterImplementation theFilter;
    public void init()
    String string = null;
    string = appletInitialize();
    setBackground(bgColor);
    if (string != null)
    removeAll();
    setBackground(Color.white);
    setForeground(Color.black);
    Label label = new Label(new StringBuffer("Error: ").append(string).toString(), 1);
    Panel panel = new Panel();
    panel.add(label);
    add(panel);
    setLayout(new FlowLayout(1, 5, Yspc));
    public void keyPressed(KeyEvent keyEvent)
    panelHelp.removeAll();
    boolean flag = true;
    if (KeyEvent.getKeyText(keyEvent.getKeyCode()).equals("Enter"))
    for (int i = 0; i < nbParameters; )
    try
    paramsValue.setElementAt(new Double(textFieldParameters.getText()), i);
    i++;
    catch (NumberFormatException e)
    labelHelp.setText(labelParameters[i].getText() + ": Not a Number");
    flag = false;
    break;
    if (flag == 1)
    labelHelp.setText(" .... Running, please wait .... ");
    labelHelp.setAlignment(1);
    panelHelp.add(labelHelp);
    panelHelp.doLayout();
    theFilter.updateParameters(paramsValue);
    theFilter.computeFilter();
    theFilteredImage = createImage(new MemoryImageSource(theFilter.getFinalImageWidth(), theFilter.getFinalImageHeight(), theFilter.getFinalImageBuffer(), 0, theFilter.getFinalImageWidth()));
    canvasFilteredImage.setImage(theFilteredImage);
    canvasFilteredImage.setBounds(0, 0, theFilter.getFinalImageWidth(), theFilter.getFinalImageHeight());
    canvasFilteredImage.repaint();
    panelHelp.removeAll();
    labelHelp.setText("- Done -");
    else
    labelHelp.setText("- Press Enter to run the Filter -");
    labelHelp.setAlignment(1);
    panelHelp.add(labelHelp);
    panelHelp.doLayout();
    public void keyReleased(KeyEvent keyEvent)
    public void keyTyped(KeyEvent keyEvent)
    private String appletInitialize()
    WinWidth = size().width;
    WinHeight = size().height;
    if (getParameter("bgcolor") == null)
    bgColor = new Color(0, 0, 40);
    else
    bgColor = new Color(Integer.parseInt(getParameter("bgcolor"), 16));
    if (getParameter("fgcolor") == null)
    fgColor = new Color(255, 255, 255);
    else
    fgColor = new Color(Integer.parseInt(getParameter("fgcolor"), 16));
    if (getParameter("sepcolor") == null)
    sepColor = new Color(158, 128, 128);
    else
    sepColor = new Color(Integer.parseInt(getParameter("sepcolor"), 16));
    if (getParameter("parcolor") == null)
    parColor = new Color(24, 24, 24);
    else
    parColor = new Color(Integer.parseInt(getParameter("parcolor"), 16));
    if (getParameter("titlecolor") == null)
    titleColor = new Color(255, 255, 0);
    else
    titleColor = new Color(Integer.parseInt(getParameter("titlecolor"), 16));
    if (getParameter("helpcolor") == null)
    helpColor = new Color(0, 255, 255);
    else
    helpColor = new Color(Integer.parseInt(getParameter("helpcolor"), 16));
    paramsName = new Vector();
    paramsValue = new Vector();
    paramsComment = new Vector();
    paramFileName = getParameter("paramfile");
    String string = readParams(paramFileName);
    if (string != null)
    return string;
    MediaTracker mediaTracker = new MediaTracker(this);
    theOriginalImage = getImage(getDocumentBase(), originalImageFileName);
    mediaTracker.addImage(theOriginalImage, 0);
    if (logoFileName != null)
    theLogo = getImage(getDocumentBase(), logoFileName);
    mediaTracker.addImage(theLogo, 1);
    try
    mediaTracker.waitForAll();
    catch (InterruptedException e1)
    return "Error while loading image";
    if (mediaTracker.isErrorAny())
    return "Error while loading image";
    if (logoFileName != null)
    logoWidth = theLogo.getWidth(this);
    logoHeight = theLogo.getHeight(this);
    imageWidth = theOriginalImage.getWidth(this);
    imageHeight = theOriginalImage.getHeight(this);
    theOriginalPixelArray = new int[imageWidth * imageHeight];
    PixelGrabber pixelGrabber = new PixelGrabber(theOriginalImage, 0, 0, imageWidth, imageHeight, theOriginalPixelArray, 0, imageWidth);
    try
    pixelGrabber.grabPixels();
    panelTitle = new Panel();
    canvasTitle = new drawCanvas();
    labelTitle = new Label();
    panelTitle.setLayout(new FlowLayout(1, 10, Yspc));
    add(panelTitle);
    panelTitle.setBackground(bgColor);
    panelTitle.add(canvasTitle);
    canvasTitle.setImage(theLogo);
    canvasTitle.setBounds(0, 0, logoWidth, logoHeight);
    labelTitle.setText(title);
    catch (InterruptedException e2)
    return "Internal Error, Try RELOAD !";
    if (title != null)
    panelTitle.add(labelTitle);
    labelTitle.setForeground(titleColor);
    labelTitle.setFont(new Font("Dialog", 1, 14));
    panelImages = new Panel();
    panelOriginalImage = new Panel();
    canvasOriginalImage = new drawCanvas();
    labelOriginalImage = new Label();
    panelFilteredImage = new Panel();
    canvasFilteredImage = new drawCanvas();
    labelFilteredImage = new Label();
    panelImages.setLayout(new FlowLayout(1, 10, Yspc));
    add(panelImages);
    panelImages.setBackground(bgColor);
    panelOriginalImage.setLayout(new BorderLayout(0, 2));
    panelImages.add(panelOriginalImage);
    panelOriginalImage.setBackground(Color.black);
    panelOriginalImage.add("Center", canvasOriginalImage);
    canvasOriginalImage.setImage(theOriginalImage);
    canvasOriginalImage.setBounds(0, 0, imageWidth, imageHeight);
    labelOriginalImage.setText(originalCaption);
    labelOriginalImage.setAlignment(1);
    panelOriginalImage.add("South", labelOriginalImage);
    labelOriginalImage.setBackground(Color.lightGray);
    labelOriginalImage.setForeground(Color.black);
    labelOriginalImage.setFont(new Font("SansSerif", 0, 10));
    panelFilteredImage.setLayout(new BorderLayout(0, 2));
    panelImages.add(panelFilteredImage);
    panelFilteredImage.setBackground(Color.black);
    panelFilteredImage.add("Center", canvasFilteredImage);
    theFilter = new FilterImplementation(paramsValue, theOriginalPixelArray, imageWidth, imageHeight);
    theFilter.computeFilter();
    theFilteredImage = createImage(new MemoryImageSource(theFilter.getFinalImageWidth(), theFilter.getFinalImageHeight(), theFilter.getFinalImageBuffer(), 0, theFilter.getFinalImageWidth()));
    canvasFilteredImage.setImage(theFilteredImage);
    canvasFilteredImage.setBounds(0, 0, theFilter.getFinalImageWidth(), theFilter.getFinalImageHeight());
    labelFilteredImage.setText(filteredCaption);
    labelFilteredImage.setAlignment(1);
    panelFilteredImage.add("South", labelFilteredImage);
    labelFilteredImage.setBackground(Color.lightGray);
    labelFilteredImage.setFont(new Font("SansSerif", 0, 10));
    scrollPaneParams = new ScrollPane(0);
    panelParams = new Panel();
    nbParameters = paramsName.size();
    int i = WinHeight - (33 + 7 * Yspc + logoHeight + imageHeight + 23);
    if (i < Yspc + 2 + 24)
    i = Yspc + 2 + 24;
    scrollPaneParams.setBounds(0, 0, WinWidth - 10, i);
    panelParams.setLayout(new GridLayout(nbParameters, 1, 5, Yspc / 2));
    scrollPaneParams.add(panelParams);
    panelParams.setBackground(sepColor);
    panelParameters = new Panel[nbParameters];
    labelParameters = new Label[nbParameters];
    textFieldParameters = new TextField[nbParameters];
    labelComments = new Label[nbParameters];
    for (int j = 0; j < nbParameters; j++)
    panelParameters[j] = new Panel();
    panelParameters[j].setLayout(new FlowLayout(0, 5, 1));
    panelParams.add(panelParameters[j]);
    panelParameters[j].setBackground(parColor);
    labelParameters[j] = new Label();
    labelParameters[j].setText((String)paramsName.elementAt(j));
    panelParameters[j].add(labelParameters[j]);
    labelParameters[j].setForeground(fgColor);
    labelParameters[j].setFont(new Font("Dialog", 1, 12));
    textFieldParameters[j] = new TextField(8);
    textFieldParameters[j].setText(paramsValue.elementAt(j).toString());
    panelParameters[j].add(textFieldParameters[j]);
    textFieldParameters[j].setBackground(fgColor);
    textFieldParameters[j].addKeyListener(this);
    labelComments[j] = new Label();
    labelComments[j].setText((String)paramsComment.elementAt(j));
    panelParameters[j].add(labelComments[j]);
    labelComments[j].setForeground(fgColor);
    add(scrollPaneParams);
    panelHelp = new Panel();
    labelHelp = new Label();
    panelHelp.setLayout(new FlowLayout(1, 5, 0));
    add(panelHelp);
    panelHelp.setBackground(bgColor);
    labelHelp.setText(" Change colour values and press enter ");
    labelHelp.setAlignment(1);
    panelHelp.add(labelHelp);
    labelHelp.setForeground(helpColor);
    return null;
    private String readParams(String string1)
    Object object1;
    String string2;
    if (string1 == null)
    return "Filename of filter's parameters needed";
    try
    URL uRL = new URL(getDocumentBase(), string1);
    URLConnection uRLConnection = uRL.openConnection();
    uRLConnection.setDoInput(true);
    uRLConnection.setUseCaches(false);
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(uRLConnection.getInputStream()));
    string2 = null;
    catch ()
    return object1.getMessage();
    catch ()
    return object1.getMessage();
    catch ()
    return object1.getMessage();
    if (bufferedReader != null)
    Object object2;
    try
    for (object2 = bufferedReader.readLine(); object2 != null && string2 == null; object2 = bufferedReader.readLine())
    string2 = extractFormat(object2);
    catch ()
    string2 = object2.getMessage();
    finally
    bufferedReader.close();
    if (string2 != null)
    return string2;
    else
    return null;
    private String extractFormat(String string1)
    if (string1.length() == 0)
    return null;
    int i = 0;
    int j = string1.indexOf(" ", i);
    if (j == -1)
    return "Bad format error (space missing)";
    String string2 = string1.substring(i, j);
    if (string2.equals("TITLE"))
    i = j;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in TITLE missing)";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in TITLE missing)";
    title = string1.substring(i, j);
    return null;
    if (string2.equals("ORIGINALCAPTION"))
    i = j;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in ORIGINALCAPTION missing)";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in ORIGINALCAPTION missing)";
    originalCaption = string1.substring(i, j);
    return null;
    if (string2.equals("FILTEREDCAPTION"))
    i = j;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in FILTEREDCAPTION missing)";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in FILTEREDCAPTION missing)";
    filteredCaption = string1.substring(i, j);
    return null;
    if (string2.equals("LOGO"))
    i = j + 1;
    j = string1.length();
    logoFileName = string1.substring(i, j);
    return null;
    if (string2.equals("ORIGINALIMAGE"))
    i = j + 1;
    j = string1.length();
    originalImageFileName = string1.substring(i, j);
    return null;
    if (!string2.equals("PARAM"))
    return null;
    i = j;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format in a PARAM line";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format in a PARAM line";
    paramsName.addElement(string1.substring(i, j));
    i = j + 2;
    j = string1.indexOf(32, i);
    if (j == -1)
    return "Bad format in a PARAM line";
    try
    paramsValue.addElement(new Double(string1.substring(i, j)));
    j = string1.indexOf(34, i);
    catch (NumberFormatException e)
    return "Bad format in a PARAM line";
    if (j == -1)
    return "Bad format (Double quote in PARAM comment missing)";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in PARAM comment missing)";
    paramsComment.addElement(string1.substring(i, j));
    return null;
    public EasyFilter()
    logoHeight = 33;
    Yspc = 5;

    Addition to my above submission
    To clarify, I'll offer the US$20 to the FIRST person who offers me a workable solution to the problem, not to everyone!!!
    JMGRAHAM

  • AWT error on Solaris, please help

    Hello all,
    I have designed a class to convert any picture format to WBMP using Jimi via a web browser.
    The user specifies the file to convert on his computer and presses a OK button. Then, the file is converted and saved to
    the server.
    When running it on a windows computer, everything is ok. But I try to run it on my solaris box, I got the following error :
    Error: 500
    java.lang.InternalError: Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
         at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
         at sun.awt.X11GraphicsEnvironment.(X11GraphicsEnvironment.java:59)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:120)
         at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:58)
         at sun.awt.motif.MToolkit.(MToolkit.java:57)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:120)
         at java.awt.Toolkit$2.run(Toolkit.java:512)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:503)
         at com.sun.jimi.core.Jimi.getImage(Jimi.java:334)
         at com.sun.jimi.core.Jimi.getImage(Jimi.java:323)
         at com.mcms.util.Convert2Wbmp.loadImage(Convert2Wbmp.java:62)
         at com.mcms.util.Convert2Wbmp.convert(Convert2Wbmp.java:110)
         at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:500)
         at org.apache.tomcat.core.Handler.service(Handler.java:223)
         at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:448)
         at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:911)
         at org.apache.tomcat.core.ContextManager.service(ContextManager.java:824)
         at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:152)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:438)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:505)
         at java.lang.Thread.run(Thread.java:484)
    Note that the 6000 port is open on my solaris server :
    6000/tcp open X11
    What should I do ?
    Here's the code, I hope we're allowed to post it ;) :
    ==================
    Convert2WBMP.java
    ==================
    import com.sun.jimi.core.Jimi;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.PixelGrabber;
    import java.io.*;
    import java.io.PrintStream;
    import java.util.EventObject;
    import java.util.StringTokenizer;
    * This handles an individual incoming request. It returns a bytes etc from remote server.
    * @version 1.0
    public class Convert2Wbmp extends Frame
    private static int width;
    private static int height;
    private static Image image;
    private static int buffer[];
    public Convert2Wbmp()
    private Image loadImage(String s, boolean flag)
    Image image1 = null;
    try
    if(flag)
    image1 = Jimi.getImage(s);
    else
    image1 = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource(s));
    MediaTracker mediatracker = new MediaTracker(this);
         mediatracker.addImage(image1, 0);
         mediatracker.waitForID(0);
    catch(Exception _ex)
         _ex.printStackTrace();
    return null;
    if(image1.getWidth(null) == -1 || image1.getHeight(null) == -1){
    return null;
    else
    return image1;
    private static Image loadImage(InputStream s)
    //System.out.println("now loading Image...");
    Image image1 = null;
    try
         image1 = Jimi.getImage(s);
         MediaTracker mediatracker = new MediaTracker(new Convert2Wbmp());
         mediatracker.addImage(image1, 0);
         mediatracker.waitForID(0);
    catch(Exception _ex)
         _ex.printStackTrace();
    return null;
    if(image1.getWidth(null) == -1 || image1.getHeight(null) == -1)
    return null;
    else
    return image1;
    private static void makeWBMP()
    if(image != null)
    buffer = new int[width * height];
    try
    PixelGrabber pixelgrabber = new PixelGrabber(image.getScaledInstance(width, height, 1), 0, 0, width, height, buffer, 0, width);
    pixelgrabber.grabPixels();
    catch(Exception exception)
         exception.printStackTrace();
    public static void convert(InputStream picSource,OutputStream target) throws Exception
    if(picSource != null)
         Image image1 = null;
         try
         image1 = loadImage(picSource);
         }catch(Exception e){ }
         if(image1 == null)
         System.out.println("Failed to load image!");
         return;
         image = image1;
         width = image1.getWidth(null);
         height = image1.getHeight(null);
         makeWBMP();
         try
         WBMP.save(buffer, width, height, 30, target);
         }catch (Exception e)
         e.printStackTrace();
    public static void main(String[] arg)
    try
    String target = "target.wbmp";
    String source = "source.jpg";
    Convert2Wbmp.convert( new FileInputStream( new File(source)), new FileOutputStream(target) );
    System.out.println("convertion finish!!");
    catch(Exception err )
    err.printStackTrace();
    ============
    WBMP.java
    ============
    import java.awt.*;
    import java.awt.image.MemoryImageSource;
    import java.io.*;
    public abstract class WBMP
    public WBMP()
    public static Image errorDiff(int ai[], int i, int j, int k, Color color, boolean flag)
    //System.out.println(" [WBMP]-----errorDiff");
    double ad[] = new double[i * j];
    for(int l = 0; l < i * j; l++)
    ad[l] = greypixel(ai[l]);
    double d = 42D;
    for(int i1 = 0; i1 < j; i1++)
    for(int j1 = 0; j1 < i; j1++)
    double d1 = ad[i1 * i + j1];
    if(ad[i1 * i + j1] > (double)k)
    ad[i1 * i + j1] = 255D;
    else
    ad[i1 * i + j1] = 0.0D;
    double d2 = d1 - ad[i1 * i + j1];
    if(j1 < i - 1)
    ad[i1 * i + j1 + 1] = ad[i1 * i + j1 + 1] + (8D / d) * d2;
    if(j1 < i - 2)
    ad[i1 * i + j1 + 2] = ad[i1 * i + j1 + 2] + (4D / d) * d2;
    if(i1 < j - 1 && j1 > 1)
    ad[((i1 + 1) * i + j1) - 2] = ad[((i1 + 1) * i + j1) - 2] + (2D / d) * d2;
    if(i1 < j - 1 && j1 > 0)
    ad[((i1 + 1) * i + j1) - 1] = ad[((i1 + 1) * i + j1) - 1] + (4D / d) * d2;
    if(i1 < j - 1)
    ad[(i1 + 1) * i + j1] = ad[(i1 + 1) * i + j1] + (8D / d) * d2;
    if(i1 < j - 1 && j1 < i - 1)
    ad[(i1 + 1) * i + j1 + 1] = ad[(i1 + 1) * i + j1 + 1] + (4D / d) * d2;
    if(i1 < j - 1 && j1 < i - 2)
    ad[(i1 + 1) * i + j1 + 2] = ad[(i1 + 1) * i + j1 + 2] + (2D / d) * d2;
    if(i1 < j - 2 && j1 > 1)
    ad[((i1 + 2) * i + j1) - 2] = ad[((i1 + 2) * i + j1) - 2] + (1.0D / d) * d2;
    if(i1 < j - 2 && j1 > 0)
    ad[((i1 + 2) * i + j1) - 1] = ad[((i1 + 2) * i + j1) - 1] + (2D / d) * d2;
    if(i1 < j - 2)
    ad[(i1 + 2) * i + j1] = ad[(i1 + 2) * i + j1] + (4D / d) * d2;
    if(i1 < j - 2 && j1 < i - 1)
    ad[(i1 + 2) * i + j1 + 1] = ad[(i1 + 2) * i + j1 + 1] + (2D / d) * d2;
    if(i1 < j - 2 && j1 < i - 2)
    ad[(i1 + 2) * i + j1 + 2] = ad[(i1 + 2) * i + j1 + 2] + (1.0D / d) * d2;
    for(int k1 = 0; k1 < i * j; k1++)
    int l1 = (int)ad[k1];
    if(!flag)
    if("1".equals(handlesinglepixel(l1, k)))
    ai[k1] = color.getRGB();
    else
    ai[k1] = Color.black.getRGB();
    } else
    if("1".equals(handlesinglepixel(l1, k)))
    ai[k1] = Color.black.getRGB();
    else
    ai[k1] = color.getRGB();
    return (new Canvas()).createImage(new MemoryImageSource(i, j, ai, 0, i));
    public static Image errorDiff2(int ai[], int i, int j, int k, Color color, boolean flag)
    //System.out.println(" [WBMP]-----errorDiff");
    char c = '\377';
    byte byte0 = 2;
    double ad[] = new double[i * j];
    for(int l = 0; l < i * j; l++)
    ad[l] = greypixel(ai[l]);
    int i1 = ((c + 1) * 2) / byte0;
    int j1 = c / (byte0 - 1);
    int k1 = (9 * c) / 32;
    int ai1[] = new int;
    for(int k2 = 0; k2 < i; k2++)
    ai1[k2] = k1;
    for(int l2 = 0; l2 < j; l2++)
    int i3 = (7 * c) / 32;
    int k3 = c / 32;
    for(int i4 = 0; i4 < i; i4++)
    int i2 = (int)ad[l2 * i + i4];
    i2 += i3 + ai1[i4];
    int l1 = (i2 / i1) * j1;
    if(l1 > c)
    l1 = c;
    ad[l2 * i + i4] = l1;
    i2 -= l1;
    int j2 = i2 >> 4;
    i3 = 7 * j2;
    ai1[i4] = 5 * j2 + k3;
    if(i4 > 0)
    ai1[i4 - 1] += 3 * j2;
    k3 = i2 - 15 * j2;
    for(int j3 = 0; j3 < i * j; j3++)
    int l3 = (int)ad[j3];
    if(!flag)
    if("1".equals(handlesinglepixel(l3, 30)))
    ai[j3] = color.getRGB();
    else
    ai[j3] = Color.black.getRGB();
    } else
    if("1".equals(handlesinglepixel(l3, 30)))
    ai[j3] = Color.black.getRGB();
    else
    ai[j3] = color.getRGB();
    return (new Canvas()).createImage(new MemoryImageSource(i, j, ai, 0, i));
    private static int greypixel(int i)
    int j = i >> 24 & 0xff;
    int k = i >> 16 & 0xff;
    int l = i >> 8 & 0xff;
    int i1 = i & 0xff;
    return (k + l + i1) / 3;
    public static String handlesinglepixel(int i, int j)
    //      System.out.println(" [WBMP]-----handlesinglepixel");
    int k = i >> 24 & 0xff;
    int l = i >> 16 & 0xff;
    int i1 = i >> 8 & 0xff;
    int j1 = i & 0xff;
    if((l + i1 + j1) / 3 > j)
    return "1";
    else
    return "0";
    public static Image open(String s)
    throws FileNotFoundException
         //System.out.println(" [WBMP]-----open");
    Image image = null;
    FileInputStream fileinputstream = new FileInputStream(s);
    try
    fileinputstream.read();
    fileinputstream.read();
    int i = readMultiByteInteger(fileinputstream);
    int j = readMultiByteInteger(fileinputstream);
    int ai[] = new int[i * j];
    int k = 0;
    for(int l = 0; l < j; l++)
    for(int i1 = 0; i1 < i / 8; i1++)
    int j1 = fileinputstream.read();
    String s1 = Integer.toBinaryString(j1);
    for(int l1 = 0; l1 < 8 - s1.length(); l1++)
    ai[k++] = Color.black.getRGB();
    for(int i2 = 0; i2 < s1.length(); i2++)
    if(s1.charAt(i2) == '0')
    ai[k++] = Color.black.getRGB();
    else
    ai[k++] = Color.white.getRGB();
    if(i % 8 > 0)
    int k1 = fileinputstream.read();
    String s2 = Integer.toBinaryString(k1);
    String s3 = "";
    for(int j2 = 0; j2 < 8 - s2.length(); j2++)
    s3 = s3 + '0';
    s2 = s3 + s2;
    for(int k2 = 0; k2 < i % 8; k2++)
    if(s2.charAt(k2) == '0')
    ai[k++] = Color.black.getRGB();
    else
    ai[k++] = Color.white.getRGB();
    fileinputstream.close();
    image = (new Canvas()).createImage(new MemoryImageSource(i, j, ai, 0, i));
    catch(Exception _ex)
         _ex.printStackTrace();
    try
    fileinputstream.close();
    catch(Exception _ex2) {_ex2.printStackTrace(); }
    return null;
    return image;
    public static int readMultiByteInteger(InputStream inputstream)
    throws IOException
    //System.out.println(" [WBMP]-----readMultiByteInteger");
    StringBuffer stringbuffer = new StringBuffer("");
    StringBuffer stringbuffer1;
    do
    stringbuffer1 = new StringBuffer(Integer.toBinaryString(inputstream.read()));
    int i = 8 - stringbuffer1.length();
    for(int j = 0; j < i; j++)
    stringbuffer1.insert(0, '0');
    stringbuffer.append(stringbuffer1.substring(1));
    } while(stringbuffer1.charAt(0) != '0');
    return Integer.parseInt(stringbuffer.toString(), 2);
    public static boolean save(int ai[], int i, int j, int k, OutputStream outputstream)
         //System.out.println(" [WBMP]-----save");
    try
    outputstream.write(0);
    outputstream.write(0);
    writeMultiByteInteger(outputstream, i);
    writeMultiByteInteger(outputstream, j);
    String s = "";
    for(int l = 0; l < j; l++)
    for(int i1 = 0; i1 < i; i1++)
    s = s + handlesinglepixel(ai[l * i + i1], k);
    if(s.length() == 8)
    outputstream.write(Integer.parseInt(s, 2));
    s = "";
    if(s.length() > 0)
    int j1 = 8 - s.length();
    for(int k1 = 0; k1 < j1; k1++)
    s = s + "0";
    outputstream.write(Integer.parseInt(s, 2));
    s = "";
    catch(NumberFormatException _ex)
    return false;
    catch(IOException _ex)
    return false;
    return true;
    public static Image threshold(int ai[], int i, int j, int k, Color color, boolean flag)
    int ai1[] = new int[i * j];
    int l = 0;
    for(int i1 = 0; i1 < j; i1++)
    for(int j1 = 0; j1 < i; j1++)
    if(!flag)
    if("1".equals(handlesinglepixel(ai[l], k)))
    ai1[l++] = color.getRGB();
    else
    ai1[l++] = Color.black.getRGB();
    } else
    if("1".equals(handlesinglepixel(ai[l], k)))
    ai1[l++] = Color.black.getRGB();
    else
    ai1[l++] = color.getRGB();
    ai = ai1;
    return (new Canvas()).createImage(new MemoryImageSource(i, j, ai1, 0, i));
    public static void writeMultiByteInteger(OutputStream outputstream, int i)
    throws IOException
    String s = Integer.toBinaryString(i);
    int j = s.length();
    int k = j / 7;
    if(j % 7 != 0)
    k++;
    int ai[] = new int[k];
    int l = j;
    for(int i1 = k - 1; i1 >= 0; i1--)
    StringBuffer stringbuffer = new StringBuffer("");
    for(int k1 = 0; k1 < 7; k1++)
    if(--l < 0)
    stringbuffer.insert(0, '0');
    else
    stringbuffer.insert(0, s.charAt(l));
    if(i1 == k - 1)
    stringbuffer.insert(0, '0');
    else
    stringbuffer.insert(0, '1');
    ai[i1] = Integer.parseInt(stringbuffer.toString(), 2);
    for(int j1 = 0; j1 < ai.length; j1++)
    outputstream.write(ai[j1]);

    Hi
    I am working on a project in which I have to perform a task some thing similar to bluemountain.com. the way, they give option to select a background image, then have to fill a form in which one type its message and then on preview, they can see an image having the text written on it.
    Now I am doing to do this thing using JIMI. So far, what I have done is, I was able to create a jpg file and write several text on different coordinates. But one thing I want to do is, I want to load an existing file and then write text on it. I have tried this code. public static void main(String[] ar)
    try
    Frame frame = new Frame();
    frame.addNotify();
    Image image = frame.createImage(100,30);
    Graphics graphic = image.getGraphics();
    graphic.setFont(new Font("Times New Roman",Font.BOLD,20));
    graphic.setColor(Color.black);
    graphic.drawString("Hi Buddy",10,20);
    graphic.drawString("Cool",50,25);
    Jimi.putImage("image/jpg",image,"try.jpg");
    frame.removeNotify();
    catch(Exception e)
    e.printStackTrace();
    This is the code which creates a new image whereas I want to load an existing image and then write text on it.
    I have already used this code in the upper code.
    Image image = Jimi.getImage("filename");
    But as response, I get the following error msg:
    java.lang.IllegalAccessError:
    getGraphics() only valid for images
    created with createImage(w, h)
    now this is the main problem when I am trying to do the stuff. I m kinda new into this stuff. I tried several things but no luck so far. I have seen that u have already worked on these kinda things so thought you might help me out to get the thing done. Please do reply me with some solution.
    Regards,
    Faisal

  • Help with PixelGarbber

    HI every one
    does any body know how to get the pixels information of an image
    I used PixelGrabber to collect the pixels data but I wrote simple class to do this
    this is my code
    import java.awt.Image;
    import java.awt.image.PixelGrabber;
    import java.awt.image.ImageObserver;
    import java.awt.MediaTracker;
    import javax.swing.JFrame;
    public class MyClass extends JFrame implements  ImageObserver {
       StringBuffer s=new StringBuffer();
      public void handlesinglepixel(int x, int y, int pixel) {
    int alpha = (pixel >> 24) & 0xff;
    int red   = (pixel >> 16) & 0xff;
    int green = (pixel >>  8) & 0xff;
    int blue  = (pixel      ) & 0xff;
    // Deal with the pixel as necessary...
    s.append(alpha+" "+red+" "+green+" "+blue+",");
    public void handlepixels(Image img, int x, int y, int w, int h) {
    int[] pixels = new int[w * h];
    PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
    try {
        pg.grabPixels();
    } catch (InterruptedException e) {
        System.err.println("interrupted waiting for pixels!");
        return;
    if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
        System.err.println("image fetch aborted or errored");
        return;
    for (int j = 0; j < h; j++) {
        for (int i = 0; i < w; i++) {
    handlesinglepixel(x+i, y+j, pixels[j * w + i]);
        }s.append('\n');
    public boolean imageUpdate(Image img,int x,int y, int w,int h,int r){
      return true;
      public static void main(String[] args) {
        Image img= java.awt.Toolkit.getDefaultToolkit().createImage("myimage.jpg");
        MyClass un=new MyClass();
        int w=img.getWidth(un);
        int h=img.getHeight(un);
        MediaTracker mediaTracker=new MediaTracker(un);
       mediaTracker.addImage(img, 0);
       try{
         mediaTracker.waitForID(0);
       catch (InterruptedException e){
         System.err.println("error loading image");
         System.exit(-1);
        mediaTracker.removeImage(img);
        un.handlepixels(img,0,0,w,h);
        String d=un.s.toString();
        //do something with d
        System.out.print(d);
    }Thnaks

    ColorModel defRGB=ColorModel.getRGBdefault();
                   int pixels[]=new int[500*500];
                   try{
                        PixelGrabber pg=new
    PixelGrabber(buffer,gen.props[gen.i][6],gen.props[gen.i][7],width,height,pixels,0,width);
                        System.out.println("Entered try and catch, trying to grab pixels");
                        pg.grabPixels();
                   catch(InterruptedException ie){
                        ie.printStackTrace();
    hey was working wid pixel grabbers myself this is my part of the code which works perfectly fine, try it

  • Need urgent help ..save BMP image

    I have a BMP image .I m extracting its pixels (using PixelGrabber)and formatting those values as per requirements.
    Now,I have to create an image using this pixels array again.
    Image img;
    img = createImage(new MemoryImageSource(iw,ih,pixels,0,iw)) ;This is creating an[b] image "img" of type Image.
    Now,I have to save this image as BMP.
    for this I am using
    ImageIO.write(img,"BMP",new File("a.bmp"));The problem is this[b] write method require an image of type Buffered Image.
    I am not able to typecast an object of type Image into BufferedImage.
    BufferedImage is subclass of Image class..
    I just hope i m making sense..
    Please help me..
    Is there any other way too to save an BMP image created by createImage()

    Thnx a lot for help I used a method u told me ...
    here is the code i hve:
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.imageio.*;
    import java.awt.image.*;
    import java.awt.image.PixelGrabber;
    import javax.imageio.ImageIO;
    public class RecreateImage2
            public static void main(String args[])
                    ImageFrame frame = new ImageFrame();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setVisible(true);
    class ImageFrame extends JFrame
            public ImageFrame()
                 Toolkit kit=Toolkit.getDefaultToolkit();
              Dimension screenSize=kit.getScreenSize();
              int screenHeight=screenSize.height;
              int screenWidth=screenSize.width;
              setSize(screenWidth/2,screenHeight/2);
              setLocation(screenWidth/4,screenHeight/4);
              setTitle("Centered Frame");
              ImagePanel1 panel=new ImagePanel1();
                 add(panel);                                     
    class ImagePanel1 extends JPanel
            Image img;
            public ImagePanel1()
                    try
                   Image image;
                   Dimension d;
                   int iw,ih;
                            image = ImageIO.read(new File("bug_apple.bmp"));
                   iw = image.getWidth(null);
                   ih = image.getHeight(null);
                            int pixels[] = new int[ih*iw];
                   PixelGrabber pg = new    PixelGrabber(image,0,0,iw,ih,pixels,0,iw);
                            pg.grabPixels();
                            img = createImage(new MemoryImageSource(iw,ih,pixels,0,iw));      
                   BufferedImage bi = new BufferedImage(iw,ih,BufferedImage.TYPE_INT_ARGB)
                   Graphics2D g2d = bi.createGraphics();
                      g2d.drawImage(img, 0, 0, null);
                      g2d.dispose();
                   img=bi;
                   ImageIO.write(img,"BMP",new File("a.bmp")) ;          
                    catch(InterruptedException e)
                    catch(IOException e)
                            e.printStackTrace();
    }Its giving error ...saying
    cannot find method write(java.awt.Image,java.lang.String,java.io.File)But If i use Method
    ImageIO.write((BufferedImage)img,"BMP",new File("a.bmp")) ;It saves the Image as "a.bmp" but preview of image is not available...
    Please help me..I really dono whr the proplem is..
    richa_sharma

  • Read ICC profile information of an image

    Dear community,
    for my further implementation I need some information about the ICC profile used for an actual image edited inside Photoshop. How can I read the ICC informations about an image?
    I am implementing an export plug-in and found some ICC component inside the ExportRecord struct, called:
    Handle iCCprofileData; /**< Handle containing the ICC profile for the image. (NULL if none.)
                                                Photoshop allocates the handle using the Photoshop handle suite.
                                                The handle is unlocked while calling the plug-in.
                                                The handle is valid from  \c ExportSelectorStart to \c ExportSelectorFinish
                                                Photoshop frees the handle after \c ExportSelectorFinish. */
    int32 iCCprofileSize; /**< Size of profile. */
    int32 canUseICCProfiles; /**< Non-zero if the host can accept or export ICC profiles .
                                                If this is zero, the plug-in should not set or dereference \c iCCprofileData. */
    What I am not understand:
    How can I read the iCCprofileData and which information will be delivered by the iCCprofileSize?
    For iCCprofileData I got int values like @179952120 or @179952176. They differ for every loaded image. Seems that I just read the memory address. The "Handle" points to an empty char '\0'. I have no idea how to work with the datatype "Handle" correctly ...
    For the iCCprofileSize I got integer values like 544 for the embedded profile Adobe RGB (1998), 3144 for the working color space sRGB IEC61966-2.1 or also 3144 for the embedded profile without color management:
    embedded profile  = Adobe RGB (1998) -> iCCprofileSize = 544 (or sometimes 560)
    working color space = sRGB IEC61966-2.1 -> iCCprofileSize = 3144
    embedded profile = without color management -> iCCprofileSize = 3144
    embedded profile = SWOP2006_Coated3v2 -> iCCprofileSize = 2747952
    working color space = Coated FOGRA39 (ISO 12647-2:2004) -> iCCprofileSize = 654352
    embedded profile = without color management -> iCCprofileSize = 654352
    The variable canUseICCProfiles delivers always the value 1. As well if I selected the embedded profile without color management.
    Can I infer from the iCCprofileSize which profile will be used by each image?
    Does somebody has more experience with these there members (iCCprofileData, iCCprofileSize and canUseICCProfiles) of the struct ExportRecord?
    I would be grateful for some hints.
    King regards,
    Silver

    hai,
    i paste the java source code for getting each pixel value of an image.i think that this code is usefull to you.
    import java.awt.image.PixelGrabber;
    import java.awt.Toolkit;
    import java.awt.Image;
    class getpixel2
    public static void main(String args[]) throws Exception
    Image image = Toolkit.getDefaultToolkit().getImage("D:\\one.jpg");
    if(image==null)
    System.out.println("NO FIle");
    PixelGrabber grabber = new PixelGrabber(image, 0, 0, -1, -1, false);
    if (grabber.grabPixels())
    int width = grabber.getWidth();
    int height = grabber.getHeight();
    if (isGreyscaleImage(grabber))
    byte[] data = (byte[]) grabber.getPixels();
    else
    int[] data = (int[]) grabber.getPixels();
    for(int i=0;i<data.length;i++)
    int r = (data[i] >> 16) & 0xff;
    int g = (data[i] >> 8) & 0xff;
    int b = (data[i] >> 0) & 0xff;
    System.out.println("(R,G,B)=("+r+","+g+","+b+")");
    public static final boolean isGreyscaleImage(PixelGrabber pg)
    return pg.getPixels() instanceof byte[];
    }

  • Parameters to Applets in Eclipse

    Hi friends
    I M new to java applets.How can I pass Parameters (HTML Tags) in a Applet using Eclipse. My Applet runs with default Parameters. How Can I give new parameters.

    oops !!!!!!
    I forget to paste program with it.
    import java.applet.*;
    import java.awt.*;
    import java.awt.image.MemoryImageSource;
    import java.awt.image.PixelGrabber;
    import java.net.URL;
    <applet code = Lavatron.class width=560 height=128>
    <param name="img" value="vf.gif">
    </applet>
    public class Lavatron extends Applet implements Runnable{
         int scrollX;
         int bulbsW, bulbsH;
         int bulbS = 8;
         Dimension d;
         Image offscreen,bulb,img;
         Graphics offgraphics;
         int pixels[];
         int pixscan;
         IntHash clut = new IntHash();
         boolean stopflag;
         public void init() {
              d = getSize();
              int offw = (int) Math.ceil(d.width/bulbS)*bulbS;
              int offh = (int) Math.ceil(d.height/bulbS)*bulbS;
              offscreen = createImage (offw , offh);
              offgraphics = offscreen.getGraphics();
              bulbsW = offw/bulbS;
              bulbsH = offh/bulbS;
              bulb = createBulbs (bulbS , bulbsH*bulbS);
              try{
                   img = getImage (getDocumentBase() , getParameter("img"));
                   MediaTracker t = new MediaTracker (this);
                   t.addImage(img,0);
                   t.waitForID(0);
                   pixscan = img.getWidth(null);
                   int h = img.getHeight(null);
                   pixels = new int[pixscan * h];          
                   PixelGrabber pg = new PixelGrabber (img,0,0,pixscan,h,pixels,0,pixscan);
                   pg.grabPixels();
              catch(InterruptedException e){};
              scrollX = 0;
              //paint blackbulbs on the offscreen image
              offgraphics.setColor(Color.black);
              offgraphics.fillRect(0,0,d.width,d.height);
              for ( int x=0; x<bulbsW; x++)
              offgraphics.drawImage(bulb, x*bulbS,0,null);
         Image createBulbs(int w,int h){
              int pixels[]= new int[w*h];
              int bulbBits[]= {
                        0,0,1,1,1,1,0,0,
                        0,1,2,1,1,1,1,0,
                        1,2,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,
                        1,1,1,1,1,1,1,1,
                        0,1,1,1,1,1,1,0,
                        0,1,1,1,1,1,0,0,
              int bulbCLUT[] = {0xff000000, 0x00c0c0c0, 0xffffffff};
              for (int i=0; i<w*h; i++)
                   pixels[i] = bulbCLUT[bulbBits[i%bulbBits.length]];
              return createImage(new MemoryImageSource(w,h,pixels,0,w));
         public final Color color(int x, int y){
              int p = pixels[y*pixscan+x];
              Color c;
              if((c=(Color)clut.get(p))== null);
              clut.put(p,c = new Color(p));
              return c;
         public void update() {}
         public void paint(Graphics g) {
              URL url= getDocumentBase();
              String msg = "Docment Base : " + url.toString();
         g.drawString(msg,10,20);
              offgraphics.copyArea(bulbS,0,bulbsW*bulbS-bulbS,d.height,-bulbS,0);
              for (int y =0; y<bulbsH;y++){
                   offgraphics.setColor(color(scrollX, y));
                   offgraphics.fillRect(d.width-bulbS, y*bulbS, bulbS, bulbS);
              offgraphics.drawImage(bulb, d.width-bulbS, 0, null);
              g.drawImage(offscreen,0,0,null);
              scrollX=(scrollX+1)% pixscan;
    Thread t;
         public void run() {
              while (true) {
                   paint(getGraphics());
                   try{Thread.yield();}
                   catch (Exception e){};
                   if(stopflag)
                        break;
         public void start() {
              t = new Thread(this);
              t.setPriority(Thread.MIN_PRIORITY);
              stopflag= false;
              t.start();
         public void stop () {
              stopflag = true;
    }

  • Image FIle Transfer

    This topic may not be appropriate for the 2D forum, but I couldn't find one that deals with images. Please let me know if there's a more appropriate forum.
    I use Java 1.4/JBoss 3.22/Oracle 9i.
    I have a swing client that occasionally needs to transfer image files (jpg and dxf) to and from the database across the WAN. The file size is typically 1MB. I use RMI-over-HTTP for EJB communication between the client and server.
    I need to figure out a way to transfer the files. The ideal would be to bundle BufferedImages in a transfer object that the session bean hands to the client. But, since BufferedImage is not Serializable I need a different method.
    How do people typically do this type of transfer?
    I appreciate any ideas you can offer.
    Thanks,
    --BobC                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    I'm the original poster.
    I've solved the problem of transferring BufferedImages between a client and server using an EJB. I wrote a TransferImage class that wraps the BufferedImage in a byte array, which is serializable. Then I transfer an instance of that object using the bean, and then use readObject() to reconstitute the BufferedImage.
    Here is the TransferImage class:
    package com.whatever;
    import java.awt.image.PixelGrabber;
    import java.awt.image.BufferedImage;
    import java.awt.*;
    import java.io.Serializable;
    import java.io.IOException;
    * This class allows BufferedImages to be serialized so that they can be tranferred
    * using an EJB.
    * <p>
    * NOTE: System.out.printlns are used for logging rather than Log4j for serialization.
    * Author: Bob Carpenter [email protected]
    * Date: Feb 4, 2004
    public class TransferImage extends Canvas
    implements Serializable {
    private transient BufferedImage image = null;
    private int imageType = BufferedImage.TYPE_INT_BGR;
    private Object pix = null;
    private int width = 0;
    private int height = 0;
    * Basic ctor.
    * <p>
    * NOTE: Creates serializable pix object from image.
    * @param image buffered image to be transferred
    * @param imageType type of image - see BufferedImage class
    public TransferImage(BufferedImage image, int imageType)
    throws IOException {
    System.out.println("TransferImage.ctor_entry");
    this.image = image;
    this.imageType = imageType;
    writeObject();
    System.out.println("TransferImage.exit_entry");
    * Writes the image to pix object.
    * <p>
    * NOTE: Uses PixelGrabber to create pix object.
    * @throws IOException
    private void writeObject() throws IOException {
    System.out.println("TransferImage.writeObject_entry");
    try {
    PixelGrabber grabber = new PixelGrabber(image, 0, 0, -1, -1, true);
    grabber.grabPixels();
    this.width = grabber.getWidth();
    this.height = grabber.getHeight();
    System.out.println("TransferImage.writeObject - width = " +width);
    System.out.println("TransferImage.writeObject - height = " +height);
    pix = grabber.getPixels();
    catch(InterruptedException ex) {
    throw new IOException("writeObject - ERROR: " +ex);
    System.out.println("TransferImage.writeObject_exit");
    * Reads the pix object and creates a BufferedImage from it.
    * @throws IOException
    public BufferedImage readObject() throws IOException {
    System.out.println("TransferImage.readObject_entry");
    try {
    int[] imgPix = (int[])pix;
    System.out.println("TransferImage.readObject - imgPixLength = " +imgPix.length);
    image = new BufferedImage(width, height, imageType);
    image.setRGB(0, 0, width, height, imgPix, 0, width);
    catch (Exception ex) {
    System.out.println("TransferImage.readObject - ERROR: " +ex);
    System.out.println("TransferImage.readObject_exit");
    return image;
    * Reads the pix object and returns an array of pixel bytes.
    * <p>
    * NOTE: Doesn't work
    * @throws IOException
    public byte[] readPix() throws IOException {
    System.out.println("TransferImage.readPix_entry");
    // Setup
    byte[] result = null;
    try {
    if(pix == null) throw new Exception("found null pix object");
    int[] imgPix = (int[])pix;
    int imgPixLen = imgPix.length;
    // Convert to bytes - this times out
    for(int i=0; i<imgPix.length; i++) {
    result = new byte[imgPixLen*4];
    int j, shift;
    for(j = 0, shift = 24; j < 4; j++, shift -= 8)
    result[i] += (byte)(0xFF & (imgPix[i] >> shift));
    if(result == null) throw new Exception("not able to read pix object");
    System.out.println("TransferImage.readPix - pixArrayLength = " +result.length);
    catch (Exception ex) {
    System.out.println("TransferImage.readPix - ERROR: " +ex);
    System.out.println("TransferImage.readPix_exit");
    return result;
    // Accessors
    * Gets the BufferedImage object.
    * @return
    public BufferedImage getImage() {
    return image;
    * Gets height of image in pixels.
    * @return
    public int getHeight() {
    return height;
    * Gets width of image in pixels.
    * @return
    public int getWidth() {
    return width;
    To use the class do this:
    //on client (for example)
    BufferedImage bufi = ImageIO.read(new File(<some_filePath>));
    TransferImage tbufi = new TransferImage(bufi, BufferedImage.TYPE_INT_BGR);
    //send tbufi to backend using something like a session bean and a transfer object
    //on backend reconstitute the buffered image
    TransferImage tbufi = spVO.getImage(); //spVO is my transfer object
    BufferedImage bufi = tbufi.readObject();
    I'd like to get readPix() working so that a byte array is returned which can feed directly into a ByteArrayInputStream, which can be useful for things like writing to a BLOB. So, if you figure out how to do that please share it.
    Take care,
    --BobC

  • PB: PixelGrabber, offscreen Image, Windows 98, ie5

    Hello,
    I've got a problem with a bug that occurs under Windows 98, and ie5.
    This is the code of a little applet that works fine under Windows NT, but not under Windows 98:
    This applet draws 3 colors in a square, and use the grabPixel method for catching the pixels of the image and create another image with those pixels.(the image should be the same)
    The problem is that the grabPixel method changes the colors of the pixels. It occurs only with an offscreen Image (that means an Image created with the createImage(w, h) method). there is no problem with a MemoryImageSource, for example.
    I just notice that the ColorModel of an offscreen Image is not the same as the default ColorModel:
    colorModel: java.awt.image.DirectColorModel = {...}
    red_mask: int = 0xf800 (instead of 0x00ff0000 )
    green_mask: int = 0x7e0 (instead of 0x0000ff00 )
    blue_mask: int = 0x1f (instead of 0x000000ff)
    alpha_mask: int = 0x0 (instead of 0xff000000)
    red_offset: int = 0xb
    green_offset: int = 0x5
    blue_offset: int = 0x0
    alpha_offset: int = 0x0
    red_scale: int = 0x1f
    green_scale: int = 0x3f
    blue_scale: int = 0x1f
    alpha_scale: int = 0x0
    But i don't know how to solve the bug.
    Here is the code :
    import java.awt.*;
    import java.awt.image.*;
    import java.applet.*;
    public class AppletFlush extends Applet implements Runnable{
    Thread anim;
    Image memimg;
    boolean bool;
    Image offImage;
    Graphics offGraphics;
         public void init() {
         public void start() {
         anim = new Thread(this);
         anim.start();
    bool = true;
    offImage = this.createImage(100, 100);
    offGraphics = offImage.getGraphics();
         public synchronized void stop() {
         anim = null;
         notify();
         public synchronized void run() {
         while (Thread.currentThread() == anim) {
    int[] pixels = new int[100 * 100];
    int color = 0;
    //set the pixels of a squared image that contains 3 colors (this is my reference image)
    if (bool)
    bool = false;
    for (int i=0; i<100; i++)
    if (i<33)
    color = 0xffff0000;
    else if (i<66)
    color = 0xff00ff00;
    else
    color = 0xff0000ff;
    for (int j=0; j<100; j++)
    pixels[i*100 + j] = color;
    else
    //grab the pixels of the offscreen image(here is the problem)
    PixelGrabber pg = new PixelGrabber(offImage, 0, 0, 100, 100, pixels, 0, 100);
    try
    pg.grabPixels();
    catch (InterruptedException ex)
    System.out.println("erreur pendant gragPixels !!!");
    //create the new image with the pixels
    MemoryImageSource imgsrc = new MemoryImageSource(100, 100, pixels, 0, 100);
    memimg = createImage(imgsrc);
    //draw the image in the offscreen image
    offGraphics.drawImage(memimg, 0, 0, null);
              repaint();
              try {wait(1000);} catch (InterruptedException e) {return;}
         public void paint(Graphics g) {
         // display the offscreen image
         g.drawImage(offImage, 0, 0, this);
    PLEASE HELP !
    YaYa

    try
    public void paint(Graphics g )
    if((_offScreen != null)&&(offScreenImage != null))
    // put your stuff here
    else
    update(g);
    g.dispose();
    g.finalize();
    return;
    public void update(Graphics g)
    if( offScreenImage == null)
    offScreenImage = this.createImage( width, height );
    if( _offScreen == null)
    _offScreen = offScreenImage .getGraphics();
    paint(g);
    }

  • Error with PixelGrabber

    I am following some code on face recognition. I have my main class which is pretty straight forward
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class FR extends JFrame {
           static Image[] trainingImages;
           static Image[] EigenImages;
           static Image[] diffImages;
          static image trainingSet;
          static Image averageImage;
          static display draw;
          static String testImage ="testImages/anita3.GIF";
           static int w;
          public FR(String s)
                 super(s);
                 trainingSet = new image("TrainingPics",this);
             draw = new display();
                 this.w=trainingSet.w;
    public static void main(String s[]) {
             FR frame = new FR("Face Recognition");
             trainingImages = draw.drawBehind(trainingSet.TrainingImageVector,trainingSet.w,trainingSet.h);
             averageImage = draw.arrayToImage(trainingSet.averageImage ,trainingSet.w,trainingSet.h);
             diffImages = draw.drawBehind(trainingSet.diffImageVector,trainingSet.w,trainingSet.h);
             EigenImages = draw.drawBehind(trainingSet.EigenVector,trainingSet.w,trainingSet.h);
             trainingSet.detectImage(testImage);
                    frame.addWindowListener(
                            new WindowAdapter() {
                                    public void windowClosing(WindowEvent e) {
                                            System.exit(0);
             frame.setSize(new Dimension(1030,750));
                frame.setVisible(true);
                frame.repaint();
            public void paint(Graphics g) {
                // g.drawImage(averageImage, 0, 0, this);
                       int b = 0;
                       int l = 0;
                      g.drawImage(trainingSet.loadImageFromFile(testImage),b,l,this);
                      g.drawImage(trainingImages[trainingSet.smallestTwoNorm], w, l, this);
                       /* for (int a = 0; a <4; a++) {
                            //g.drawImage(diffImages[a], b, l, this);
                            g.drawImage(trainingImages[a], b, l, this);
                            //g.drawImage(EigenImages[a], b, l, this);
                               b = b + w;
    }Now most of them Image Arrays are assigned their values from the display class and drawBehind method
    class display{
             *  Convert a pixel of array into a buffer image
             *Accepts a vector of integer arrays as its elements
             *Convert each of vector element to an Image object and
             *stores it in an Image array and returns that array .
             * w , h are width and heights of an image.
            public Image[] drawBehind(Vector v,int w,int h) {
                     Image[] temp = new Image[v.size()];
                     for (int a = 0; a < v.size(); a++) 
                       temp[a] = arrayToImage((int[]) v.elementAt(a), w, h);
              return temp;
            }

    And the important part of my own image class is
    class image{
    static File[] imageFiles;                     // of all images we will be loading
    int[] averageImage;                          // averageImage=average value of i'th pixel over all images = sum[i]/NumOfImages
    static int NumOfImages,w,h;                //NumberOfImages,width and height
    static Vector TrainingImageVector;           //All images will be stored in this vector
    static DoubleMatrix2D eigenVectCovMatrix;//EigenVector for the Covariance Matrix of diffImageMatrix
    static DoubleMatrix2D diffImageMatrix;      //Matrix representation of difference images [each column rep. 1 image]
    static DoubleMatrix2D weightMatrix;      // projection of (original images-averageImage) onto eigenfaces
    static Vector diffImageVector;                // Each vector element is an array of difference pixels.
    static Vector EigenVector;
    static Component component;
    static double twoNorm[];                     //TwoNorm of the projected image onto the weight matrix.
    Image[] ImgA;                                    //All actual images are stored in this array.
    int smallestTwoNorm;
    //WriteToFile writer;
    /* Constructor of image class
    String dr specifies the directory where all the images are stored
    Component component is the frame on which all the images will be displayed
    public image(String dr,Component component)
         File f = new File(dr);
         imageFiles = f.listFiles();
         this.component = component;
         NumOfImages = imageFiles.length; // number of images in that directory
         System.out.println("Total number of training images : "+NumOfImages);
         diffImageVector = new Vector();
         TrainingImageVector = loadImgsIntoVector();
         averageImage = findAverageImage(TrainingImageVector);
    // writer = new WriteToFile();
              for (int a = 0; a < NumOfImages; a++)
                   diffImageVector.addElement(findDeviated((int[])TrainingImageVector.elementAt(a)));
         diffImageMatrix = ConvertVectorIntoMatrix(diffImageVector);     
         // eigenVectCovMatrix = ConvertVectorIntoMatrix(EigenVector);
         eigenVectCovMatrix = findEigenVector(diffImageMatrix);
    EigenVector = ConvertMatrixIntoVector(eigenVectCovMatrix); //need in display class
         normalizeColumns(eigenVectCovMatrix);
         System.out.println("Normalized EigenvectorCovMatrix=\n");
         printPartOfDoubleMatrix2D(eigenVectCovMatrix,10,3);
         // END CHANGE
         weightMatrix = project(diffImageMatrix);
    //     classify(ImgA[testImg-1]); //we are not using testImg number
    //     writer.writeEigenMatrix(weightMatrix);
    public image(Component component){this.component=component;}
    // Normalize (2-norm=1) all columns in m
    private void normalizeColumns(DoubleMatrix2D m){
         // for each column
         // normalize the column, that is
         //      find the norm of the column
         //      divide column by the norm
         for(int c=0;c<m.columns();c++){
              double norm=0;
              for(int r=0;r<m.rows();r++)norm=norm+(m.get(r,c)*m.get(r,c));
              norm=Math.sqrt(norm);
              for(int r=0;r<m.rows();r++)m.set(r,c,m.get(r,c)/norm);
    public void detectImage(String fileName){
    classify(loadImageFromFile(fileName));     
    * Place each image into an integer array and stores that array in vector and returns that vector
    * Also stores raw images in array ImgA
    public Vector loadImgsIntoVector() {
         Vector imageVec = new Vector();
         ImgA = new Image[NumOfImages];
              for (int i = 0; i < imageFiles.length; i++) {
              //Get all the images in an array
                   ImgA[i] = loadImageFromFile(imageFiles[i].getAbsolutePath());
                   imageVec.addElement(grabPixels(ImgA[i]));
                   System.out.println(imageVec.size());
                   System.out.println(imageFiles.length);
    return imageVec;
    * Load the image specified by filename
    * @param fileName Description of the Parameter
    * @return Description of the Return Value
    public Image loadImageFromFile(String fileName) {
         Image img = Toolkit.getDefaultToolkit().getImage(fileName);
              try {
                   MediaTracker tracker = new MediaTracker(component);
                   tracker.addImage(img, 0);
                   tracker.waitForID(0);
              } catch (Exception e) {
                   System.out.println("Cant load image file " + fileName);
                   System.exit(0);
         System.out.println(fileName);
         System.out.println("w=" + img.getWidth(null) + "h=" + h);
         return img;
    * Return an array of the pixels from image i
    * pixel x,y gets stored in the width*y+x position of the array
    public static int[] grabPixels(Image i) {
         w = i.getWidth(null);      
         h = i.getHeight(null);
              System.out.println("w=" + w + "h=" + h);
         int[] pixels = new int[w * h];
         PixelGrabber pg = new PixelGrabber(i, 0, 0, w, h, pixels, 0, w);
              try {
                   pg.grabPixels();
              } catch (InterruptedException e) {
                   System.err.println("interrupted waiting for pixels!");
                   System.exit(0);
              if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
                   System.err.println("image fetch aborted or errored");
                   System.exit(0);
         return pixels;
    } When i run it, the output is to my console and displaysTotal number of training images : 7
    C:\Users\Nick\Desktop\New Folder\TrainingPics\amber1.gif
    w=250h=0
    w=250h=300
    1
    7
    C:\Users\Nick\Desktop\New Folder\TrainingPics\amy1.gif
    w=250h=300
    w=250h=300
    2
    7
    C:\Users\Nick\Desktop\New Folder\TrainingPics\andrew1.gif
    w=250h=300
    w=250h=300
    3
    7
    C:\Users\Nick\Desktop\New Folder\TrainingPics\andy1.gif
    w=250h=300
    w=250h=300
    4
    7
    C:\Users\Nick\Desktop\New Folder\TrainingPics\andyp1.gif
    w=250h=300
    w=250h=300
    5
    7
    C:\Users\Nick\Desktop\New Folder\TrainingPics\anita1.gif
    w=250h=300
    w=250h=300
    6
    7
    C:\Users\Nick\Desktop\New Folder\TrainingPics\Thumbs.db
    w=-1h=300
    w=-1h=-1
    image fetch aborted or errored
    Press any key to continue...So this is being returned from my image class, grabPixels method.  Can anyone see a logical reason as to why this might be happening?
    cheers                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Problem using PixelGrabber ( cannot resolve symbol ) - newbie

    Hi All,
    I have a problem with my short program because the compiler write this (jdk1.4) :
    img.java:17: cannot resolve symbol
    symbol : constructor PixelGrabber (java.awt.Image,int,int,int,int,int[],int)
    location: class java.awt.image.PixelGrabber
    PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this
    ),image.getHeight(this),pixels,0);
    ^
    1 error
    ... And I wrote that in my code :
    ( all is OK, the bug is only when I uncomment the line where the PixelGrabber object
    is needed in my program ).
    Thanks if you have any idea of solution to solve this problem or a doc,
    ( I don't find the answer to my problem in http://java.sun.com/j2se/1.4/docs/api/java/awt/image/PixelGrabber.html ),
    import java.awt.*;
    import java.awt.image.*;
    import java.applet.*;
    import java.awt.image.PixelGrabber;
    public class img extends Applet {
    Image image;
    int pixels[];
    public void init() {
    image = getImage(getDocumentBase(), "rouge.jpg");
    pixels = new int[image.getWidth(this) * image.getHeight(this)];
    PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this),image.getHeight(this),pixels,0);
         pg.grabPixels();
    public void paint(Graphics g) {
              String s = Integer.toString(pixels[5], 16);
              g.drawString(s, 50, 50);

    Hi,
    PixelGrabber needs one more parameter scansize (width).
    change this line;
    PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this),image.getHeight(this),pixels,0);
    to:
    PixelGrabber pg = new PixelGrabber(image,0,0,image.getWidth(this),image.getHeight(this),pixels,0, image.getWidth(this)
    );

  • How can i user  PixelGrabber in javafx.scee.image.Image

    how can i user PixelGrabber in javafx.scee.image.Image

    You can either get a java.awt.BufferedImage snapshot of the Image, and use a PixelGrabber with that:
    import javafx.scene.image.Image ;
    import javafx.embed.swing.SwingFXUtils ;
    import java.awt.image.BufferedImage ;
    import java.awt.image.PixelGrabber ;
    Image img = ... ;
    BufferedImage bImage = SwingFXUtils.fromFXImage(img, null);
    PixelGrabber grabber = new PixelGrabber(bImage, ...);Or, you can use a javafx.scene.image.PixelReader, which has essentially the same functionality:
    import javafx.scene.image.Image ;
    import javafx.scene.image.PixelReader ;
    import javafx.scene.image.PixelFormat ;
    Image img = ... ;
    PixelReader reader = img.getPixelReader();
    int[] pixelArray = ... ;
    int x, y, w, h ; // bounds of image portion from which to read pixels
    reader.getPixels(x, y, w, h, PixelFormat.getIntArgbInstance(), pixelArray, 0, w); // see javadocs for full description of parameters(The second solution is probably better; the first might be useful if you have a lot of existing functionality that relies on a PixelGrabber.)

  • Filename in import statement

    Hi srinivas bobbala,
    Thank you for your response.But I think my quesition was not clear.My ques... is for suppose there is one datafile for importing like.. "datafile_21" Here my intention is it takes file from datafile_21 only but it appears in import statement like datafile_21<<curmon>>.
    import database sample.sample data from data_file "c:\\ABC\datafile_21_AUG.txt" using server rules_file datafile on error abort;
    In this it takes datafile from datafile_21.But it appears like datafile_21_AUG in import statement.This AUG coming from batch file.
    Essmsh c:\\ABC\loadmxl.mxl %curmon%

    No it is not possible.
    I assume the data file "datafile_21" is first renamed to datafile_21_${CurrMth} in the batchscript.
    After that this data file *datafile_21_${CurrMth}* is pointed in the import statement.
    In the logs you will see this file as datafile_21_Aug.

Maybe you are looking for

  • How do I restore vista to original using the on-board recovery drive?

    I have a CQ60-410US Notebook Pc (HP of course), but recently it will not start normally.  It launches the repair module, then says it can't repair the computer automatically.  I go back to the screen where there is an option to start Windows normally

  • PO creation-ME21n-Why SAP does not check company code and Plant relation

    Hi All, Does someone know, why SAP does not check Plant and company code relation at the time of PO creation or how can we put validation between plant and company code at the time of PO creation. <b>Example:</b> Suppose i have a company 0001 which i

  • How to restore command shift 3 instead of grab

    I always used command+shift+3 to photograph the desktop and command+shift+4 to photograph a selection of the screen. Then, one day I lost it and had to use Grab, which it takes longer to use. Can anyone help me restore that? Thank you. Beltran

  • Web service published but not visible

    Hi, I have developed a Webservice from a WSDL file i created from a XI outbound interface following the steps given in the thread below. /people/sap.user72/blog/2005/11/17/xi-how-to-publish-wsdl-generated-from-xi-to-uddi In the UDDI Client i got the

  • Simple Console Display Manager

    I created a forked project from "The Console Display Manager" CDM, thanks Ghost1227 for your work I simplified its interface and added new options. It has all its initial features (less theming):    - Multiple X sessions (user logins are all handled