For Programmers: Free Programming Magazines  


Home > Archive > Java Help > March 2004 > getting pixels from an applet area









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author getting pixels from an applet area
Québec

2004-03-27, 12:30 am

Hi,

How can I get the pixels from an applet area that
has been drawed, written over etc?
How do I put the pixels in a buffer [w, h]?

Lets say the portion of the applet screen is 0, 0,
200, 100.


Jean

===============
public void grab(Graphics g, int w, int h) {
int buffer[] = new int [w * h];
PixelGrabber grabber =
new PixelGrabber(g, 0, 0, w, h, buffer, 0, w);
try {
grabber.grabPixels();
for (int y = 0; y < h; y++) {
int col = 0;
row--;
for (int x = 0; x < w; x++) {
buffer[ (x*h ];
}
}
} catch (Exception e) {e.printStackTrace();}

}


Québec

2004-03-27, 12:30 am

Is the copyArea method in awt.Graphics a jni or exe class?
I cant find it in the jdk1.1.8 src folder.


Andrew Thompson

2004-03-27, 12:30 am

On Mon, 22 Mar 2004 18:19:49 -0500, Québec wrote:

> Is the copyArea method in awt.Graphics a jni or exe class?


I do not quite understand what you are asking.

Graphics.copyArea() is part of the Graphics class,
it is neither a JNI nor 'exe' class..

My (1.4) docs have no indication of when it
was introduced, though the Graphics class is
listed as being introduced in 1.0.

And.. yes, as I suspected, the following code
compiles against a 1.1 rt.jar..
<sscce>
import java.awt.*;

public class GraphicsTest {
public static void main(String args[]) {
Panel p = new Panel();
Graphics g = p.getGraphics();
g.copyArea(1,1,2,3,4,4);
}
}
</sscce>

(shrugs) Does that clear anything up?

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology
Québec

2004-03-27, 12:30 am

Lets say a Martien dropped some pixels on a canvas. No image was loaded or
came from a graphic context.

How do I get them? I red almost everything on RGB filters,
memoryImageSource, PixelsGrabber, etc. It seems there is no way to get a
screenshot of an application or applet window.


I was thinking I could find a way by scritinizing:
package java.awt.Graphics;
public abstract void copyArea(int x, int y, int width, int height,
int dx, int dy);

but I know some
classes uses native coding.


Jean




Andrew Thompson

2004-03-27, 12:30 am

On Mon, 22 Mar 2004 22:20:25 -0500, Québec wrote:

> Lets say a Martien


??

>..dropped some pixels


?????

>..on a canvas. No image was loaded or
> came from a graphic context.
>
> How do I get them?


Once you explain those two bits above
where I put question marks, I might at
least understand the question.

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology
Québec

2004-03-27, 12:30 am

You dont understand ...

Ok.

How do you get pixels from a canvas that are not an image? How do you get
pixels from a canvas if you cant use getImage().

Lets say it is an applet an the users can draw on it whit the mouse.
Then they click on abutton and the image is copied to the clipboard ( if
this is possible) or grabbed with Pixels Grabber and stored in a buffer.
Lets say there is a class wich does this.
First it create an
emptyImage.createImage(100, 100)
then it
Canvas.copyArea(0,0,100,100) in the emptyImage.

Or else.

There is the createScreenCapture in 1.2 but it would probably not be allowed
by the security manager for an applet as told to me by a guru.


Jean



Andrew Thompson

2004-03-27, 12:30 am

On Tue, 23 Mar 2004 07:21:10 -0500, Québec wrote:

> How do you get pixels from a canvas that are not an image? How do you get
> pixels from a canvas if you cant use getImage().


You have strayed out of my area of expertise
on that one, so I'll leave it for others.
I will just add some points about copying..

> Lets say it is an applet an the users can draw on it whit the mouse.
> Then they click on abutton and the image is copied to the clipboard ( if
> this is possible)


It is, but the applet needs to be signed
(* actually I am not positive about that,
most AWT textual components support copy
from the underlying OS functionality, but
to do it programmatically would AFAIU,
require a signed applet)

<snip>
> There is the createScreenCapture in 1.2


Eh? What Class is that in?

It sounds like the wrong method anyway.
You want to capture an image of a componenet
inside your applet, you do not need to 'capture
the screen' in general.

[ And I would get a bit antsy if you tried
to grab my pornographic desktop image. ;-) ]

