public class TestCameraActivity extends Activity implements OnClickListener{ private Uri mOutPutFileUri;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button takePiCButton = (Button) this.findViewById(R.id.button1);
takePiCButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
saveFullImage();
break;
default:
break;
}
}
private void saveFullImage(){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//文件夹aaaa
String path = Environment.getExternalStorageDirectory().toString()+"/aaaa";
File path1 = new File(path);
if(!path1.exists()){
path1.mkdirs();
}
File file = new File(path1,System.currentTimeMillis()+".jpg");
mOutPutFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mOutPutFileUri);
startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1){
Uri imageUri = null;
if(data != null){
if(data.hasExtra("data")){
Bitmap thunbnail = data.getParcelableExtra("data");
//处理缩略图
}
}else{
//处理mOutPutFileUri中的完整图像
}
}
}
}
为什么不这样做那
Bundle extras = data.getExtras();
Bitmap bitmap = (Bitmap) extras.get("data");
这样可以得到一个Bitmap对象,可以利用流存到你想存的位置
public class TestCameraActivity extends Activity implements OnClickListener{ private Uri mOutPutFileUri;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button takePiCButton = (Button) this.findViewById(R.id.button1);
takePiCButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
saveFullImage();
break;
default:
break;
}
}
private void saveFullImage(){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//文件夹aaaa
String path = Environment.getExternalStorageDirectory().toString()+"/aaaa";
File path1 = new File(path);
if(!path1.exists()){
path1.mkdirs();
}
File file = new File(path1,System.currentTimeMillis()+".jpg");
mOutPutFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mOutPutFileUri);
startActivityForResult(intent, 1);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == 1){
Uri imageUri = null;
if(data != null){
if(data.hasExtra("data")){
Bitmap thunbnail = data.getParcelableExtra("data");
//处理缩略图
}
}else{
//处理mOutPutFileUri中的完整图像
}
}
}
}