package map.demo;
public class MapDemoActivity extends Activity {
Button capture;
ImageView image;
int cameracode=100;
Bitmap bm;
Boolean result;
FileOutputStream fos;
File sd;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
capture=(Button)findViewById(R.id.capture);
capture.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
image=(ImageView)findViewById(R.id.image);
Intent i=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameracode);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(requestCode==100)
{
bm=(Bitmap) data.getExtras().get("data");
image.setImageBitmap(bm);
image.setDrawingCacheEnabled(true);
bm = image.getDrawingCache();
if(bm==null)
{
Toast.makeText(getApplicationContext(), "Image is null", 1000).show();
}
else
{
try {
fos = new FileOutputStream(new File(Environment.getExternalStorageDirectory(), "image.jpg"));
result=bm.compress(CompressFormat.JPEG, 75, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}
}
我做上面的代碼,以捕捉攝像機圖像,並設置圖像圖像視圖 &轉換圖像JPEG, 但我沒有得到的圖像,它顯示了空。即在圖像捕獲後我的代碼bm = null。 但圖像視圖顯示圖像,這是默認情況下相機(我正在使用模擬器捕捉圖像)。相機圖像轉換
感謝它的工作....偉大的工作 – user1461473
很高興聽到..所以如何接受這作爲答案然後.. :) –