我創建一個應用程序,並希望建立一個畫廊視圖。我不希望圖庫視圖中的圖像爲全尺寸。如何在Android中調整圖像大小?如何在Android中調整圖像大小?
72
A
回答
146
嘗試:
Bitmap yourBitmap;
Bitmap resized = Bitmap.createScaledBitmap(yourBitmap, newWidth, newHeight, true);
或:
resized = Bitmap.createScaledBitmap(yourBitmap,(int)(yourBitmap.getWidth()*0.8), (int)(yourBitmap.getHeight()*0.8), true);
+8
它顯示低比例模糊圖像... –
4
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize=2; //try to decrease decoded image
Bitmap bitmap=BitmapFactory.decodeStream(is, null, options);
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, fos); //compressed bitmap to file
6
可以使用矩陣來調整你的攝像機圖像....
BitmapFactory.Options options=new BitmapFactory.Options();
InputStream is = getContentResolver().openInputStream(currImageURI);
bm = BitmapFactory.decodeStream(is,null,options);
int Height = bm.getHeight();
int Width = bm.getWidth();
int newHeight = 300;
int newWidth = 300;
float scaleWidth = ((float) newWidth)/Width;
float scaleHeight = ((float) newHeight)/Height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0,Width, Height, matrix, true);
BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
6
捕獲圖像和調整它。
Bitmap image2 = (Bitmap) data.getExtras().get("data");
img.setImageBitmap(image2);
String incident_ID = IncidentFormActivity.incident_id;
imagepath="/sdcard/RDMS/"+incident_ID+ x + ".PNG";
File file = new File(imagepath);
try {
double xFactor = 0;
double width = Double.valueOf(image2.getWidth());
Log.v("WIDTH", String.valueOf(width));
double height = Double.valueOf(image2.getHeight());
Log.v("height", String.valueOf(height));
if(width>height){
xFactor = 841/width;
}
else{
xFactor = 595/width;
}
Log.v("Nheight", String.valueOf(width*xFactor));
Log.v("Nweight", String.valueOf(height*xFactor));
int Nheight = (int) ((xFactor*height));
int NWidth =(int) (xFactor * width) ;
bm = Bitmap.createScaledBitmap(image2,NWidth, Nheight, true);
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bm.compress(CompressFormat.PNG, 100, ostream);
ostream.close();
4
bm = Bitmap.createScaledBitmap(bitmapSource, width, height, true);
:)
28
public Bitmap resizeBitmap(String photoPath, int targetW, int targetH) {
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeFile(photoPath, bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
int scaleFactor = 1;
if ((targetW > 0) || (targetH > 0)) {
scaleFactor = Math.min(photoW/targetW, photoH/targetH);
}
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true; //Deprecated API 21
return BitmapFactory.decodeFile(photoPath, bmOptions);
}
5
//照片是位圖圖像
Bitmap btm00 = Utils.getResizedBitmap(photo, 200, 200);
setimage.setImageBitmap(btm00);
And in Utils class :
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth)/width;
float scaleHeight = ((float) newHeight)/height;
Matrix matrix = new Matrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// RECREATE THE NEW BITMAP
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
matrix, false);
return resizedBitmap;
}
2
resized = Bitmap.createScaledBitmap(yourImageBitmap,(int)(yourImageBitmap.getWidth()*0.9), (int)(yourBitmap.getHeight()*0.9), true);
0
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 10;
FixBitmap = BitmapFactory.decodeFile(ImagePath, options);
//FixBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.gv);
byteArrayOutputStream = new ByteArrayOutputStream();
FixBitmap.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayOutputStream); //compress to 50% of original image quality
byteArray = byteArrayOutputStream.toByteArray();
ConvertImage = Base64.encodeToString(byteArray, Base64.DEFAULT);
相關問題
- 1. Android圖像調整大小
- 2. 在Android中調整大小圖像
- 3. 在android中調整圖像大小
- 4. 如何在調整窗口大小時調整圖像大小?
- 5. 如何在Android中調整圖像大小而不縮小?
- 6. 如何在調整圖像大小時調整圖像大小使用drawImage
- 7. 如何在窗口中調整圖像大小在CSS中調整大小?
- 8. Android如何調整其圖像調整大小後的佈局
- 9. 用Java調整圖像大小。如何調整大小
- 10. 如何根據圖像大小調整圖像視圖大小?
- 11. 在Java中調整圖像大小以縮小圖像大小
- 12. 如何在Android中滾動時調整圖像大小?
- 13. 如何防止圖像在Android中調整大小
- 14. 如何在Android中調整GIF圖像大小?
- 15. Android視頻和圖像調整大小
- 16. 圖像縮放調整大小IMAGEVIEW android
- 17. Android ListView圖像調整大小
- 18. 如何調整圖像大小?
- 19. 如何調整圖像大小
- 20. 如何調整Javascript圖像大小?
- 21. 如何使圖像調整大小
- 22. 如何調整圖像大小
- 23. 如何調整圖像大小?
- 24. CSS如何調整圖像大小?
- 25. 如何調整圖像大小?
- 26. 如何調整Uri的圖像大小?
- 27. iPhone如何調整圖像大小?
- 28. Python如何調整圖像大小?
- 29. 如何調整圖像大小?
- 30. 如何調整RTF圖像大小
您想降低大小,如果圖片或 剛想要顯示小? – MAC