Results 1 to 8 of 8
Thread: BufferedImage through FTP
- 11-04-2009, 08:38 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 56
- Rep Power
- 0
BufferedImage through FTP
I can choose between one of these lines to send an image to my ftp server:
ftp.stor(new File("img.jpg"));
ftp.stor(new FileInputStream(new File("img.jpg")), "img.jpg");
ftp.stor(someSocket.getInputStream(), "img.jpg");
But all I have is a BufferedImage called bimg. How can I create a jpg out of that bimg or send the BufferedImage as jpg in one of those three lines?
Note: I will use this application on my server so I cannot first save it and then send it.
- 11-04-2009, 09:25 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
See the API docs for ImageIO
- 11-04-2009, 09:27 PM #3
Java Code:/** * puts an image to a ftp server. assumes ftp is already open / connected. * @param bimg the image * @param ftp that ftp client handle you're using there * @param fileName the name to stor as */ public void ftpPutImage(final BufferedImage bimg, FTP ftp, String fileName) { final PipedOutputStream pout = new PipedOutputStream(); PipedInputStream pin = new PipedInputStream(pout); // i don't know if the image io will block or until the ftp stor is finished, so thats why i run it in a thread here. Thread writerThread = new Thread(new Runnable() { public void run() { ImageIO.write(bimg, "png", pout); } }); writerThread.start(); ftp.stor(pin, fileName); }
- 11-05-2009, 03:37 PM #4
Member
- Join Date
- Oct 2009
- Posts
- 56
- Rep Power
- 0
Hm, it gives me an error:
image.java:206: local variable bimg is accessed from within inner class; needs t
o be declared final
ImageIO.write(bimg, "png", pout);
^
And also, should I change file name to something like "image.jpg" for example?
- 11-05-2009, 04:45 PM #5
yea, you see in my example, i did that
ftpPutImage(final BufferedImage bimg
- 11-05-2009, 05:08 PM #6
Member
- Join Date
- Oct 2009
- Posts
- 56
- Rep Power
- 0
I use this code for ftp:
But I get this error:Java Code:SimpleFTP ftp = new SimpleFTP(); ftp.connect("clipboard.site11.com", 21, "myusername", "mypass"); ftp.bin(); ftp.cwd("public_htm"); String fileName = "image.jpg"; ftpPutImage(bimg, ftp, fileName); ftp.disconnect();
image.java:181: cannot find symbol
symbol : class FTP
location: class image
public void ftpPutImage(final BufferedImage bimg, FTP ftp, String fileName) {
^
1 error
- 11-05-2009, 05:18 PM #7
right, i was just using FTP as example, this should be that SimpleFTP thing
Java Code:public void ftpPutImage(final BufferedImage bimg, SimpleFTP ftp, String fileName)
- 11-05-2009, 05:36 PM #8
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
BufferedImage: Uneven rescale
By legsmacgee in forum Java 2DReplies: 2Last Post: 04-24-2009, 10:48 AM -
Converting BufferedImage Into ImageIcon
By hitmen in forum AWT / SwingReplies: 9Last Post: 03-25-2009, 08:10 AM -
How to convert between SWT Image and AWT BufferedImage
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:06 PM -
Convert Byte [] to BufferedImage
By Smily in forum Advanced JavaReplies: 3Last Post: 04-28-2008, 05:54 PM -
BufferedImage to Byte
By Java Tip in forum Java TipReplies: 0Last Post: 01-22-2008, 08:17 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks