Android 提高版面中的图像质量

Android 提高版面中的图像质量,android,android-layout,android-image,Android,Android Layout,Android Image,我想将相机拍摄的图像或galery拍摄的图像放在版面中,但质量太低,你可以从这些照片中看到: 原图: 1.真实图像 2.-直接从相机拍摄此图像 3.-从图像库中获取此图像 第二张和第三张图片的质量很差,特别是第三张,但我也想提高第二张的质量。有没有办法做到这一点 以下是我用来拍照的代码(从相机和图像库): 我认为o2中使用的var标度值太大。inSampleSize=标度太大。您对图片进行的下采样太多。我认为o2中使用的var标度值太大。inSampleSize=标度太大。您对图片进行的下

我想将相机拍摄的图像或galery拍摄的图像放在版面中,但质量太低,你可以从这些照片中看到:

原图:

1.真实图像

2.-直接从相机拍摄此图像

3.-从图像库中获取此图像

第二张和第三张图片的质量很差,特别是第三张,但我也想提高第二张的质量。有没有办法做到这一点

以下是我用来拍照的代码(从相机和图像库):


我认为o2中使用的var标度值太大。inSampleSize=标度太大。您对图片进行的下采样太多。

我认为o2中使用的var标度值太大。inSampleSize=标度太大。您对图片进行的下采样太多。谢谢!它适用于画廊图像。对于相机上的照片,我不得不做一些改变,把它们作为画廊的图片,现在它们都有很好的质量。太好了!我把这个评论贴出来作为回答。你能接受吗?
   public class PhotoEditingActivity extends Activity {


private byte[] photoByteArray;
private Button btnRotate;
private ImageView ivPhoto;
private Bitmap bmp;
private Button btnEditDone;
private ChooseImageInputDialog dialogBuilder;
private AlertDialog dialog;
private Button btnCancel;
private Button btnChooseNewPhoto;
private String actualPath;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.photo_editing);
    setUpViews();
    /*try{
        getPhoto();
    }catch(Exception e){
        showOptionsDialog();
    }*/
    showOptionsDialog();
    //first try to get photo from intent, 
    //if there is no photo
    //show options to take one
}

private void showOptionsDialog() {
    dialogBuilder = new ChooseImageInputDialog(this);
    dialog = dialogBuilder.create();
    dialog.show();

}

/*private void getPhoto() {
    Intent i = this.getIntent();
    Bundle extras = i.getExtras();
    photoByteArray = extras.getByteArray("photo");
    bmp = BitmapFactory.decodeByteArray(photoByteArray, 0, photoByteArray.length);
    ivPhoto.setImageBitmap(bmp);

}*/

private void setUpViews() {
    ivPhoto = (ImageView)findViewById(R.id.ivPhotoEditing);
    btnRotate = (Button)findViewById(R.id.btnPhotoEditRotate90);
    btnRotate.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            Matrix matrix = new Matrix();
            matrix.postRotate(90);
            bmp = Bitmap.createBitmap(bmp, 0, 0, 
                                          bmp.getWidth(), bmp.getHeight(), 
                                          matrix, true);

            ivPhoto.setImageBitmap(bmp);

        }
    });
    btnCancel = (Button)findViewById(R.id.btnPhotoEditingCancel);
    btnCancel.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            PhotoEditingActivity.this.setResult(RESULT_CANCELED);
            PhotoEditingActivity.this.finish();
        }
    });

    btnChooseNewPhoto =(Button)findViewById(R.id.btnPhotoEditingTakeNewPicture);
    btnChooseNewPhoto.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            showOptionsDialog();

        }
    });

    btnEditDone = (Button)findViewById(R.id.btnPhotoEditDone);
    btnEditDone.setOnClickListener(new View.OnClickListener() {

        public void onClick(View arg0) {
            if(photoByteArray!=null){
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                bmp.compress(Bitmap.CompressFormat.PNG, 100, os);
                photoByteArray = os.toByteArray();
                Intent i = PhotoEditingActivity.this.getIntent();
                BitmapData.setBitmap(bmp);
                Log.d("actual path pea", actualPath);
                PhotoEditingActivity.this.setResult(RESULT_OK, i);
                PhotoEditingActivity.this.finish();
            }else{
                Toast t = Toast.makeText(PhotoEditingActivity.this, "Please take a picture first", Toast.LENGTH_SHORT);
                t.show();
            }

        }
    });
}

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

