pixel manipulation

Can anyone tell me if it's possible to manipulate a single pixel at a time in Java? For example, change the color of a pixel at location (x, y) to the color (r, b, g). How do I do that?

Comments

  • : Can anyone tell me if it's possible to manipulate a single pixel at a time in Java? For example, change the color of a pixel at location (x, y) to the color (r, b, g). How do I do that?
    :
    I advice you to take a look at the Java Advanced Imaging API http://java.sun.com/products/java-media/jai/ as well as the graphics classes. I know it is possible, but can't remember the exact code right now. I've done a lot of image manipulation in Java, and it works just great. The JAI API is very useful when manipulating images.
  • Hi Cthulhu

    Thanks for the reply and the link.

    The link you gave me was unfortunatly not very helpful. I have all the help files from sun and those don't even tell me much. There must be simple way of manipulating the colour of a pixel there somewhere, but I have searched these help files and Sun's website with no success.

    Pixel manipulation is one of the core reasons I started studying programming in the first place. I still can't decide which language to use. I've always supported C++ above all other languages because it's suppose to be powerful. But now I'm not so sure since Java seems easier (I like the object orientation concept). I know how to do pixel manipulation using Delphi/Pascal, but those are horrible languages and I don't want to use them for any applications. I would be so greatfull if someone can tell me how to do this in either Java or C++!

    : : Can anyone tell me if it's possible to manipulate a single pixel at a time in Java? For example, change the color of a pixel at location (x, y) to the color (r, b, g). How do I do that?
    : :
    : I advice you to take a look at the Java Advanced Imaging API http://java.sun.com/products/java-media/jai/ as well as the graphics classes. I know it is possible, but can't remember the exact code right now. I've done a lot of image manipulation in Java, and it works just great. The JAI API is very useful when manipulating images.
    :

  • : Hi Cthulhu
    :
    : Thanks for the reply and the link.
    :
    : The link you gave me was unfortunatly not very helpful. I have all the help files from sun and those don't even tell me much. There must be simple way of manipulating the colour of a pixel there somewhere, but I have searched these help files and Sun's website with no success.
    :
    : Pixel manipulation is one of the core reasons I started studying programming in the first place. I still can't decide which language to use. I've always supported C++ above all other languages because it's suppose to be powerful. But now I'm not so sure since Java seems easier (I like the object orientation concept). I know how to do pixel manipulation using Delphi/Pascal, but those are horrible languages and I don't want to use them for any applications. I would be so greatfull if someone can tell me how to do this in either Java or C++!
    :
    : : : Can anyone tell me if it's possible to manipulate a single pixel at a time in Java? For example, change the color of a pixel at location (x, y) to the color (r, b, g). How do I do that?
    : : :
    : : I advice you to take a look at the Java Advanced Imaging API http://java.sun.com/products/java-media/jai/ as well as the graphics classes. I know it is possible, but can't remember the exact code right now. I've done a lot of image manipulation in Java, and it works just great. The JAI API is very useful when manipulating images.
    : :
    :
    :
    It would be interesting to know a bit more about what you need done. I've done some edge detection, histogram equalization and the likes in Java, and it works great. The advantage Java has over C++ is that it is easier to start programming, because you have many large and helpful API's. C++ is faster, but not by a significant amount on smaller programs. I haven't tried C++ on manipulation though. I have some code on my laptop ( which is at home, I'm at work now ) that I can take a look at later tonight, but I can't remember if I had manipulation of each and every pixel.
    As I said, would be interesting to know exactly what you need done, maybe I can help more.
  • : It would be interesting to know a bit more about what you need done. I've done some edge detection, histogram equalization and the likes in Java, and it works great. The advantage Java has over C++ is that it is easier to start programming, because you have many large and helpful API's. C++ is faster, but not by a significant amount on smaller programs. I haven't tried C++ on manipulation though. I have some code on my laptop ( which is at home, I'm at work now ) that I can take a look at later tonight, but I can't remember if I had manipulation of each and every pixel.
    : As I said, would be interesting to know exactly what you need done, maybe I can help more.
    :


    Well, I'm trying do design a specific 3D engine that'll be used by various applications. I want to use it with two types of programs, business (accounts, etc...) that'll also entail alot of teaching, and scientific, that'll also be eduactional by nature. I'm trying to get a computer to more of a use for researching events. This engine I'm working on will do the trick, but changing the color of a specific pixel is the core operation of this engine.
  • : Well, I'm trying do design a specific 3D engine that'll be used by various applications. I want to use it with two types of programs, business (accounts, etc...) that'll also entail alot of teaching, and scientific, that'll also be eduactional by nature. I'm trying to get a computer to more of a use for researching events. This engine I'm working on will do the trick, but changing the color of a specific pixel is the core operation of this engine.
    :

    Building your engine over OpenGL would be a much smarter idea, or also check out Anfy3D.

    Next, you can write object-oriented code in C++. In fact, C++ is typically called an object-oriented language though it's more of a multi-paradigm language.

    Finally, to manipulate a pixel at the low-level you would use a MemoryImageSource. You can get the pixel data with PixelGrabber. Both are part of java.awt.image.

    PS: putPixel (or whatever you want to call it) is Satan incarnate (at least if you are going for speed). putPixel does provide a nice layer of abstraction, but the cost usually isn't too worth while.

    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

  • : : Well, I'm trying do design a specific 3D engine that'll be used by various applications. I want to use it with two types of programs, business (accounts, etc...) that'll also entail alot of teaching, and scientific, that'll also be eduactional by nature. I'm trying to get a computer to more of a use for researching events. This engine I'm working on will do the trick, but changing the color of a specific pixel is the core operation of this engine.
    : :
    :
    : Building your engine over OpenGL would be a much smarter idea, or also check out Anfy3D.
    :
    : Next, you can write object-oriented code in C++. In fact, C++ is typically called an object-oriented language though it's more of a multi-paradigm language.
    :
    : Finally, to manipulate a pixel at the low-level you would use a MemoryImageSource. You can get the pixel data with PixelGrabber. Both are part of java.awt.image.
    :
    : PS: putPixel (or whatever you want to call it) is Satan incarnate (at least if you are going for speed). putPixel does provide a nice layer of abstraction, but the cost usually isn't too worth while.
    :
    : "We can't do nothing and think someone else will make it right."
    : -Kyoto Now, Bad Religion
    :
    :

    You might also want to check out the Java3D API. Using pixel manipulation to do 3D is not the best way "nowerdays" (your graphics adapter would get really bored ... you know what I mean ;-)

    I've already done some things with MemoryImageSource a long time ago which was very easy to use I remember. It was one of these funny 256x256 wobblers - neat but useless. But I remember that I was quite surprised (in a good meaning) about the execution speed on my old P200MMX. As much as I remember, you can easily use an int[] array as the pixel source and create an Image via MemoryImageSource in the paint method of your (sub-class of) Canvas. That makes pixel manipulation as easy as "var video : array[0..65534] of Byte absolute $A000:$0" - good old Mode13 days ... where are you gone :-(

    What was kinda kicking me out of my "Java = slow" thinking about 3 years ago where the Java-Demos from the Demo-Group called "Komplex". http://www.komplex.org
    Even today it's still a nice piece o'work ;-) It's good solid 3D done with pixel manipulation.

    But I still believe that Java3D would be the best solution if you want to do it with Java - except you like to create your own poly-fill, shader, etc. routines ... that might be fun - but unfortunately it's out of date - and I'm still sad about that fact :-(

    tron.
  • Did you find an application that will do the pixel manipulation as you described? I am looking for a similar tool. Please email me at [email protected] with what you found.

    Thanks for your response.


    Timothy
  • You'd learn a lot from a 3D texture mapping application I made.

    It manipulates pixel by pixel quite efficiently by accessing them through an array internally used by a BufferedImage.

    [link=http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=5851&lngWId=2]http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=5851&lngWId=2[/link]
  • Look at this object java.awt.image.PixelGrabber (javadoc has good examples).
    [code]
    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 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]);
    }
    }
    }
    [/code]
    You can get Image from your content pane. Do you need to render each pixel? If not, you can use Graphics2D to build your image or polygon.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories