使用 android 相机 Intent 拍照时,我得到一张低质量的位图图像。我想知道是否有可能使此图像具有良好的质量。
我用谷歌搜索了一些关于它的信息,我认为我必须使用“EXTRA_OUTPUT”( http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE )
我很挣扎,因为我不知道把它放在哪里,我不知道它是否能解决我的问题。
按 btnTakePhoto 后,我更改布局并打开 android 相机。位图显示在第二个布局中(低质量)。这是我的代码:
import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
public class Camera extends AppCompatActivity {
ImageButton btnTakePhoto;
ImageView imgTakenPhoto;
private static final int CAM_REQUEST = 1313;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);
btnTakePhoto = (ImageButton) findViewById(R.id.buttonFoto);
imgTakenPhoto = (ImageView) findViewById(R.id.genomenFoto);
btnTakePhoto.setOnClickListener(new btnTakePhotoClicker());
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == CAM_REQUEST){
setContentView(R.layout.share);
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
imgTakenPhoto = (ImageView) findViewById(R.id.genomenFoto);
imgTakenPhoto.setImageBitmap(thumbnail);
}
}
class btnTakePhotoClicker implements Button.OnClickListener {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAM_REQUEST);
}
}
//CameraShare layout -- back button - Go back to first layout
public void ibBackToPhotograph(View v) {
setContentView(R.layout.camera);
btnTakePhoto = (ImageButton) findViewById(R.id.buttonFoto);
btnTakePhoto.setOnClickListener(new btnTakePhotoClicker());
}
}
编辑:图像未保存在任何地方。接受后会在 facebook 上发布 (snapchat)
原文由 Meindert Stijfhals 发布,翻译遵循 CC BY-SA 4.0 许可协议
不要使用
bitmap
,而是使用uri
。