2012-11-28 3 views
0

나는 bitmap의 품질을 잃지 않고 비트 맵의 ​​높이와 너비를 줄이기 위해 인터넷에서 bitmap을 다운로드했습니다. 이것을 달성하는 방법.비트 맵의 ​​높이와 너비를 최소화하면 화질이 왜곡됩니다.

인터넷에서 비트 맵을 다운로드하는 방법입니다.

URL url_1 = null; 
try { 
    url_1 = new URL(vmImageUrl); 
    bmp = BitmapFactory.decodeStream(url_1.openConnection().getInputStream()); 
    } catch (Exception e) { 
    Log.v("Error while downloading bitmap from url", e.getMessage()); 

나는 이와 같이 크기를 조정했습니다.

Bitmap.createScaledBitmap(bmp, convertDpToPixel(140, context), convertDpToPixel(35, context), false); 

이 방법은 dp 단위를 동등한 장치 특정 값 (픽셀 단위)으로 변환합니다.

public static int convertDpToPixel(float dp,Context context) 
{ 
    Resources resources = context.getResources(); 
    DisplayMetrics metrics = resources.getDisplayMetrics(); 
    int px = (int) (dp * (metrics.densityDpi/160f)); 
    return px; 
} 

답변

0

설정했습니다.

Bitmap.createScaledBitmap(bmp, convertDpToPixel(140, context), VirtualMirrorActivity.convertDpToPixel(35, context), true); 

대신

Bitmap.createScaledBitmap(bmp, convertDpToPixel(140, context), VirtualMirrorActivity.convertDpToPixel(35, context), false); 

그것은 부드러운 가장자리 비트 맵의 ​​명확한 &에게 제공합니다. 이제는 잘 작동합니다 ...

-2

당신은 u는 현재 이미지에 대한 SRC를 설정할 수 있습니다

다음
Rect src = new Rect(); 
Rect dst = new Rect(); 

이 사각형,

src.set(0,0,imgWidth,imgHeigth); 

다음 다음 필요한 크기

dst.set(startX,startY,endX,endY); 

주의가 필요합니다 : startX와 startY가 대상이됩니다. 화면상의 좌표는 이며, UR 이미지는 U를 endX endY 좌표로 그립니다. 와 캔버스

Canvas.drawBitmap(bitmapFile, src, dst, null); 
+0

내 질문은 캔버스에 비트 맵을 그리지 않습니다. 높이와 너비를 줄인 후 품질 비트 맵이 필요합니다. –

+0

괜찮 았어.로드하기 전에 비트 맵에 선호되는 RGB를 설정할 수있다. BitmapFactory.Options 옵션 = 새로운 BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.RGB_565; \t \t \t bitmap = BitmapFactory.decodeStream (is, null, options); – cotsios

0

사용 BitmapFactory.Options.inSampleSize와 UR 비트 사람을 그릴은 작은 비트 맵을 얻을 수 있습니다.

BitmapFactory.Options opts = new BitmapFactory.Options(); 
opts.inSampleSize = 2; 
Bitmap bitmap = BitmapFactory.decodeFile(YOUR_FILE, opts); 
+0

나는 새로운 비트 맵의 ​​높이와 너비를 알려주고 싶습니다. 어쨌든 –

+0

예, 출력 비트 맵은 원본 비트 맵과 동일한 종횡비를 가지며 output.width = 1/inSampleSize * original.width입니다. 그러나 비트 맵의 ​​종횡비를 유지하지 않고 비트 맵의 ​​품질을 어떻게 유지할 수 있습니까? – faylon

+0

Bitmap.createScaledBitmap (bmp, VirtualMirrorActivity.convertDpToPixel (140, context), VirtualMirrorActivity.convertDpToPixel (35, context), false)을 사용하는 것처럼 비트 맵의 ​​widht와 height를 지정하려고합니다. –

관련 문제