I want to pick the image from gallery and set the image with same size in imageview in activity but i wrote code but its not displaying on with same size in imageview. its displaying small. How to achieve with same size.
Here its set size of 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 for pick image from gallery.
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;
}
}
}
mainImageView.setLayoutParams().height = 270
mainImageView.setLayoutParams().width= 270
size of image
remove this and try code above mainImageView.setLayoutParams(new LayoutParams(VirtualMirrorActivity.convertDpToPixel(270,this),VirtualMirrorActivity.convertDpToPixel(280, this)));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.