0
URL을 받고 Imageview에 표시하고 있습니다. 내 장치의 자동 로테이션이 켜져 있습니다. 일단 이미지 뷰가 회전되면 장치의 너비에 따라 크기를 조정하고 싶습니다.자동 회전시 이미지 뷰 확장하기
URL에서 이미지를 가져올 때 가능합니까?
URL을 받고 Imageview에 표시하고 있습니다. 내 장치의 자동 로테이션이 켜져 있습니다. 일단 이미지 뷰가 회전되면 장치의 너비에 따라 크기를 조정하고 싶습니다.자동 회전시 이미지 뷰 확장하기
URL에서 이미지를 가져올 때 가능합니까?
이미지가 멀리 보이지 않게 조정되거나 회전 할 때 일어나는 일을보다 잘 제어하려는 경우 코드에서이 작업을 수행 할 수 있습니다.
먼저 장치의 폭과 높이를 얻을 :
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
그런 다음 당신은 이미지 크기를 조정하기 위해이 정보를 사용할 수 있습니다.
o.inJustDecodeBounds = true로 설정하면 이미지를로드하지 않고 이미지 크기를 얻을 수 있습니다. 이미지가 커지면 크기를 조정할 수 있습니다. 아래 예제 코드.
private Bitmap getBitmap(String path) {
Uri uri = getImageUri(path);
InputStream in = null;
try {
final int IMAGE_MAX_SIZE = 1200000; // 1.2MP
in = mContentResolver.openInputStream(uri);
// Decode image size
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(in, null, o);
in.close();
int scale = 1;
while ((o.outWidth * o.outHeight) * (1/Math.pow(scale, 2)) >
IMAGE_MAX_SIZE) {
scale++;
}
Log.d(TAG, "scale = " + scale + ", orig-width: " + o.outWidth + ",
orig-height: " + o.outHeight);
Bitmap b = null;
in = mContentResolver.openInputStream(uri);
if (scale > 1) {
scale--;
// scale to max possible inSampleSize that still yields an image
// larger than target
o = new BitmapFactory.Options();
o.inSampleSize = scale;
b = BitmapFactory.decodeStream(in, null, o);
// resize to desired dimensions
int height = b.getHeight();
int width = b.getWidth();
Log.d(TAG, "1th scale operation dimenions - width: " + width + ",
height: " + height);
double y = Math.sqrt(IMAGE_MAX_SIZE
/(((double) width)/height));
double x = (y/height) * width;
Bitmap scaledBitmap = Bitmap.createScaledBitmap(b, (int) x,
(int) y, true);
b.recycle();
b = scaledBitmap;
System.gc();
} else {
b = BitmapFactory.decodeStream(in);
}
in.close();
Log.d(TAG, "bitmap size - width: " +b.getWidth() + ", height: " +
b.getHeight());
return b;
} catch (IOException e) {
Log.e(TAG, e.getMessage(),e);
return null;
}
세트 이미지 뷰 폭 매개 변수는 match_parent하고 당신을 위해 그 규모 유형 나던 작품은 당신이 가로 세로 비율을 유지하는이 HTTP에서 살펴 봐야 할 수 있기 때문에 경우 scaleType는 내 이미지 –
을 fitXY하기 : // 개발자 .android.com/reference/android/widget/ImageView.ScaleType.html 그 중 하나가 작동하지 않으면, 당신은 스스로 조정해야 할 것입니다;) – user1619306
을 스트레칭 –