bitmap 裁剪

来源:互联网 发布:app软件编程 编辑:程序博客网 时间:2024/05/22 08:20



try {if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())&& Environment.getExternalStorageDirectory().exists()) {TEST_IMAGE = Environment.getExternalStorageDirectory().getAbsolutePath() + FILE_NAME;} else {TEST_IMAGE = getApplication().getFilesDir().getAbsolutePath()+ FILE_NAME;}// 创建图片文件夹File file = new File(TEST_IMAGE);if (!file.exists()) {file.createNewFile();Bitmap pic = BitmapFactory.decodeResource(getResources(),R.drawable.gift);FileOutputStream fos = new FileOutputStream(file);pic.compress(CompressFormat.JPEG, 100, fos);fos.flush();fos.close();}} catch (Throwable t) {t.printStackTrace();TEST_IMAGE = null;}



ByteArrayOutputStream out = new ByteArrayOutputStream();bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
byte[] buffer = out.toByteArray();



0 0