- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以更改拍照 Intent 的设置来设置生成图像的大小或分辨率?
现在我拍了一张照片,结果图像是用 16MP 和 4608x2304 拍摄的。
我想知道是否有可能获得结果图像,例如(例如):2MP 和 460x230...
我知道有这样的方法:
intent.putExtra("outputX", 460);
intent.putExtra("outputY", 230);
但我正在寻找适用于所有设备的东西(因为当然它们都没有相同的图像尺寸,如果我用硬编码值裁剪它们,那就很糟糕了)...
希望您能理解我的问题所在..
最佳答案
您需要拍照而不将其保存在文件中:
static final int REQUEST_IMAGE_CAPTURE = 1;
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
之后,您需要缩放结果位图并保存宽高比:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
Bitmap scaledImage = scaleBitmap(imageBitmap , 460, 230);
mImageView.setImageBitmap(scaledImage);
}
}
private Bitmap scaleBitmap(Bitmap bm, int maxWidth, int maxHeight) {
int width = bm.getWidth();
int height = bm.getHeight();
if (width > height) {
// landscape
int ratio = width / maxWidth;
width = maxWidth;
height = height / ratio;
} else if (height > width) {
// portrait
int ratio = height / maxHeight;
height = maxHeight;
width = width / ratio;
} else {
// square
height = maxHeight;
width = maxWidth;
}
bm = Bitmap.createScaledBitmap(bm, width, height, true);
return bm;
}
关于java - 更改 IMAGE_CAPTURE Intent 的图片大小/分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51761373/
我正在尝试使用 MediaStore.ACTION_IMAGE_CAPTURE Intent 拍摄个人资料照片。 启动 Intent 的代码: Intent cameraIntent = new In
我用 Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); intent.putExtra(MediaStore.EXT
我正在尝试理解 android.media.action.IMAGE_CAPTURE Intent 。如果我打电话: Intent intent = new Intent("android.medi
这是一种罕见的情况,我正在尝试从我的三星 galaxy s3 上的 native 相机 Activity 中捕获图像,并且 onActivityResult 文件尚不存在,无法读取。如果我断开电话并再
我运行我的 android 应用程序,其中实现了相机功能android-powered手机,但我得到的相机图像总是很小解析度。似乎默认情况下,android相机分辨率是小(如640*480),如何提高
我希望用户能够在我的应用中快速打开默认的相机应用(或他们设置为默认的应用)。但是,我不想使用 android.media.action.IMAGE_CAPTURE,因为这只会显示应用程序的拍照部分。我
是否可以更改拍照 Intent 的设置来设置生成图像的大小或分辨率? 现在我拍了一张照片,结果图像是用 16MP 和 4608x2304 拍摄的。 我想知道是否有可能获得结果图像,例如(例如):2MP
我正在尝试使用 IMAGE_CAPTURE Intent 拍照并立即在屏幕上显示这张照片。我的工作: File photoFile = createImageFile(); Intent intent
我有 Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); 10秒后可以自动拍照吗? 谢谢 最佳答案 您很可能需要使用自己
我像这样启动一个IMAGE_CAPTURE Intent,我的 Activity 的onActivityResult() 被调用: Intent i = new Intent (android.pro
我继承了在 和 provider_paths.xml MainActivity.java File f = new File(Environment.
当我尝试调用 ACTION_IMAGE_CAPTURE Intent 时,我在我的 Android 应用程序中收到了以下崩溃报告。这段代码已经在我的应用程序中运行了几个月,没有任何问题。我猜这是特定于
我是一名优秀的程序员,十分优秀!