我真的寻遍整个网站,然后再发布。 我的问题是,我不能不失图像质量调整位图(质量实在是太差和像素化)。
我把位图从相机,然后我不得不缩减它,这样我就可以把它上传到服务器更快。
这是做采样功能
public Bitmap resizeBitmap(Bitmap bitmap){
Canvas canvas = new Canvas();
Bitmap resizedBitmap = null;
if (bitmap !=null) {
int h = bitmap.getHeight();
int w = bitmap.getWidth();
int newWidth=0;
int newHeight=0;
if(h>w){
newWidth = 600;
newHeight = 800;
}
if(w>h){
newWidth = 800;
newHeight = 600;
}
float scaleWidth = ((float) newWidth) / w;
float scaleHeight = ((float) newHeight) / h;
Matrix matrix = new Matrix();
// resize the bit map
matrix.preScale(scaleWidth, scaleHeight);
resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, matrix, true);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawBitmap(resizedBitmap, matrix, paint);
}
return resizedBitmap;
这是我是如何从活动结果得到的图像
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if(resultCode != RESULT_CANCELED){
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
getContentResolver().notifyChange(mImageUri, null);
ContentResolver cr = this.getContentResolver();
try
{
b = android.provider.MediaStore.Images.Media.getBitmap(cr, mImageUri);
Log.d("foto", Integer.toString(b.getWidth()));
Log.d("foto", Integer.toString(b.getHeight()));
addPhoto.setImageBitmap(b);
}
catch (Exception e)
{
Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();
Log.d("TAG", "Failed to load", e);
}
}
}
我开始以为得到的小画面尺寸的最佳方式是设置摄像头分辨率。 任何人都可以帮忙吗?