Ziggy Kowalski

Greenhorn
+ Follow
since Feb 06, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Ziggy Kowalski

Hi,

is there a way to stop someone from downloading the jar file that my appelt src code is stored in, unjarring the files and getting access to my src code?

thank you
11 years ago

Originally posted by Jeff Albertson:
One of the standard approaches to encoding/decoding binary information as text is to use the "Base 64" codec. There are plenty of implementations of that around, for example: http://jakarta.apache.org/commons/codec/apidocs/org/apache/commons/codec/binary/Base64.html



I'm using the Base 64 implementation shown above but i've encountered something weird. I thought base64 encoding returns only digits whereas i'm getting all sorts of stuff. For example: /9j/4AAQSkZJRg (that's the beginning of an encoded jpeg image). The encoding and decoding works fine, but i'm asking because another part of the system is going to have to use the encoded data and decode it itself. I don't want any problems to pop-up when that happens else my necks on the chopping block

thank you
12 years ago
JPEGCodec is from the com.sun.image.codec.jpeg.* package

Yes, all the steps taken in my applet require a few lines of code each.

I have one question however:
My program now works fine but the load(...) method keeps throwing an exception for me.
When i comment-out the if statement, everything works like a breeze. The code appears to have been correctly written so i can't for the life of me think why the exception is being thrown. The image is obvioulsy loaded else it wouldn't appear on my applet. If that's the case why is statusID returning 0 (assuming MediaTracker.COMPLETE = 1)?
12 years ago
Actually, i've hit a snag with the new code Jeff posted above. The problem is that getScaledInstance(...) returns an image whereas i require a BufferedImage object because i later cast the image to this class and convert it to a jpeg using the code below:

BufferedImage bimg = null;
int w = image.getWidth(null);
int h = image.getHeight(null);
System.out.println("w: "+w+" h: "+h);
int[] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(image, 0, 0, w, h, pixels, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException ie) {
ie.printStackTrace();
}

bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
bimg.setRGB(0, 0, w, h, pixels, 0, w);

// Encode as a JPEG
ByteArrayOutputStream bout = new ByteArrayOutputStream();
try {
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bout);

encoder.encode((BufferedImage)image);
//bout.close();
}catch(Exception e){
System.err.println("An error occured while trying to convert img to jpg:"+e);
}
byte[] ba = bout.toByteArray();

I was actually surprised to see this code work in the first place because image was meant to be initially an Image object but the BufferedImage cast was allowed to occur and the code seemed to work. Now that i have this line in my code:
image = image.getScaledInstance(w, h, Image.SCALE_AREA_AVERAGING);
i get a classCastException.

so i guess my question is whether there's another way to convert an image object into a jpeg without having to use a BufferedImage.

For background info, my code is meant to do this:
grab a screenshot (using Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); etc)
scale it to fit into a panel and disply it
convert the image into a jpeg and then into base64 format

this is turning out to be much more difficult than i first expected...
12 years ago

Originally posted by marc weber:
"zzdziarski zzdziarski,"

Welcome to JavaRanch!

Please revise your display name to meet the JavaRanch Naming Policy. To maintain the friendly atmosphere here at the ranch, we like folks to use real (or at least real-looking) names.

You can edit your name here.

Thank you for your prompt attention, and enjoy the ranch!

-Marc




No problem, however, if i recall correctly, the only policy shown to me when signing up for this forum was "Be nice". There was nothing about the types of names that we could select
12 years ago
works like a dream, thanks
12 years ago

Originally posted by Jeff Albertson:
Take a look at Integer.parseInt

Why are you converting an image to a String?



I'm converting an image to a string because i'm passing the image to javascript which in turn passes the image to a hidden field for php to parse and manipulate as it pleases. I can't use a simple POST method in the applet because the number of applets on the page is specified by the user dynamically, and there are many other fields which constitute the page's form.

And Integer.parseInt looks promising. thanks
12 years ago
sorry, i can't get past step 1 :/

I've looked at the Integer class but i still can't work out how to (for eg) convert "A0" to a byte.
12 years ago
i'm simply drawing the image by calling the 'drawImage' method in the graphics class. By passing in the width and height of the panel, the image is automatically resized (by about half of the original size).
So, basically i'm squashing the image into a panel half its size.
[ February 06, 2006: Message edited by: zzdziarski zzdziarski ]
12 years ago
Hi,

I'm having problems converting my image back to jpeg format. The code i used to get from jpeg to hex is as follows:

where:
ba is a byte[] which contains the image in jpeg format
ret is a string buffer, which stores the image in hex format.

i can't work out how to convert back to jpeg format

thank you in advance
12 years ago
Hi,

I've written this applet into which the user can paste a screenshot and do various things with the pasted image. The problem i've encountered is that when the image is made to fit into the panel, its very illegible. Is there a way to make the image more smoother? I don't mind changing the resolution of the picture or whatever as long as the image is good enough to view.

thank you in advance
12 years ago