|
Author |
Topic: Save sketch to JPEG/PNG (Read 9174 times) |
|
Martin
|
Re: Save sketch to JPEG/PNG
« Reply #15 on: Oct 22nd, 2003, 4:57pm » |
|
ok. this one's done.
|
|
|
|
mrb
|
Re: Save sketch to JPEG/PNG
« Reply #17 on: Oct 23rd, 2003, 2:50am » |
|
seriously, command performance by all
|
|
|
|
Koenie
|
Re: Save sketch to JPEG/PNG
« Reply #18 on: Oct 23rd, 2003, 12:24pm » |
|
Martin? Is something wrong? It's never done Let's try to implement some gif export stuff. Koenie
|
http://koeniedesign.com
|
|
|
mKoser
|
Re: Save sketch to JPEG/PNG
« Reply #19 on: Oct 23rd, 2003, 2:49pm » |
|
i just tried using code snippet on my MAC (os10.2.8 / p5.0066) and it wouldn't work. it said that imageio is either misplaced or nonexsistent ... it works fine on my PC. any clues? - - - - sample code - - - - Code: void setup(){ size(320, 240); background(0); } void draw(){ line(0, 0, 100, 100); save("img.jpg"); } // save IMAGE hacked by Martin and Koenie public void save(String filename) { BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); img.setRGB(0, 0, width, height, pixels, 0, height); if(filename.toLowerCase().endsWith(".jpg")) {try {File file = new File(filename); javax.imageio.ImageIO.write(img, "jpg", file);} catch(Exception e) {}} else if(filename.toLowerCase().endsWith(".png")) {try {File file = new File(filename); javax.imageio.ImageIO.write(img, "png", file);} catch(Exception e) {}} else {g.save(filename);} } |
|
|
mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
|
|
|
fry
|
Re: Save sketch to JPEG/PNG
« Reply #20 on: Oct 23rd, 2003, 4:11pm » |
|
on Oct 23rd, 2003, 2:49pm, mKoser wrote:i just tried using code snippet on my MAC (os10.2.8 / p5.0066) and it wouldn't work. it said that imageio is either misplaced or nonexsistent ... it works fine on my PC. any clues |
| perhaps imageio is 1.4 only the mac version of processing defaults to 1.3, details for changing to 1.4 are in the readme. also for the code, here's another method that might be more usable, though i'm doing this off the top of my head and haven't debugged it, so it may need a tweak or two: Code: // save IMAGE hacked by Martin and Koenie public void save(String filename) { BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); img.setRGB(0, 0, width, height, pixels, 0, height); String extn = filename.substring(filename.lastIndexOf('.') + 1).toLowerCase(); if (ext.equals("jpg") || extn.equals("png")) { // add here as needed try { javax.imageio.ImageIO.write(img, extn, new File(filename)); } catch (Exception e) { System.err.println("error while saving as " + extn); e.printStackTrace(); } } else { super.save(filename); } } |
|
|
|
|
|
Martin
|
Re: Save sketch to JPEG/PNG
« Reply #21 on: Oct 23rd, 2003, 5:02pm » |
|
koenie: nothing's wrong. hehe... ok, an updated version with gif capability will be posted soon (not using javax.imageio). hehe. mrb: erm... hi, what do you mean? mkoser: thanks. what version of java are you using on your mac? javax.imageio is part of jre1.4. it should work if you have it. then again, in my previous posting before koenie's, i inserted code to detect what version of java you're using. i've updated it to use setrgb as well as to do java version checking. (the link is right above. --- update: not posted right now, just hack the previous code and use setrgb. i'll post something loooong a little later that does barebones gif encoding). i don't have a mac right now to test this but i really appreciate feedback. note: ugh. fry beat me in posting abt 1.3 vs 1.4 hehe... at any rate, you can still use the other jpeg encoding method if you want to default to 1.3 ... uh yah, i was coding the gif encoder while typing this reply. hehe. got stuck with object references. BImage ... hehe....
|
|
|
|
Martin
|
Re: Save sketch to JPEG/PNG
« Reply #22 on: Oct 23rd, 2003, 5:45pm » |
|
just in case someone (koenie?) can hack this while i'm sleeping ... (12mn here! haha. or i'll get whipped! yeah yeah i know, it sucks ... well, my parents still view me as still on the road to recovery so... hehe. is it actually right for me to post that here? hehehe) http://decode.ateneo.edu/martin/SaveJPEGPNGGIF.pde
|
|
|
|
Koenie
|
Re: Save sketch to JPEG/PNG
« Reply #23 on: Oct 23rd, 2003, 8:13pm » |
|
*jaw drops* err... isn't there an easier way to save to gif? The stuff for jpg and png was so short! Koenie
|
http://koeniedesign.com
|
|
|
elout
|
Re: Save sketch to JPEG/PNG
« Reply #24 on: Oct 23rd, 2003, 8:26pm » |
|
Yesterday I got interrested trying to save a sequence of images to (raw)avi/quicktime. Anyway my jaws dropped as well seeing the (different) specs. a good source on different file-formats; http://www.wotsit.org/
|
|
|
|
Martin
|
Re: Save sketch to JPEG/PNG
« Reply #25 on: Oct 24th, 2003, 4:46am » |
|
koenie: there is of course... the thing is, it uses javax.imagio (using fry's code snip). this leaves out people who don't have 1.4. elout: a little patience and you'll get it. here's a suggestion... why not look into an animated gif first?
|
|
|
|
Koenie
|
Re: Save sketch to JPEG/PNG
« Reply #27 on: Oct 24th, 2003, 3:31pm » |
|
Ok, when I get home, I'll look into some video stuff. Damn, I love developing this kinda stuff! Koenie
|
http://koeniedesign.com
|
|
|
Martin
|
Re: Save sketch to JPEG/PNG
« Reply #28 on: Oct 24th, 2003, 4:13pm » |
|
koenie, don't you wanna fix the gif stuff first (you brought it up! )? hehe.
|
|
|
|
arielm
|
Re: Save sketch to JPEG/PNG
« Reply #29 on: Oct 24th, 2003, 4:36pm » |
|
some tips for the future video track creator: Java Media Framework (jmf) is a nice piece of software and it is supposed produce both avi & qt, but the number of codecs it can handle is ridiculously low... (a good point: the documentation is very helpfull and it gives a very good overview the concept of time-based-media) concerning qt for java: it rocks, but the api reference with all the java classes is not going to help you, what you need is to download the sdk, and you'll find a lot of working examples with source code (at least one of them is directly dealing with track creation). final note: i think it's better to stick to qt for java prior to version 6.4 since it seems that all the working examples are using the "old way" (qt for java 6.4 is introducing a lot of api changes) hands-on!..
|
« Last Edit: Oct 24th, 2003, 4:49pm by arielm » |
|
Ariel Malka | www.chronotext.org
|
|
|
|