在“主要活动”中,我调用本机“相机”应用程序。那很好。但是,单击快门后,相机将返回“主要活动”。如果他们正确拍摄了照片,那会很好。看来“相机”需要一些时间来保存图片,而离开“相机”应用会导致图片被取消。
不确定要为相机留出足够的时间保存图片而需要做什么!
import random
bases=["U", "A", "C", "G"]
b1=[random.choice(bases) for i in bases [0:3] '\n' for i in range(0,64)]
print(b1)
答案 0 :(得分:0)
在您的Activity
或Fragment
中尝试一下。
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
public 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");
mImageView.setImageBitmap(imageBitmap);
}
}
示例示例遵循此Link
有两种类型的意图:
Explicit intents
通过提供目标应用程序的程序包名称或标准组件类名称来指定哪个application
将满足intent
。通常,您将使用explicit intent
在您自己的应用程序中启动组件,因为您知道要启动的活动或服务的类名。例如,您可以响应用户的操作在应用程序中启动新的activity
,或启动服务以在后台下载文件。
Implicit intents
不命名特定组件,而是声明要执行的常规操作,该操作允许另一个应用程序中的组件进行处理。例如,如果要向用户显示地图上的位置,则可以使用隐式意图来请求另一个功能强大的应用程序在地图上显示指定位置。 More Info
注意:-图像捕获为Implicit intent
。您必须使用startActivityforResult()
。它将使用您的OS软件应用程序捕获图像并返回您的应用程序。
答案 1 :(得分:0)
I think you should use this api for camera it is easy to use and can solve your issue.
https://github.com/kosalgeek/PhotoUtil
1. Download PhotoUtil.jar
2. Copy it and paste into your Android project at App > libs > right click on the jar file and choose Add as Library
**Take a Photo using Camera**
1. Add Permissions
To use the camera, first you need to add permissions in AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
...>
<uses-feature android:name="android.hardware.camera2" android:required="true"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
...
</manifest>
2. Dispatch a Camera and Save it to External Storage
2.1. To dispatch a camera and save a photo:
CameraPhoto cameraPhoto = new CameraPhoto(getApplicationContext());
Intent in = cameraPhoto.takePhotoIntent();
startActivityForResult(in, CAMERA_REQUEST);
2.2. To get the photo path
String photoPath = cameraPhoto.getPhotoPath(); //call it in onActivityResult() method
Snippet of code:
//declare them as global variables
CameraPhoto cameraPhoto;
final int CAMERA_REQUEST = 1100;
protected void onCreate(Bundle savedInstanceState) {
...
//initialize it inside onCreate()
cameraPhoto = new CameraPhoto(getApplicationContext());
//call it to open the camera
startActivityForResult(cameraPhoto.takePhotoIntent(), CAMERA_REQUEST);
cameraPhoto.addToGallery();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(resultCode == RESULT_OK){
if(requestCode == CAMERA_REQUEST){
String photoPath = cameraPhoto.getPhotoPath();
try {
Bitmap bitmap = ImageLoader.init().from(photoPath).requestSize(512, 512).getBitmap();
imageView.setImageBitmap(bitmap); //imageView is your ImageView
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}//end if resultCode
}