【安卓开发 】Android判断图片的真正格式以及转为jpeg格式
public String getPictureType(String path){String type ="";try{BitmapFactory.Options options = new BitmapFactory.Options();options.inJustDecodeBounds = true;BitmapFactory.decodeFile(path,opt...
·
public String getPictureType(String path)
{
String type ="";
try{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path,options);
type = options.outMimeType;
}catch(Exception e)
{
Log.e("TAG :getPictureType " ,e.getMessage()) ;
}
return type == null ? "":type;
}
public static void convertToJpg(String pngFilePath, String jpgFilePath) {
Bitmap bitmap = BitmapFactory.decodeFile(pngFilePath);
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(jpgFilePath))) {
if (bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos)) {
bos.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
}
更多推荐



所有评论(0)