其实这个也没什么太多的东西,我就直接上两个方法,大家自己去研究:
(1)Bitmap->Drawable
public static Drawable getDrawable(Context ctx, Bitmap bitmap){
if (density == 0) {
DisplayMetrics metrics = new DisplayMetrics();
WindowManager wm = (WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getMetrics(metrics);
density = metrics.densityDpi;
}
BitmapDrawable d = new BitmapDrawable(bitmap);
d.setTargetDensity((int) (density * (density * 1.0f / 240)));
return d;
}
(2)Bitmap->.png,.jpg格式的文件
public void saveMyBitmap(String bitName, Bitmap bitmap) throws IOException {
File f = new File("/sdcard/" + bitName + ".png");
f.createNewFile();
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bitmap.compress(Bitmap.CompressFormat.PNG, 0, fOut);
try {
fOut.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}