【问题标题】:Pick image from gallery and set in imageview with same size从图库中选择图像并在图像视图中设置相同大小
【发布时间】:2012-11-25 17:00:17
【问题描述】:

我想从图库中选择图像并在活动中的 imageview 中设置相同大小的图像,但我编写了代码但它没有在 imageview 中以相同大小显示。它的显示很小。相同尺寸如何实现。

这里是它设置的imageview大小

mainImageView.setLayoutParams(new LayoutParams(VirtualMirrorActivity.convertDpToPixel(270,this),VirtualMirrorActivity.convertDpToPixel(280, this)));

mainImageView.setBackgroundResource(R.layout.border);
LinearLayout linearLayout=(LinearLayout)findViewById(R.id.linearLayout);
linearLayout.addView(mainImageView);

从图库中挑选图片的意图。

Intent intent = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

startActivityForResult(Intent.createChooser(intent, "Select Picture"),10);

if (requestCode == 10 && resultCode == Activity.RESULT_OK) 
            {             
                Uri contentUri = data.getData();          
                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();         
                imageUri = Uri.parse(cursor.getString(column_index));

                InputStream stream = getContentResolver().openInputStream(data.getData());
                tempBitmap = BitmapFactory.decodeStream(stream);
                mainImageView.setImageBitmap(tempBitmap);

                if(tempBitmap!=null)
                {
                    isModel = false;
                    VMAdjustFrame.issaved = false;
                    isPhotofromAccount = false;
                    isPhotoChanged = true;
                }
            }
        }

【问题讨论】:

    标签: android android-gallery


    【解决方案1】:

    mainImageView.setLayoutParams().height = 270 mainImageView.setLayoutParams().width= 270

    图片大小

    删除它并尝试上面的代码 mainImageView.setLayoutParams(new LayoutParams(VirtualMirrorActivity.convertDpToPixel(270,this),VirtualMirrorActivity.convertDpToPixel(280, this)));

    【讨论】:

      猜你喜欢
      • 2017-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-07
      • 2018-11-07
      相关资源
      最近更新 更多