Results 1 to 5 of 5

Thread: Pixel Array?

  1. #1
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default Pixel Array?

    So, I've been messing with applets and I wanted to try an effect that would blur the image. I'm not going to implement anything like a gaussian blur, so I made up my own very simply method. The problem is, I have no idea how to change the applet to an image, then change that to an array of colors. Say I have an applet 100x100, I need to get what is displayed on it to a Color[100][100] array to manipulate each pixel, then paste that back on the applet. How would I go about doing this? I looked at the Graphics class and Image class on sun's website. It wasn't much help to me... :/

    Some potentially relevant information I have gathered:

    Image imageName = createImage(WIDTH, HEIGHT);
    g.drawImage(imageName, x, y, this); //I guess this would draw the image? lol.



    On another note, this is kind of what I was thinking for the blur (this example being for non-edge pixels).

    Java Code:
    ...
    
    int newR = ( R[x-1][y-1] + R[x+1][y-1] + R[x-1][y+1] + R[x+1][y+1] + 2 * R[x][y-1] + 2 * R[x+1][y] + 2 * R[x][y+1] + 2 * R[x-1][y] + 4 * R[x][y] ) / 16;
    
    int newG = ( G[x-1][y-1] + G[x+1][y-1] + G[x-1][y+1] + G[x+1][y+1] + 2 * G[x][y-1] + 2 * G[x+1][y] + 2 * G[x][y+1] + 2 * G[x-1][y] + 4 * G[x][y] ) / 16;
    
    int newB = ( B[x-1][y-1] + B[x+1][y-1] + B[x-1][y+1] + B[x+1][y+1] + 2 * B[x][y-1] + 2 * B[x+1][y] + 2 * B[x][y+1] + 2 * B[x-1][y] + 4 * B[x][y] ) / 16;
    
    Color newColor = new Color(newR, newG, newB);
    
    ...
    Last edited by AndrewM16921; 04-02-2009 at 12:26 AM.

  2. #2
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default

    Does that mean no one knows? :(

  3. #3
    paul pasciak is offline Senior Member
    Join Date
    Jul 2008
    Posts
    125
    Rep Power
    0

    Default Try this search

    Sorry I haven't time now to
    contribute a more accurate
    suggestion.

    Do a search using:

    "java Richard G. Baldwin pixel"

    His writing style is kind of stale,
    but he provides lots of great code,
    especially on pixel manipulation
    and image processing.
    Last edited by paul pasciak; 04-02-2009 at 08:41 PM. Reason: capitalization of one word

  4. #4
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default

    Ok thanks, I'll look into it.

    Edit:

    Hmm... only thing I found is from 1997. I hope it is still worth reading, but I fear it might be outdated. I'll give it a try... :/
    Last edited by AndrewM16921; 04-02-2009 at 11:49 PM.

  5. #5
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default

    Ok, I did learn quite a bit from that. Unfortunately, I didn't quite understand how to use the things he talked about. Here's what I found, though.
    Java Code:
    int[] pix = new int[WIDTH * HEIGHT];
    /*Why is it a one-dimensional array?
     *I guess I could use x=index%WIDTH and y=index/WIDTH for coordinates
     * or something
     *EDIT: And why is pix of integers, shouldn't it be Colors?
     */
    
    Image oldImg = new Image(...) //Some how get Image from the applet
    
    PixelGrabber PxGrb = new PixelGrabber(oldImg, 0, 0, WIDTH, HEIGHT, pix, 0, WIDTH);
    /*
     *********************************************************
     *PixelGrabber(Image img, int x, int y, int w, int h, int[] pix,
     * int off, int scansize) 
     *********************************************************
     *img, x, y, w, and h are obvious... but
     *Will it fill in pix for me? Or am I suppose
     *to have the pixel data already? And if
     *so then what's the point...
     *********************************************************
     *off is offset?
     *********************************************************
     *scansize is? I have no idea...
     *The example used the width, so
     *I'll use that for now.
     *********************************************************
     */
    
    //Manipulate pixels (this part is too long to post for this example).
    
    modImage = createImage(new MemoryImageSource(WIDTH, HEIGHT, pix, 0, WIDTH)); 
    
    g.drawImage(modImage, 0, 0, this); 
    
    /*Honestly, I pieced this together like a jigsaw puzzle that's been sitting
     *in the attic for at least a decade and most of the pieces are missing...
     *and those that aren't are badly damaged! ^_^
     */
    So yeah, if anyone can help me make some more sense of this... :cool:


    Oh, and cause I like to make additional notes for no reason... I think this will work for getting the colors of the necessary pixels...

    I need to get the color of the current pixel and the 8 around it,

    TL | TC | TR
    ML | MC | MR
    BL | BC | BR

    Java Code:
    Color[] newPix = new Color()[WIDTH * HEIGHT];
    
    Color TL, TC, TR, ML, MC, MR, BL, BC, BR;
    
    TL = pix[MC-(WIDTH+1)];
    TC = pix[MC-WIDTH];
    TR = pix[MC-(WIDTH-1)];
    ML = pix[MC-1];
    MC = pix[MC];
    MR = pix[MC+1];
    BL = pix[MC+(WIDTH-1)];
    BC = pix[MC+WIDTH];
    BR = pix[MC+(WIDTH+1)];
    
    //Manipulate MC
    
    newPix[i] = MC;
    
    //Then I'll realize that pix[] is an int[] and it doesn't work. : )
    
    //Which now brings me to another question that I'll add to the above code block...
    Last edited by AndrewM16921; 04-03-2009 at 01:08 PM.

Similar Threads

  1. Scanning Image Pixel by Pixel
    By the_transltr in forum Advanced Java
    Replies: 5
    Last Post: 08-28-2012, 05:01 PM
  2. increase pixel size
    By rosh72851 in forum New To Java
    Replies: 9
    Last Post: 07-31-2012, 08:30 PM
  3. how to get rgb value each pixel of an image file
    By tOpach in forum New To Java
    Replies: 1
    Last Post: 03-28-2009, 05:38 PM
  4. Replies: 3
    Last Post: 08-24-2008, 02:51 PM
  5. Replies: 1
    Last Post: 07-17-2007, 05:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •