這是我用來獲取全尺寸圖像的代碼,尺寸爲> 2mb尺寸,3560 X 1876尺寸。如何從本機攝像頭獲取特定尺寸的圖像
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image = (ImageView) findViewById(R.id.image);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
filePath = Environment.getExternalStorageDirectory() + "/Full_"
+ System.currentTimeMillis() + ".jpeg";
File file = new File(filePath);
Uri output = Uri.fromFile(file);
Intent i = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, output);
startActivityForResult(i, CAPTURE_IMAGE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap photo = BitmapFactory.decodeFile(filePath, options);
image.setImageBitmap(photo);
}
有沒有辦法讓特定大小的圖像,在我的情況的尺寸480×320的< 100KB大小的圖像。
檢查這篇文章,幫助你。 http://stackoverflow.com/questions/8757341/android-reduce-size-of-camera-picture 感謝 –
@MdAbdulGafur是啊,我看到了帖子,但它使用專用相機。 –