I would like to reduce size of photo befo开发者_高级运维re uploading to picasa using picasa java api. How can I resize photo during upload with Picasa API?
As far as I see in the API, photos has to be resized before the upload. Luckily, it is easy to do in Java.
I used a combination of ImageIO and imgscalr:
import javax.imageio.ImageIO;
import org.imgscalr.Scalr;
InputStream myPhotoInputStream = // new FileInputStream(file)
// or FileItemStream.openStream(); from an HTTP upload
OutputStream outstream = ...
BufferedImage image = ImageIO.read( myPhotoInputStream );
int maxDimension = 1024;
image = Scalr.resize(image, maxDimension);
ImageIO.write(image, "JPEG", outstream);
Unfortunately when you resize, you lose the EXIF metadata. I have yet to find a library capable of simply saving this on read and restoring it on write. Apache commons-imaging looked promising but seems unable to write a JPEG.
精彩评论