안녕하세요 저는 android에서 새롭습니다. 아무도 이미지의 종횡비를 유지하도록 도와 줄 수 있습니까? 내 응용 프로그램에서 SDCARD에서 이미지를 선택하고 다음 활동에 의도를 전달하여 이미지 뷰에 표시합니다. 그러나 이미지가 크거나 작을 때 대부분의 경우 이미지가 내 이미지 뷰에 제대로 표시되지 않습니다.android image는 종횡비를 유지하지 않습니다
BitmapFactory.Options options = new BitmapFactory.Options();
options.inTempStorage = new byte[16 * 1024];
options.inJustDecodeBounds = true;
bitmap = BitmapFactory.decodeStream(getContentResolver()
.openInputStream(mImageCaptureUri));
ByteArrayOutputStream bs = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 50, bs);
Bitmap newbitmap = Bitmap.createScaledBitmap(bitmap, 120,
120, true);
newbitmap.compress(Bitmap.CompressFormat.PNG, 50, bs);
Intent photointent = new Intent(MethinkzActivity.this,
DisplayImage.class);
photointent.putExtra("photo", bs.toByteArray());
startActivity(photointent);
그리고 다른 활동에서 나는 다음을 사용하여 그것을 잡습니다.
bitmap = BitmapFactory.decodeByteArray(getIntent()
.getByteArrayExtra("photo"), 0, getIntent()
.getByteArrayExtra("photo").length);
final double viewWidthToBitmapWidthRatio = (double) my_image
.getWidth()/(double) bitmap.getWidth();
my_image.getLayoutParams().height = (int) (bitmap.getHeight() * viewWidthToBitmapWidthRatio);
my_image.setImageBitmap(bitmap);
이 부분을 찾으십시오.
감사를 이미지 뷰에 대한 XML 파일에서이 속성은 하나의 스케일 유형 사용하는 이미지 뷰 사용을 위해 이미지 뷰의 Scalling 속성을 사용해야한다을 reply @jeet를 위해. 나는 이것을 작성했지만 OutOfMemoryError를 제공하는 대부분의 시간. –
OutOfMemoryError가 다른 문제이므로이 오류를 찾아야하며이 오류를 피할 수있는 충분한 가이드가 제공됩니다. – jeet