Created
November 11, 2015 15:42
-
-
Save abdallaadelessa/61aa898b13f42b95d183 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String decodeFile(String path,int DESIREDWIDTH, int DESIREDHEIGHT) { | |
String strMyImagePath = null; | |
Bitmap scaledBitmap = null; | |
try { | |
// Part 1: Decode image | |
Bitmap unscaledBitmap = ScalingUtilities.decodeFile(path, DESIREDWIDTH, DESIREDHEIGHT, ScalingLogic.FIT); | |
if (!(unscaledBitmap.getWidth() <= DESIREDWIDTH && unscaledBitmap.getHeight() <= DESIREDHEIGHT)) { | |
// Part 2: Scale image | |
scaledBitmap = ScalingUtilities.createScaledBitmap(unscaledBitmap, DESIREDWIDTH, DESIREDHEIGHT, ScalingLogic.FIT); | |
} else { | |
unscaledBitmap.recycle(); | |
return path; | |
} | |
// Store to tmp file | |
String extr = Environment.getExternalStorageDirectory().toString(); | |
File mFolder = new File(extr + "/TMMFOLDER"); | |
if (!mFolder.exists()) { | |
mFolder.mkdir(); | |
} | |
String s = "tmp.png"; | |
File f = new File(mFolder.getAbsolutePath(), s); | |
strMyImagePath = f.getAbsolutePath(); | |
FileOutputStream fos = null; | |
try { | |
fos = new FileOutputStream(f); | |
scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 75, fos); | |
fos.flush(); | |
fos.close(); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
scaledBitmap.recycle(); | |
} catch (Throwable e) { | |
} | |
if (strMyImagePath == null) { | |
return path; | |
} | |
return strMyImagePath; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment