Beg*_*ner 4 compression android image
ImageButton avatarButton = (ImageButton) findViewById(R.id.ImageButton_Avatar);
avatarButton.setImageResource(R.drawable.avatar);
strAvatarFilename = "Image.jpg";
final Uri imageUriToSaveCameraImageTo = Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/Folder/"+strAvatarFilename));
avatarButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent pictureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
pictureIntent.putExtra( MediaStore.EXTRA_OUTPUT, imageUriToSaveCameraImageTo );
startActivityForResult(Intent.createChooser(pictureIntent, strAvatarPrompt), TAKE_AVATAR_CAMERA_REQUEST);
Editor editor = Preferences.edit();
editor.putString(PREFERENCES_AVATAR, imageUriToSaveCameraImageTo.getPath());
editor.commit();
}
});
Run Code Online (Sandbox Code Playgroud)
我有这个代码.它需要一张照片,然后将它存储在两个位置,SD卡上的默认位置和/文件夹/文件我希望照片也存储在其中.一旦拍下我用这个刷新屏幕......
ImageButton avatarButton = (ImageButton) findViewById(R.id.ImageButton_Avatar);
String strAvatarUri = Preferences.getString(PREFERENCES_AVATAR, "");
Uri imageUri = Uri.parse(strAvatarUri);
avatarButton.setImageURI(null);
avatarButton.setImageURI(imageUri);
Run Code Online (Sandbox Code Playgroud)
这将刷新图像按钮,以便用户可以看到他们拍摄的图像.然而,这显得非常大并且填满了屏幕.有什么方法可以压缩或缩小图像,以便用户可以以合理的尺寸看到它吗?谢谢
Sha*_*ade 17
Bitmap thumb = Bitmap.createScaledBitmap (BitmapFactory.decodeFile(photoPath), 96, 96, false);
Run Code Online (Sandbox Code Playgroud)
其中createScaledBitmap的第二个和第三个参数分别是宽度和高度.
编辑:我现在想到你可以使用B itmapFactory.Options和inSampleSize选项以更快,更有效的方式做到这一点:
BitmapFactory.Options opts = new BitmapFactory.Options ();
opts.inSampleSize = 2; // for 1/2 the image to be loaded
Bitmap thumb = Bitmap.createScaledBitmap (BitmapFactory.decodeFile(photoPath, opts), 96, 96, false);
Run Code Online (Sandbox Code Playgroud)
这样您将节省更多内存,缩小尺寸应该花费更少的时间.
| 归档时间: |
|
| 查看次数: |
11639 次 |
| 最近记录: |