> ..but it would probably not be allowed
> by the security manager for an applet as told to me by a guru.


You may need to sign it either way.

--
Andrew Thompson
* http://www.PhySci.org/ Open-source software suite
* http://www.PhySci.org/codes/ Web & IT Help
* http://www.1point1C.org/ Science & Technology
Québec

2004-03-28, 12:01 am

For the sake of the newbees.
I have tried to draw multiple images on an offScreenGraphics. And then
tried to rotate it with a relative success.
The rotate filter uses a PixelGrabber.


Québec

2004-03-29, 5:39 pm

Correction with total success.

Image myOffImage = createImage(72, 72);
Graphics secondG = myOffImage.getGraphics();
secondG.drawImage(img[0], 35, 0, null);
secondG.drawImage(img[1], 15, 0, null);
secondG.drawImage(img[2], 40, 20, null);
secondG.drawImage(img[3], 0, 20, null);
secondG.drawImage(img[4], 20, 40, null);
secondG.setColor(Color.green);
secondG.drawString("biz.z..z...z....z", 0, 65);

//if(imageUpdate(myOffImage, ALLBITS,0, 0, 72,72))
////////////////////////////////////////////////////////////////
tracker.addImage(myOffImage, 6);
while (!tracker.checkID(5, true)) {
pause(50);
}
///////////////////////////////////////////////////////////////
g.drawImage(flipV(myOffImage), 5, 5, null);
g.drawImage(myOffImage, 264, 190, null);
secondG.dispose();
"Québec" <notAgain@enough.ca> a écrit dans le message de
news:9Me9c.66792$Un3.1758797@wagner.videotron.net...
> For the sake of the newbees.
> I have tried to draw multiple images on an offScreenGraphics. And then
> tried to rotate it with a relative success.
> The rotate filter uses a PixelGrabber.
>
>



Québec

2004-03-29, 5:39 pm

I must say I how this to Mike Lundy


Andrew Thompson

2004-03-29, 5:39 pm

On Mon, 29 Mar 2004 16:59:22 -0500, Québec wrote:

> Correction with total success.


I still do not understand what you are
trying to do, even now rereading the posts.

But, ..glad you sorted it! :-)

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Québec

2004-03-29, 10:37 pm

I am puzzeling a new images from parts of of another image. They are all
painted to an offscreen. Then the offscreen image is flipped and g.drawImage
on the visible area of the applet applet.

To be sure the offscreen image is complete before painting it. I am using a
while loop to wait for the media tracker to finish the loading.


well, I guess you wont understand this either. ;_)


May the illumination be within us.

Jean


Québec

2004-03-31, 3:41 pm

This works in IEXplorer with Microsoft JVM and may not work with
appletviewer 1.1.8
"Québec" <notAgain@enough.ca> a écrit dans le message de
news:0%0ac.54711$KQ1.892400@weber.videotron.net...
> Correction with total success.
>
> Image myOffImage = createImage(72, 72);
> Graphics secondG = myOffImage.getGraphics();
> secondG.drawImage(img[0], 35, 0, null);
> secondG.drawImage(img[1], 15, 0, null);
> secondG.drawImage(img[2], 40, 20, null);
> secondG.drawImage(img[3], 0, 20, null);
> secondG.drawImage(img[4], 20, 40, null);
> secondG.setColor(Color.green);
> secondG.drawString("biz.z..z...z....z", 0, 65);
>
> //if(imageUpdate(myOffImage, ALLBITS,0, 0, 72,72))
> ////////////////////////////////////////////////////////////////
> tracker.addImage(myOffImage, 6);
> while (!tracker.checkID(5, true)) {
> pause(50);
> }
> ///////////////////////////////////////////////////////////////
> g.drawImage(flipV(myOffImage), 5, 5, null);
> g.drawImage(myOffImage, 264, 190, null);
> secondG.dispose();
> "Québec" <notAgain@enough.ca> a écrit dans le message de
> news:9Me9c.66792$Un3.1758797@wagner.videotron.net...
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com