Pixel-by-pixel graphics

I'm working on a bioinformatics project that will use java. My data will be represented pixel-by-pixel, where the color of that pixel will represent of three variables in the dataset. The x and y dimensions are used for two other variables.
I've been looking through the Java 2D API and tutorials, and there doesn't seem to be a tutorial on pixel-by-pixel specification. Everything seems to be discussing shapes and lines instead.
In the end, I want a JFrame to pop up, draw the data to the screen, save the graph as a lossless, 8-color picture file, and terminate. Eventually, I hope to have thousands of these files, and I want to animate a change in the data over thousands of generations.
But first things first... how do I deal with pixel-by-pixel graphics generation?

g.setRGB(int x, int y, int rgb) where g is the graphics context of a BufferedImage, for example
buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = buf.getGraphics();
g.setRGB(x, y, rgb);
//or//
g.setRGB(x, y, new Color(r, g, b).getRGB());
have fun!

Similar Messages

  • Can you make a background a random multicolor, pixel by pixel?

    In any basic window, would you be able to color the background, like, a random multicolor? Let me explain...
    Say I have a window that was generated with Java. Typically, this window would have a white background. Instead of that, I'd like the background to be a continuously changing random bunch of colors, pixel by pixel. So, it would be just a giant mess of crazy colors.
    Is there a way to do this? I searched online, but didn't find anything.
    This isn't really important to me, just something I thought would be fun to do.
    ~Dac

    import java.awt.event.*;
    import java.awt.image.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.Timer;
    public class TVExample implements Runnable, ActionListener {
        private Timer t = new Timer(10, this);
        private JLabel label;
        private BufferedImage image;
        private Random r = new Random();
        public void run() {
            image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
            label = new JLabel(new ImageIcon(image));
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(label);
            f.pack();
            f.setResizable(false);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            t.start();
        public void actionPerformed(ActionEvent evt) {
            int x = r.nextInt(image.getWidth());
            int y = r.nextInt(image.getHeight());
            int rgb = r.nextInt(0x1000000);
            image.setRGB(x, y, rgb);
            label.repaint();
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new TVExample());
    }

  • Pixel by Pixel Scan

    Hi all.
    I'm messing around trying to make a simple 2D game. Currently, I have a few sprites on the screen and collision detection working between them. My sprites have transparent backgrounds and the collisions occur when the sprites bounding boxes contact each other but unfortunately this means that things like missiles explode when they hit the bounding box of a ship rather than the ship itself.
    I want to perform a pixel by pixel scan of two sprites once a collision between them has been detected and allow their transparency to overlap until they hit 'solid' color. Basically I want my missile to explode when it hits my ship, not when their two transparent boxes hit each other.
    Anyone have any ideas how I would do this? I've used C++ APIs which have these functions built in but I have no clue as to how to do it in Java. Please help!
    Thanks.

    Heres some code from what I use.
      BufferedImage bi   = new BufferedImage(800, 500, BufferedImage.TYPE_INT_ARGB);
      public static byte[] getAreaCollisions(BufferedImage bi, int minX, int maxX, int minY, int maxY) {
        byte[] collisions = new byte[(maxY - minY + 1) * (maxX - minX)];
        int numCollisions = 0;
        for (int i = maxX; i > minX; i--) {
          for (int j = maxY; j > minY; j--) {
            if (Util.getAlpha(bi.getRGB(i, j)) > 0) {
              collisions[numCollisions++] = 1;
            } else {
              collisions[numCollisions++] = 0;
        if (collisions.length == 0) {
          System.out.println(minX + " " + maxX + " " + minY + " " + maxY);
        return collisions;
      public static int getAlpha(int pixel) {
        return (pixel >> 24) & 0xff;
      }May not be the best code, but it works :)
    CoW

  • Pixel by pixel

    Hi to every one..
    m new at j2me and at this forum too... and have started working on face
    recognition in j2me..
    but for now i want to do a pixel by pixel matching of two images..
    can i do it with immutable images? or necessary to do it with mutable ones?
    and one more question plz..
    if i've displayed the image like this
         image = Image.createImage("/randy_orton.png");
              imageItem = new ImageItem(null, image,
                        ImageItem.LAYOUT_NEWLINE_BEFORE
                        | ImageItem.LAYOUT_LEFT
                        | ImageItem.LAYOUT_NEWLINE_AFTER,null);
              form.append(imageItem);
    how can i now get the pixels of it or bytes of this image..
    plz gime ur suggestions ..
    thanks
    a small piece of code with a bit of discription would be of greater help..
    thanks in advance,,

    i went thorugh that API ahve searched some more things as well.. I have listened about the getRGB() and getPixels methods for it.. If you found a getPixels method, you're looking at the wrong API. I told you to
    Read the API for javax.microedition.lcdui.Image
    Not any of the classes in java.awt.image.
    but dont know how to use those...Do you know what an array is? How to access and assign values of array elements? If not, then go back to basics and go through some tutorials. Start here:
    {color:#0000ff}http://java.sun.com/docs/books/tutorial/{color}
    db

  • Is pixel by pixel painting possible in standard MIDP?

    With pixel by pixel painting I mean painting each pixel on the screen instead of using methods like draweline and drawarc. I know that this is possible when using platform specific Java libraries, like Nokias. But is it also possible to do this in standard MIDP, so it works on all Java-enabled mobiles?

    I assume you mean that there is no such method.No, I mean you should look in the api docs to see if there is such a method (but no, there is none)
    I want to make a fullscreen animation. If I did that
    by calling drawline for each pixel, wouldn't that be
    e terribly slow?Well, just try it. Also, you probably don't need to update all of the screen with every frame

  • How to adjust the green (starting) and the red (end) rectangles pixel by pixel (top, bottom, left and right) by changing the number of pixels in ken burns.

    How to adjust the green (starting) and the red (end) rectangles pixel by pixel (top, bottom, left and right) by changing the number of pixels in ken burns. Help please.

    If you look closely at the top of the canvas pane, as you move either of the boxes (green or red) there is an indication of pixel positions... "top, bottom, left, right," and "scale."
    Admittedly, it doesn't seem as if you can "enter" the dimensions with your keyboard, however, as you move the boxes, you have a real time indication of the boxs' locations.
    (I couldn't take a screen shot, as you have to actively move the box with a mouse or other input device... thus, I could not also take a screen shot with same device.)
    I hope this helps.

  • Input to output (pixel by pixel) problems

    I'm at the start of creating a simple plugin. My aim is to put everything from input to output but pixel by pixel. I'm using a CCU example for that, but this causes problems.
    Here's my code:
        PF_EffectWorld *inputP = &params[0]->u.ld;
        PF_Pixel8 *inputPix = (PF_Pixel8 *)inputP->data;
        PF_Pixel8 *outPix = (PF_Pixel8 *)output->data;
        for (int i=0; i<output->height; i++)
            for (int j=0; j<output->width; j++)   
                *outPix++ = *inputPix++;
    My original footage looks like this:
    And after using my code it looks like this:
    After adding the bold line everything works (why do I have to use that line?):
    for (int i=0; i<output->height; i++)
            for (int j=0; j<output->width; j++)   
                *outPix++ = *inputPix++;
            for(int k=0;k<4;k++) inputPix++;
    But when I'm trying to use the plugin again on the same footage it looks like this:
    Am I missing something? What causes that? When I use the callback funcion everything works fine, but I have to do that using the above way 'cause I have to have access to every pixel of the footage.
    Thanks in advance, David

    It is called gutter or row padding, each row may contain more pixel than the actual width. You can check for this with the rowBytes value of inputP.
    The CCU example already compensates for this, so look there for more information:
    in_gutterL        =     (inputP->rowbytes / sizeof(PF_Pixel8)) - inputP->width,
    out_gutterL        =    (outputP->rowbytes / sizeof(PF_Pixel8)) - outputP->width;
    // At the end of each row, account for the gutter
    // (this number can vary by platform and for other reasons)
    if (yL >= 0 && yL < inputP->height){
        bop_inP    += in_gutterL;
    bop_outP += out_gutterL;

  • Help setting the movement to pixel by pixel

    Good day fellow designers. I'm having a "not so good" situation. I hope you can help me guys. It's all about moving an selected object pixel by pixel.
    I have this object selected on photoshop. And I want to move it pixel by pixel. So what I did is I selected it then press the arrow keys. In photoshop,
    usually, this will make the object move pixel by pixel. But in my illustrator however, it's kinda different. It moves at least 3 pixel by 3 pixel. It's not
    accurate. I already tried playing with illustrator's preferences but still no good. I know it's just around there somewhere.
    Maybe someone can help me with this? Thanks and have a good day ahead! Cheers!

    Hmm, I already got that tweaked... But it still skips a few pixels when I move it. A solution that I currently have right now is move it via mouse. It gets
    the job done but the movement via arrow keys helps a lot specially when my workspace is starting to get laggy.
    EDIT :
    I already got it figure out. And yup, it's the keyboard increment. I got used to 1px that I've forgotten that I can also input much lower than 1px. I tried
    0.25px and it worked! : )
    Thanks mate. Cheers! : )

  • Dispay an image pixel by pixel

    Hy! i want to read an image, bmp or jpg and then display it on the screen pixel by pixel....can you help?
    thanks!
    Message was edited by:
    zzirna

    http://forum.java.sun.com/thread.jsp?forum=31&thread=313033
    could prove to be of some interest

  • Cursor ove, pixel by pixel

    I'm a novice at this, so bear with me. In older Macintosh systems there was a program called "Easy Access." At that time, this program allowed for a keyboard function that allowed you to move the cursor pixel by pixel (a benefit for unsteady arthritic hands). The command was: Shift-Command-Clear (from the numeric keypad). Then the zedro key activated this function, and the period key cancelled it. The up and down arrows on the numeric keypad then moved the cursor up or down, and the left and right arrows moved the cursor left or right. does this function still exist, and if so, how do I use it? I may have gotten the older commands mixed up, but would appreciate any help with this.

    I have checked the Universal Access options, but I don't see anyting that specifically relates to what I want to do. I would like to use the up, down, left, and right arrows on the keyboard to move my cursor one pixel at a time in any of those directions. Perhaps I have missed something, but I don't see that capability. any suggestions?

  • Pixelated text and graphics in MacBook Pro Retina

    Why are text and graphics in pixelated in Numbers and iBooks applications, to name two, on the MacBook Pro Retina? All updates have been downloaded.

    Clinton- The problem is that the way things are setup is a bit confusing. Apple doesn't let us use the actual full resolution of 2880 x 1800, in relateive size. There is a hack to see the screen at full native resolution, and it's unbelievably small. So what they do is use the pixels, but use 4 vs 1, and thus they make the UI look like it would look as standard 1440 x 900 display. I have an old 15" and looking at both, the UI is the same relative size on the screen. However the retina is using more pixels to make the same physical size.
    Now, Apple also lets apps use 1:1 within their "working area." For instance, if you view a graphic on a web page, it shows it doubled, and pixelated. But if you drag that image to the desktop then open in Preview, preview will show it half size of Safari, but in actual resolution. it's sharp, but half the size of Safari, as Safari is doubling it. So apps can take advantage of that but will have to be updated. Pixelmator isn't updated, and graphics/text/vectors are blurry in their work area, but once you save/export, and view in preview, they are perfect.
    So there is going to be a lot of strange stuff going on until everyone gets on the same page.
    I did find you can view Pages/Numbers with better resolution (just not icons) by right-clicking "get info" and unchecking open in low resolution. But Pages acts weird. I will post a screenshot in a minute about what I mentioend about apps using the native resolution within work spaces.
    Bryan

  • Stuck Pixel, but from graphics card, NOT LCD

    Two days ago, I noticed two stuck white pixels on my 30" Apple Cinema Display. This display is plugged into the Mini-DisplayPort -> Dual Link DVI adapter and then into my unibody 17" Macbook Pro.
    This all sounds fine and dandy, a somewhat common occurrence. But it's not.
    If the pixels were really dead pixels on the screen, they wouldn't move. When I use the screen zoom feature (control-scrollwheel), they move. When I put the mouse in a certain position while zooming, I can actually push the "dead pixels" from the 30" display back onto the 17" laptop's display. The pixel also gets pixelated when it is zoomed.
    I can cover up the dead pixels with the mouse (and not have a strange stationary dot on the mouse), and they appear in screen shots (taken with command-shift-3)
    I rebooted the computer once, and they went away. Soon after, one of the two came back.
    Sleeping the display and/or the computer does not make them go away.
    They remain there when I switch spaces (their physical location on the screen stays the same - they do not slide and reappear in another space), and are there on top of any application. This includes all applications that may use Core Graphics (Quartz 2D), Core Animation, OpenGL, etc to display their interface.
    Does anybody have the foggiest idea what is going on?

    Ok, so I have more information:
    • The Firmware's Diagnostic Utility found nothing wrong (which, after the next few bullets, will make sense)
    • When at the login screen, the dot doesn't appear.
    • When logging in, the dot appears at the same time as the SystemUIServer for my user launches. Upon logout (or switch-users), the dot disappears at the same time the SystemUIServer goes away (hidden or quit)
    I have a more thorough and easier to follow demonstration (using video) here: http://www.kd7qis.com/MBPPixel

  • Pixelation in iMovie graphic

    I have been fighting iMovie for days now, and have read the Apple docs and help to no avail. I have a map image that I am adding an arrowed line to in Photoshop. The image is prestine in Photoshop, yet no matter what I try (what format, what file type, what have you), every time I import it into iMovie HD, the line is pixelated beyond belief. I just don't get it. What's really weird is that there is fine detail in the map which is not pixelated. This is driving me crazy. Any advice?

    Hey Don,
    I think I have the solution to your problem (but it will lack explanation as to the reason it works).
    I have experienced the same problems in the past with graphics. Assuming you are following all posted advice regarding size and other things, it may be a color issue. What makes me think that is the fact that the rest of your graphic does not appear to experience the bad pixelation. Ask yourself these questions:
    1. Is the color of the line unique to the image? (aka, is that color in any other part of the image?)
    2. Does the color happen to be red?
    I don't know the reasons why, but in my experience, when I use red in an image, it gets horribly pixelated. Try changing the color to something else. I would recommend another color in your map, but then the line may not show up as well. Assuming your map is filled with blues, greens, and browns, how about trying yellow? I'd be curious to find out if this solves your problem.
    If someone could shed some light on this color issue, I'd love to read about it.

  • Pixel by pixel image manipulation- java

    Hey guys, i need to write a bit of code that looks at 3 images, assesses which pixels in ALL 3 are grey, and then redraws a new image consisting of the old ones, but grey only showing where all 3 have grey.
    The inputs are mays with grey overlays, so therefore the output pixels should be the same UNLESS the pixel was grey in all 3.
    I know its to do with arrays but im not a very good programmer and i need to get this done. Ive written the rest of my program, is anyone able to write this simple code? My problem is that i dont really know how to create an image using an array, plus also i know the pixel colours are stored awkwardly too. Ive only been programming in java for 4 weeks!

    The BufferedImage class is really good at creating images from an array. I don't know what a may is, but if you had an array of integer values in the format {a, r, g, b, a ,r, g, b}, it would be as easy as this:
              BufferedImage b = new BufferedImage(5, 5, BufferedImage.TYPE_4BYTE_ABGR);
              b.getRaster().setPixels(0, 0, 2, 1, new int[] {128, 64, 32, 16, 128, 75, 50, 25});Hope this helps.

  • Scaling two objects to match exactly pixel to pixel.

    I have two art objects on two layers. I want to match to the pixel the two objects that otherwise could be exactly the same but one layered object was imported slightly smaller. The scale tool has good scale handling, I just want to measure the tool spots to the pixel to gain an exact scale size factor and match sizes.

    If they could be the same  size what caused the scale difference. Were the images taken with or different cameras, or different focal length or angle are you sure only the scale is off.  That the perspectives and sizes of the objects are the same. Photoshop has a measure tool just remember perspective, angle, axis all effect the measurements size.

Maybe you are looking for

  • Stuck with making my event structure examine if two arrays are equal

    Hi there, I'm new to labview. I'm trying to write an event structure; examining if one array equals another array. The program will carry on if they are equal, otherwise it will continue checking... Any help is appreciated. My program is attached.. I

  • Persist column values clicking on next or previous link of pagination

    Hello All, I have created one tabular form type report using apex APIs like apex_item.checkbox,apex_item.textfield etc where i want to update the values of each rows , i have also implemented pagination also. Actual problem is that i have 17 rows and

  • Amber update in Norway

    Greetings to all of our Norwegian friends, We've heard from some customers with the Telenor variant of the Lumia 920 that they were unable to update to Amber. We have temporarily removed the update in order to investigate these concerns and will prov

  • How do I get 16x9 aspect ration on an external monitor?

    I'm connected to a huge monitor but can only choose resolutions that are 4x3 - and the monitor is 16x9. Is my VGA connection restricting it? Will the option become available if I use HDMI? I just haven't bought the connections yet, but would definite

  • Preview - Rotate a picture and resave it WITHOUT changing the date?

    Hi all, Is there a way in Preview to save a picture, but have it NOT change the date of the picture? I usually run into this problem when I download pictures from my cellphone. Lets say I take some snapshots with my phone, some vertical some horizont