Skip to content

Instantly share code, notes, and snippets.

@truongngoclinh
Last active March 29, 2016 10:05
Show Gist options
  • Save truongngoclinh/ddc1567aaa6ec83e6f4e to your computer and use it in GitHub Desktop.
Save truongngoclinh/ddc1567aaa6ec83e6f4e to your computer and use it in GitHub Desktop.
for (int i = 568; i <= 647; i++) {
String fileName1 = "Image#" + i + ".jpg";
//String fileName2 = "image"+i+".jpg";
//File file1 = new File(PATH+"/"+fileName1);
//File file2 = new File(PATH+"/"+fileName2);
if (file1.exists()) {
file1.renameTo(file2);
}
Bitmap bitmap = BitmapFactory.decodeFile(PATH + File.separator + fileName1);
Bitmap resized = Bitmap.createBitmap(bitmap, 0, bitmap.getHeight() / 8 + 10, bitmap.getWidth(), bitmap.getHeight() / 2 - 3);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
resized.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
//you can create a new file name "test.jpg" in sdcard folder.
File f = new File(PATH1 + File.separator + "image" + i + ".jpg");
try {
f.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//write the bytes in file
FileOutputStream fo = null;
try {
fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment