Closed Thread Icon

Topic awaiting preservation: Send an image to java using javascript? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=24433" title="Pages that link to Topic awaiting preservation: Send an image to java using javascript? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Send an image to java using javascript? <span class="small">(Page 1 of 1)</span>\

 
TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 12-17-2004 16:54

I'm playing around with some things and I'm trying to grab the url from an img-tag and send the image to java along with some pixel coordinates and color values (RGB or whatever).
As a return value, I'd like to get a boolean value stating wether the pixels with the coordinates I sent have the colors I sent along.

I don't know any java but I heard that you can easily grab the color value of any pixel on a gif or jpg using it.

This is a function that I've missed much in JavaScript...

/TwoD

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-17-2004 19:16

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 12-17-2004 19:39

Thanks InI,
That's what I thought, just wanted to confirm it.

/TwoD

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 12-26-2004 14:57

First, I know this isn't a Java forum, but I'll ask here anyway since I've already created this thread.

I got the pixelgrabber working and I can call it from JavaScript, but I get a SocketPermission error if I try to grab an image that is not on my own comp/server depending on where I run the applet.
I read somewhere that you could give Java permission to "leave the site", but how??

/TwoD

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-26-2004 18:37

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-26-2004 18:55

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 12-27-2004 04:00

Thanks for the links InI, they cleared up a few things.
Looks like I can't make an applet grab data from another server other than using certificates...
But what if I converted it into a java application instead, would I still be able to communicate with JavaScript easily?

/TwoD

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-27-2004 08:26

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-27-2004 10:21

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-27-2004 13:26

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 12-29-2004 21:09

To answer you questions:

1, I'd like to be able to run both the JS code and applet locally, but running them from a server would probably be ok too.
2, The image(s) I'd like to grab data from could be anywhere online.
3, Haven't thought about that really, I'm just trying to find a way to do it easily.

The code you posted does almost exactly the same thing as my code and I get the same error when grabbing a "distant" image.

There's always the brute-force approach left if all else fails: Use Active X in the JavaScript to create/write to a txt file. Then have the Java application read that file with an interval and follow the commands JavaScript put in there. Then it removes the commands and prints out it's answer instead. The JavaScript is also reading the file with an interval but it stores the old contents in a string. If that string doesn't equal the
file contents (or the file starts with a special header), the Java application must have done what it was told and the contents is the return value.

The Java application shouldn't complain about having to read a file on say C: on the user comp and image files from www.whatever.com while run either locally or on a server.
But the JavaScript will popup a small box when Active X is started saying something about insecure code.. I can live with that though...
This is probably how I will solve it unless it's possible with an applet... Might not be very fast but speed isn't important in this test.

Sorry for the late reply, I was at a LAN party and there were a few problems with the internet connection. Couldn't read my mail or post in some forums like this one...

/TwoD

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 12-30-2004 08:44

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 01-03-2005 05:10

I decided that this has to be accomplished at any cost so I'll do this the "ugly way".
Basically, it's what I said above about the text file and a java application.
Of course I ran into a brick wall of problems since java isn't exactly my native language....

Here's what I've done so far:

code:
//Grabber.java

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.image.*;
import java.applet.Applet;

public class Grabber extends Applet implements ImageObserver {

public void main(String[] args) {
Grabber f = new Grabber();
String oldData = f.readMyFile();
System.out.print(oldData);
int[] imgData = GrabPixels(oldData);
System.out.print("-----");
System.out.print(imgData);
writeMyFile(imgData);
System.out.print("Done");
}

String readMyFile() {
String imageURL = null;
DataInputStream dis = null;
String record = null;
int recCount = 0;
try {

File f = new File("C:/mydata.txt");
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);

if ((record = dis.readLine()) != null) {
imageURL = record;
}

} catch (IOException e) {
// catch io errors from FileInputStream or readLine()
System.out.println("Uh oh, got an IOException error!"
+ e.getMessage());

} finally {
// if the file opened okay, make sure we close it
if (dis != null) {
try {
dis.close();
return imageURL;
} catch (IOException ioe) {
}
}
}
return imageURL;
}

public int[] GrabPixels(String imageName) {
boolean image_is_ready = false;
Image final_image;
int imageWidth, imageHeight;
Image initialImage;
//get image
try {
MediaTracker mt = new MediaTracker(this);

URL imageURL = new URL(getCodeBase(), imageName);
initialImage = getImage(imageURL);

//add the image to the media tracker's list
mt.addImage(initialImage, 1);
//wait for all images in list to load before proceeding
mt.waitForAll();

//serialize to bytes

imageWidth = initialImage.getWidth(this);
imageHeight = initialImage.getHeight(this);

int[] img_data = new int[imageWidth * imageHeight];

//the PixelGrabber class is used to convert
//Images to bytes

PixelGrabber pg = new PixelGrabber(initialImage, 0, 0, imageWidth,
imageHeight, img_data, 0, imageWidth);

//copy pixels into array
pg.grabPixels();

return img_data;

} catch (MalformedURLException mue) {
System.out
.println("Malformed URL exception when trying to load image "
+ imageName);
image_is_ready = false;
} catch (InterruptedException ie) {
System.out.println("Interrupted exception");
image_is_ready = false;
}
return new int[0];
}

void writeMyFile(int[] Data) {

DataOutputStream dos = null;
String record = null;
int recCount = 0;

try {

File f = new File("C:/mydata.txt");
FileOutputStream fos = new FileOutputStream(f);
BufferedOutputStream bos = new BufferedOutputStream(fos);
dos = new DataOutputStream(bos);
OutputStreamWriter osw = new OutputStreamWriter(dos);
osw.write(Data.toString(), 0, Data.toString().length());

} catch (IOException e) {
System.out.println("Uh oh, got an IOException error!"
+ e.getMessage());

} finally {
// if the file opened okay, make sure we close it
if (dos != null) {
try {
dos.close();
} catch (IOException ioe) {
}
}
}
}
}



I've borrowed code from all over the web to get this thing "working" so that's why it looks the way it does.
It compiles fine but I can't run it as an application since it complains about a missing main method

The file it reads is supposed to contain just the image's URL (which is put there by JavaScript).
As you see now it just reads the file no matter what, I will later change it so it'll read the file over and over again (with a delay if that's possible) so that it can be "called" multiple times by writing a new URL to the file from JavaScript.

btw, sorry for keeping this part of the forum busy with java questions. I've tried other places but without luck. If a moderator wishes to move it to a more suitable place, please do.

/TwoD

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-03-2005 08:39

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

TwoD
Nervous Wreck (II) Inmate

From: Sweden
Insane since: Aug 2004

posted posted 01-04-2005 19:19

Yes I've understood that and I have a void main method in the code above, but the application says otherwise

I don't really need a javascript interface, all I need is for the application to give me the image data, no matter how.
If having to launch the application "manually" and having a textfile as a middle hand that's fine as long as it works. I'm not planning to use this in any commercial way lol

/TwoD

InI
Maniac (V) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 01-04-2005 23:51

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

« BackwardsOnwards »

Show Forum Drop Down Menu