java将捕获的图像保存为JPEG的PNG格式
我是Android新手。我正在Eclipse中使用一个摄像头应用程序。捕获的图像存储到应用程序文件夹(内部存储器)。图像存储为JPEG格式,但我希望它保存为PNG格式。但是,我不想将映像保存在外部存储目录上
这是我的密码:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
String date = dateFormat.format(new Date());
String photoFile = "Picture_" + date + ".JPEG";
String filename = pictureFileDir.getPath() + File.separator + photoFile;
File pictureFile = new File(filename);
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
bmp.compress(Bitmap.CompressFormat.PNG,100,fos);
fos.flush();
// fos.write(data);
fos.close();
Toast.makeText(context, "New Image saved:" + photoFile,Toast.LENGTH_LONG).show();
} catch (Exception error) {
//Log.d(IntersaActivity.DEBUG_TAG, "File" + filename + "not saved: "+ error.getMessage());
Toast.makeText(context, "Image could not be saved.",
Toast.LENGTH_LONG).show();
}
}
private File getDir() {
String filepath = "MyFileStorage";
ContextWrapper contextWrapper = new ContextWrapper(context);
File sdDir = contextWrapper.getDir(filepath, Context.MODE_PRIVATE);
//File sdDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
return new File(sdDir, "CameraAPIDemo");
}
}
# 1 楼答案
使用
并将文件名的扩展名设置为PNG
希望能有帮助
编辑:调用此方法的总代码