Android的 - 如何COM preSS或缩小图片? [英] Android - how to compress or downsize an image?

查看:147
本文介绍了Android的 - 如何COM preSS或缩小图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
    }
});

我有这个code。它拍照,然后将其存储在两个位置中,我想要的照片,以被存储在也对SD卡的默认位置和/文件夹/文件。一旦采取我用这个刷新屏幕...

I have this code. It takes a photo and then stores it in two locations, the default location on the SDcard and the /folder/ file i want the photo to be stored in also. Once taken i refresh the screen using this...

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);

这将刷新图像按钮,以便用户可以看到他们所拍摄的图像。然而,这是出现非常大的和充满屏幕。有没有什么办法可以COM preSS或缩小图像,从而使用户能够在一个合理的规模看呢?谢谢

This refreshes the image button so the user can see the image they have taken. However, this is appears very big and fills the screen. Is there any way i can compress or downsize the image so the user can see it at a reasonable size? thanks

推荐答案

可以乱用的ImageButton的scaleType属性(以fitXY例如,或cropCenter),并通过一个固定的大小设置为布局preferences(高度和宽度),你将所有设置。

You can mess with the ImageButton's scaleType properties (to fitXY for example, or cropCenter), and by setting a fixed size to LayoutPreferences (height and width) you'll be all set.

这篇关于Android的 - 如何COM preSS或缩小图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