private Bitmap decodeFile(File f){
    try {
        //Decode image size
        BitmapFactory.Options o = new BitmapFactory.Options();
        o.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(new FileInputStream(f),null,o);

        //The new size we want to scale to
        final int REQUIRED_SIZE=70;

        //Find the correct scale value. It should be the power of 2.
        int width_tmp=o.outWidth, height_tmp=o.outHeight;
        int scale=1;
        while(true){
            if(width_tmp/2<REQUIRED_SIZE || height_tmp/2<REQUIRED_SIZE)
                break;
            width_tmp/=2;
            height_tmp/=2;
            scale*=2;
        }

        //Decode with inSampleSize
        BitmapFactory.Options o2 = new BitmapFactory.Options();
        o2.inSampleSize=scale;
        return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
    } catch (FileNotFoundException e) {}
    return null;
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    switch(requestCode) { 
    case ChooseImageInputDialog.ACTIVITY_SELECT_PHOTO:
        if(resultCode == RESULT_OK){  
            Log.d("resultcode pea pick", "result ok");
            Uri selectedImageUri=data.getData();
            actualPath=getRealPathFromURI(selectedImageUri);
            File file=new File(actualPath);
            bmp=decodeFile(file); //this is new bitmap which you can use for your purpose 

            ByteArrayOutputStream os = new ByteArrayOutputStream();
            //bmp.compress(Bitmap.CompressFormat.PNG, 65, os);
            photoByteArray = os.toByteArray();
            ivPhoto.setImageBitmap(bmp);
        }else{
            Log.d("resultcode pea pick", "result not ok");
        }
        break;
    case ChooseImageInputDialog.ACTIVITY_CAMERA_PHOTO:
        if(resultCode == RESULT_OK){
            Bundle extras = data.getExtras();
            bmp = (Bitmap)extras.get("data");
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            //bmp.compress(Bitmap.CompressFormat.PNG, 65, os);
            photoByteArray = os.toByteArray();
            ivPhoto.setImageBitmap(bmp);
            actualPath = getRealPathFromURI(data.getData());
            Log.d("take pic actual path", actualPath);

        }
        break;
    }
}
   }
    private void setUpViews() {
    // TODO Auto-generated method stub
    upSize = up.length;
    upCount = 1;
    downSize = down.length;
    downCount = 1;
    head = (ImageView)findViewById(R.id.galleryUp);
    tShirt = (ImageView)findViewById(R.id.galleryDown);
    rowUp1 = (ImageView)findViewById(R.id.ivMonkeyRowUp1);
    rowUp2 = (ImageView)findViewById(R.id.ivMonkeyRowUp2);
    rowDown1 = (ImageView)findViewById(R.id.ivMonkeyRowDown1);
    rowDown2 = (ImageView)findViewById(R.id.ivMonkeyRowDown2);
    llTab = (LinearLayout)findViewById(R.id.llTab);
    llTop = (LinearLayout)findViewById(R.id.llTop);
    monkeyTab = (LinearLayout)findViewById(R.id.llTab1);
    monkeyTab.setOnClickListener(this);
    shareTab = (LinearLayout)findViewById(R.id.llTab3);
    shareTab.setOnClickListener(this);
    web = (ImageView)findViewById(R.id.imageWeb);
    web.setOnClickListener(this);
    ll = (LinearLayout) findViewById(R.id.llPhoto);
    bmp = BitmapData.getBitmap();
    d =(Drawable) new BitmapDrawable (getResources(), bmp);
    ll.setBackgroundDrawable(d);

    head2 = (ImageView)findViewById(R.id.galleryUp2);
    tShirt2 = (ImageView)findViewById(R.id.galleryDown2);
    rowUp12 = (ImageView)findViewById(R.id.ivMonkeyRowUp12);
    rowUp22 = (ImageView)findViewById(R.id.ivMonkeyRowUp22);
    rowDown12 = (ImageView)findViewById(R.id.ivMonkeyRowDown12);
    rowDown22 = (ImageView)findViewById(R.id.ivMonkeyRowDown22);
    llPhoto2 = (LinearLayout) findViewById(R.id.llPhoto2);


}