@Override
protected void onCreate(final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bitmap mBitmap = decodeResource(getResources(), R.drawable.white);
saveBitmap(mBitmap);
}
private void saveBitmap(Bitmap mBitmap){
try {
FileOutputStream out = new
FileOutputStream(this.getFilesDir().getAbsolutePath() + "/white.png");
mBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private Bitmap decodeResource(Resources resources, int id) {
TypedValue value = new TypedValue();
resources.openRawResource(id, value);
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inTargetDensity = value.density;
opts.inScaled = false;
return BitmapFactory.decodeResource(resources, id, opts);
}
从 R.drawable 中读取图片数据转换成bitmap 保持图片不放缩
于 2022-06-13 18:06:41 首次发布