Pixelgrabber and Vectors, changes not happening. - Java

This is a discussion on Pixelgrabber and Vectors, changes not happening. - Java ; Hi All, I am trying to use pixelgrabber, use vectors and storing the results. The program below is my program. However the "if " condition is not recognized during a run at "private String RestateClrLine (String mSt) {" .... and ...

+ Reply to Thread
Results 1 to 6 of 6

Pixelgrabber and Vectors, changes not happening.

  1. Default Pixelgrabber and Vectors, changes not happening.

    Hi All,

    I am trying to use pixelgrabber, use vectors and storing the results.
    The program below is my program. However the "if " condition is not
    recognized during a run at "private String RestateClrLine (String
    mSt) {" ....
    and thus the changes are not reflected in the output file saved.

    Simply put, I am trying to change the color of the "000000" to any
    other color, say "ff0000" and it is not happening.

    TIA

    bH

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.io.*;
    import java.util.*;

    public class applicPxlgrabMTstoBytes {

    public static void main(String[] args) {
    JFrame frame = new ImageProcessingFrame();
    frame.show();
    }
    }

    class ImageProcessingFrame
    extends JFrame
    implements ActionListener {

    public ImageProcessingFrame() {
    setTitle("PxlgrabMTstoBytes");

    int frameX = 600;
    int frameY = 800;
    setSize(frameX, frameY);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    }
    });

    Container contentPane = getContentPane();
    panel = new ImageProcessingPanel();
    contentPane.add(panel, "Center");

    JMenu fileMenu = new JMenu("File");
    openItem = new JMenuItem("Open");
    openItem.addActionListener(this);
    fileMenu.add(openItem);

    exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(this);
    fileMenu.add(exitItem);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);
    setJMenuBar(menuBar);
    }

    public void actionPerformed(ActionEvent evt) {
    Object source = evt.getSource();
    if (source == openItem) {
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("images"));
    chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
    public boolean accept(File f) {
    String name = f.getName().toLowerCase();
    return name.endsWith(".gif")
    || name.endsWith(".jpg")
    || name.endsWith(".jpeg")
    || name.endsWith(".png") // added this on 17 June 2003
    || f.isDirectory();
    }

    public String getDescription() {
    return "Image files";
    }
    });

    int r = chooser.showOpenDialog(this);
    if (r == JFileChooser.APPROVE_OPTION) {
    String name = chooser.getSelectedFile().getAbsolutePath();
    panel.loadImage(name);
    }
    }
    else if (source == exitItem) {
    System.exit(0);
    }

    }

    private ImageProcessingPanel panel;
    private JMenuItem openItem;
    private JMenuItem exitItem;
    //private RestateClrLine mSt;
    }

    class ImageProcessingPanel
    extends JPanel {

    public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (image != null) {
    g.drawImage(image, 0, 0, null);
    }
    }

    public void loadImage(String name) {
    String sourceCodeString;
    int iwidth;
    int iheight;
    int scansize;
    int[] pixels;
    Vector vectorColorData = new Vector();
    Vector vectorDimensions = new Vector();
    Image loadedImage = Toolkit.getDefaultToolkit().getImage(name);
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(loadedImage, 0);
    try {
    tracker.waitForID(0);
    image = new BufferedImage(600, 800, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    g2.drawImage(loadedImage, 0, 0, null);

    }
    catch (InterruptedException e) {
    }

    try {
    iwidth = loadedImage.getWidth(null);
    vectorDimensions.addElement(Integer.toString(iwidth));
    iheight = loadedImage.getHeight(null);
    vectorDimensions.addElement(Integer.toString(iheight));
    System.out.println("the width is " + iwidth);
    System.out.println("the height is " + iheight);
    scansize = iwidth * iheight;
    pixels = new int[scansize];
    PixelGrabber myPixelGrabber = new PixelGrabber(image, 0, 0,
    iwidth,
    iheight, pixels, 0, iwidth);
    myPixelGrabber.grabPixels();

    String mSet;
    String s;
    String si;
    String mest;
    int cr;
    int cg;
    int cb;
    int hcb;
    for (int i = 0; i < scansize; i++) {
    mSet = "";
    s = Integer.toString(i) + ". = Red Hex " +
    Integer.toString( ( (int[]) pixels)[i] >> 16 & 0xff, 16);
    si = "";

    //cr = (((int[])pix)[i] >> 16 & 0xff); //, 16);
    si = Integer.toString( ( (int[]) pixels)[i] >> 16 & 0xff, 16);
    if (si.length() < 2) { // add an extra "0" in front of the
    single
    si = "0" + si;
    }
    mSet = mSet + si;
    s = Integer.toString(i) + ". = Green Hex " +
    Integer.toString( ( (int[]) pixels)[i] >> 8 & 0xff, 16);
    si = "";

    //cg = (((int[])pix)[i] >> 8 & 0xff); //, 16);
    si = Integer.toString( ( (int[]) pixels)[i] >> 8 & 0xff, 16);
    if (si.length() < 2) {
    si = "0" + si;
    }
    mSet = mSet + si;
    s = Integer.toString(i) + ". = Blue Hex " +
    Integer.toString( ( (int[]) pixels)[i] & 0xff, 16);
    si = "";

    //cb = (((int[])pix)[i] & 0xff); //, 16);
    si = Integer.toString( ( (int[]) pixels)[i] & 0xff, 16);
    if (si.length() < 2) {
    si = "0" + si;
    }

    mSet = mSet + si;
    RestateClrLine(mSet);
    vectorColorData.addElement(mSet);

    }
    System.out.println(
    "Will be finsihed storing color bytes into a file after
    image appears ");
    }
    catch (InterruptedException ie) {
    System.out.println("Error Gathering Pixels");
    }

    try {
    FileOutputStream fout = new
    FileOutputStream("ColorPixlData.txt");
    ObjectOutputStream out = new ObjectOutputStream(fout);
    out.writeObject(vectorDimensions);
    out.writeObject(vectorColorData);
    out.flush();
    out.close();
    repaint();
    }
    catch (IOException e) {
    System.out.println("error with write to file");
    }

    repaint();
    }

    private void filter(BufferedImageOp op) {
    BufferedImage filteredImage
    = new BufferedImage(image.getWidth(), image.getHeight(),
    image.getType());

    op.filter(image, filteredImage);
    image = filteredImage;
    repaint();
    }

    private BufferedImage image;


    // look at a mStr value
    private String RestateClrLine (String mSt) {
    String res ="";
    System.out.println(mSt );
    if (mSt == "000000"){
    res = "ff0000";
    System.out.println("Y");
    }
    else {
    res = mSt;
    System.out.println("N");
    }
    return res;
    }

    }
    // end of program applicPxlgrabMTstoBytes


  2. Default Re: Pixelgrabber and Vectors, changes not happening.

    On Fri, 27 Jul 2007 16:00:42 -0700, bH wrote:
    > if (mSt == "000000"){


    String == comparison only works under certain conditions that are not
    true for about 95% of the cases.

    The short answer:

    Use "000000".equals(mSt) instead of mSt == "000000"

    The long answer:

    There is a long thread explaining this topic in full detail in the
    comp.lang.java.programmer group, entitled "String.equals()" by Chameleon,
    started on July 22, 2007.

  3. Default Re: Pixelgrabber and Vectors, changes not happening.

    On Jul 27, 8:06 pm, Joshua Cranmer <Pidgeo...@verizon.net> wrote:
    > On Fri, 27 Jul 2007 16:00:42 -0700, bH wrote:
    > > if (mSt == "000000"){

    >
    > String == comparison only works under certain conditions that are not
    > true for about 95% of the cases.
    >
    > The short answer:
    >
    > Use "000000".equals(mSt) instead of mSt == "000000"
    >
    > The long answer:
    >
    > There is a long thread explaining this topic in full detail in the
    > comp.lang.java.programmer group, entitled "String.equals()" by Chameleon,
    > started on July 22, 2007.


    Hi Joshua,

    Thanks for your help.

    First I discarded entirely:
    private String RestateClrLine (String mSt) {
    String res ="";
    System.out.println(mSt );
    if (mSt == "000000"){
    res = "ff0000";
    System.out.println("Y");
    }
    else {
    res = mSt;
    System.out.println("N");
    }
    return res;
    }


    Revision as you have suggested:


    mSet = mSet + si;
    if ("000000".equals( mSet)) {
    mSet = "ff0000";
    }
    vectorColorData.addElement(mSet);

    or this will also work

    mSet = mSet + si;
    if( mSet.equals("000000")) {
    mSet = "ff0000";
    }
    vectorColorData.addElement(mSet);

    Thanks again,

    bH


  4. Default Re: Pixelgrabber and Vectors, changes not happening.

    bH wrote:
    > On Jul 27, 8:06 pm, Joshua Cranmer <Pidgeo...@verizon.net> wrote:
    >> On Fri, 27 Jul 2007 16:00:42 -0700, bH wrote:
    >>> if (mSt == "000000"){

    >> String == comparison only works under certain conditions that are not
    >> true for about 95% of the cases.
    >>
    >> The short answer:
    >>
    >> Use "000000".equals(mSt) instead of mSt == "000000"
    >>
    >> The long answer:
    >>
    >> There is a long thread explaining this topic in full detail in the
    >> comp.lang.java.programmer group, entitled "String.equals()" by Chameleon,
    >> started on July 22, 2007.

    >
    > Hi Joshua,
    >
    > Thanks for your help.
    >
    > First I discarded entirely:
    > private String RestateClrLine (String mSt) {
    > String res ="";
    > System.out.println(mSt );
    > if (mSt == "000000"){
    > res = "ff0000";
    > System.out.println("Y");
    > }
    > else {
    > res = mSt;
    > System.out.println("N");
    > }
    > return res;
    > }
    >
    >
    > Revision as you have suggested:
    >
    >
    > mSet = mSet + si;
    > if ("000000".equals( mSet)) {
    > mSet = "ff0000";
    > }
    > vectorColorData.addElement(mSet);
    >
    > or this will also work
    >
    > mSet = mSet + si;
    > if( mSet.equals("000000")) {
    > mSet = "ff0000";
    > }
    > vectorColorData.addElement(mSet);
    >
    > Thanks again,


    The second form may in some applications require a separate check for
    non-null-ness, actually an advantage in my book, and also recommended by the
    knowledgeable Patricia Shanahan.

    if ( mSet != null && mSet.equals("000000")) {

    While some think this is too hard (whiners), Patricia has made the excellent
    point that when null is a "Bad Thing", an explicit check for it emphasizes
    that in a "literate code" way. The shortcutters argue that the first form
    will yield "not equal" if mSet is null, so the job is done. I argue that null
    is a special value, and should be treated as an out-of-band value nearly always.

    --
    Lew

  5. Default Re: Pixelgrabber and Vectors, changes not happening.

    On Jul 28, 12:38 am, Lew <l...@lewscanon.nospam> wrote:
    > bH wrote:
    > > On Jul 27, 8:06 pm, Joshua Cranmer <Pidgeo...@verizon.net> wrote:
    > >> On Fri, 27 Jul 2007 16:00:42 -0700, bH wrote:
    > >>> if (mSt == "000000"){
    > >> String == comparison only works under certain conditions that are not
    > >> true for about 95% of the cases.

    >
    > >> The short answer:

    >
    > >> Use "000000".equals(mSt) instead of mSt == "000000"

    >
    > >> The long answer:

    >
    > >> There is a long thread explaining this topic in full detail in the
    > >> comp.lang.java.programmer group, entitled "String.equals()" by Chameleon,
    > >> started on July 22, 2007.

    >
    > > Hi Joshua,

    >
    > > Thanks for your help.

    >
    > > First I discarded entirely:
    > > private String RestateClrLine (String mSt) {
    > > String res ="";
    > > System.out.println(mSt );
    > > if (mSt == "000000"){
    > > res = "ff0000";
    > > System.out.println("Y");
    > > }
    > > else {
    > > res = mSt;
    > > System.out.println("N");
    > > }
    > > return res;
    > > }

    >
    > > Revision as you have suggested:

    >
    > > mSet = mSet + si;
    > > if ("000000".equals( mSet)) {
    > > mSet = "ff0000";
    > > }
    > > vectorColorData.addElement(mSet);

    >
    > > or this will also work

    >
    > > mSet = mSet + si;
    > > if( mSet.equals("000000")) {
    > > mSet = "ff0000";
    > > }
    > > vectorColorData.addElement(mSet);

    >
    > > Thanks again,

    >
    > The second form may in some applications require a separate check for
    > non-null-ness, actually an advantage in my book, and also recommended by the
    > knowledgeable Patricia Shanahan.
    >
    > if ( mSet != null && mSet.equals("000000")) {
    >
    > While some think this is too hard (whiners), Patricia has made the excellent
    > point that when null is a "Bad Thing", an explicit check for it emphasizes
    > that in a "literate code" way. The shortcutters argue that the first form
    > will yield "not equal" if mSet is null, so the job is done. I argue that null
    > is a special value, and should be treated as an out-of-band value nearly always.
    >
    > --
    > Lew- Hide quoted text -
    >
    > - Show quoted text -



    Thanks to Lew and Patricia Shanahan

    bH


  6. Default Re: Pixelgrabber and Vectors, changes not happening.

    >Use "000000".equals(mSt) instead of mSt == "000000"
    see http://mindprod.com/jgloss/gotchas.html#COMPARISON
    http://mindprod.com/jgloss/interned.html
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com

+ Reply to Thread

Similar Threads

  1. PixelGrabber question
    By Application Development in forum Java
    Replies: 4
    Last Post: 08-19-2007, 02:03 PM
  2. What's Happening With This TIFF?
    By Application Development in forum Adobe Photoshop
    Replies: 12
    Last Post: 08-06-2007, 07:35 AM
  3. What is happening?!
    By Application Development in forum Adobe Premiere
    Replies: 1
    Last Post: 10-29-2005, 01:50 AM
  4. reflection is not happening, why?
    By Application Development in forum Graphics
    Replies: 6
    Last Post: 04-21-2005, 05:32 PM
  5. Re: What's happening?
    By Application Development in forum Microsoft Exchange
    Replies: 0
    Last Post: 07-10-2003, 06:24 PM