「Java学習」javaでbmpをjpegに変換するサンプルコード
Javaコード:
public static String saveBitmap2File(String url) throws IOException {
BufferedInputStream inBuff = null;
BufferedOutputStream outBuff = null;
SimpleDateFormat sf = new SimpleDateFormat(“yyyy_MM_dd_HH_mm_ss");
String timeStamp = sf.format(new Date());
File targetFile = new File(Constants.ENVIROMENT_DIR_SAVE, timeStamp
+ “.jpg");
File oldfile = ImageLoader.getInstance().getDiscCache().get(url);
try {
inBuff = new BufferedInputStream(new FileInputStream(oldfile));
outBuff = new BufferedOutputStream(new FileOutputStream(targetFile));
byte[] buffer = new byte[BUFFER];
int length;
while ((length = inBuff.read(buffer)) != -1) {
outBuff.write(buffer, 0, length);
}
outBuff.flush();
return targetFile.getPath();
} catch (Exception e) {
} finally {
if (inBuff != null) {
inBuff.close();
}
if (outBuff != null) {
outBuff.close();
}
}
return targetFile.getPath();
}