示例代码 FFFFFF), 文字阴影是50, 文字水印内容是:Hello 图片服务!,水印位置是:右中,水平边距是:10,中线垂直偏移是:20 is.getObject(bucket, objectName, "@oosImagewatermark2&typed3F5LXplbmhlaQ&size20&textSGVsbG8g5Zu54mH5pyN5YqhIQ&colorI0ZGRkZGRg&s50&t90&p6&x10&voffset20", new File("wartermark.jpg")); } private String authorize(String httpVerb, String date, String bucket, String objectName) throws Exception { String stringToSign httpVerb + "nnn" + date + "n/" + bucket + "/" + objectName; Mac mac Mac.getInstance("HmacSHA1"); mac.init(new SecretKeySpec(sk.getBytes("UTF8"), "HmacSHA1")); byte[] macResult mac.doFinal(stringToSign.getBytes("UTF8")); String signature new String(Base64.encodeBase64(macResult), "UTF8"); String authorization "AWS " + ak + ":" + signature; return authorization; } public static void downloadInputStream(InputStream input, File file) throws IOException { int c; FileOutputStream fos new FileOutputStream(file); byte[] buff new byte[1024 4]; try { while ((c input.read(buff)) ! 1) { fos.write(buff, 0, c); } input.close(); fos.flush(); } finally { fos.close(); } } public void getObject(String bucketName, String objectName, String imageParams, File destFile) throws Exception { String date DATEFMT.format(new Date()); String authorization authorize("GET", date, bucketName, objectName + imageParams); URL url new URL("https", host, "/" + bucketName + "/" + objectName + imageParams); HttpURLConnection conn (HttpURLConnection) url.openConnection(); conn.setUseCaches(false); conn.setRequestProperty("Date", date); conn.setRequestProperty("Authorization", authorization); conn.setConnectTimeout(CONNTIMEOUT); conn.setReadTimeout(READTIMEOUT); conn.setDoInput(true); conn.setRequestMethod("GET"); conn.connect(); downloadInputStream(conn.getInputStream(), destFile); } }