1. Senior Member
Join Date
Jan 2009
Location
CA, USA
Posts
271
Rep Power
8

## 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-01-2009 at 11:26 PM.

2. Senior Member
Join Date
Jan 2009
Location
CA, USA
Posts
271
Rep Power
8
Does that mean no one knows? :(

3. Senior Member
Join Date
Jul 2008
Posts
125
Rep Power
0

## 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 07:41 PM. Reason: capitalization of one word

4. Senior Member
Join Date
Jan 2009
Location
CA, USA
Posts
271
Rep Power
8
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 10:49 PM.

5. Senior Member
Join Date
Jan 2009
Location
CA, USA
Posts
271
Rep Power
8
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 12:08 PM.

#### Posting Permissions

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