나는 도움이 필요해. 것은 namecard 독자에 응용을하고 사진을 찍기 위하여 사진기 기능을 이용할 필요가있다. 하지만 내 앱이 앱을 종료하고 갤러리로 이동하지 않고도 저장 한 여러 가지 그림을 볼 수있게하려면 어떻게해야합니까? 아래 내가 사용하는 카메라 소스 코드 감사합니다 ..입니다 내가 카메라카메라 안드로이드에 대한 소스 코드
을 시작하는 버튼을 사용하고 CameraMainActivity.Java
private static final int REQUEST_CODE = 1;
private static final int CAMERA_PIC_REQUEST = 1337;
private Bitmap bitmap;
private ImageView imageView;
private Button save, capture;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_main);
imageView = (ImageView) findViewById(R.id.result);
save = (Button) findViewById(R.id.save);
save.setOnClickListener(this);
capture = (Button) findViewById(R.id.capture);
capture.setOnClickListener(this);
}
public void captureImage() {
// Capture image from camera
Intent intent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_PIC_REQUEST);
}
public void pickImage() {
// To pick a image from file system
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
if (requestCode == REQUEST_CODE) {
try {
// We need to recycle unused bitmaps
if (bitmap != null) {
bitmap.recycle();
}
InputStream stream = getContentResolver().openInputStream(
data.getData());
bitmap = BitmapFactory.decodeStream(stream);
stream.close();
imageView.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else if (requestCode == CAMERA_PIC_REQUEST) {
if (bitmap != null) {
bitmap.recycle();
}
bitmap = (Bitmap) data.getExtras().get("data");
if (data.getExtras().get("data") == null)
Toast.makeText(getApplicationContext(),
"No image returned", Toast.LENGTH_LONG).show();
else
imageView.setImageBitmap(bitmap);
}
}
super.onActivityResult(requestCode, resultCode, data);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_camera_main, menu);
return true;
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v == save) {
BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
Bitmap bitmap = drawable.getBitmap();
File sdCardDirectory = Environment.getExternalStorageDirectory();
File image = new File(sdCardDirectory, "test.png");
boolean success = false;
// Encode the file as a PNG image.
FileOutputStream outStream;
try {
outStream = new FileOutputStream(image);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
/* 100 to keep full quality of the image */
outStream.flush();
outStream.close();
success = true;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (success) {
Toast.makeText(getApplicationContext(),
"Image saved with success", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Error during image saving", Toast.LENGTH_LONG).show();
}
} else if (v == capture) {
captureImage();
}
}
}
`
main.xml
<Button
android:id="@+id/takeviewpic"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Take/View Pic" />
안드로이드`
응용 프로그램 폴더를 만들어 IO 파일 관리자에 이미지를 저장할 수 있습니다. 그리고 해당 폴더에서 이미지를 가져 와서 갤러리 또는 이미지보기에 표시하십시오. – Maulik