btn_photo.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEventevent)
{
switch(v.getId())
{
case R.id.iv_photo:
if(event.getAction() ==MotionEvent.ACTION_DOWN)
{
// ImageView¶ÔÏó(iv_photo)±ØÐë×öÈçÏÂÉèÖú󣬲ÅÄÜ»ñÈ¡ÆäÖеÄͼÏñ
iv_photo.setDrawingCacheEnabled(true);
// ÔÚImageView¶ÔÏó(iv_photo)±»touch downµÄʱºò£¬»ñÈ¡ImageViewÖеÄͼÏñ
obmp = Bitmap.createBitmap(iv_photo.getDrawingCache());
//È»ºóÔÚOK°´Å¥(btn_photo)±»touch downµÄʱºò£¬±È½ÏImaageView¶ÔÏó(iv_photo)ÖеÄͼÏñºÍ
//obmpÊÇ·ñÒ»Ö£¬ÒÔ±ã×ö½øÒ»²½µÄ´¦Àí£¬±ÈÈ磬Èç¹û²»Ò»Ö¾ͱ£´æ£¬·ñÔò¾Í²»±£´æµ½Êý¾Ý¿âÖС£
//´ÓImaggeView¶ÔÏóÖлñȡͼÏñºó£¬Òª¼ÇµÃµ÷ÓÃsetDrawingCacheEnabled(false)Çå¿Õ»Í¼»º
//³åÇø£¬·ñÔò£¬ÏÂÒ»´ÎÓÃgetDrawingCache()·½·¨»ØÈ¥Í¼Ïñʱ£¬»¹ÊÇÔÀ´µÄͼÏñ
iv_photo.setDrawingCacheEnabled(false);
// ½«µÃµ½obmpдÈëÎļþ
FileOutputStream m_fileOutPutStream = null;
String filepath = Environment.getExternalStorageDirectory() +File.separator + "tempPhoto.png";
try
{
m_fileOutPutStream= new FileOutputStream(filepath);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
obmp.compress(CompressFormat.PNG, 100, m_fileOutPutStream);
try
{
m_fileOutPutStream.flush();
m_fileOutPutStream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
Intent intent = new Intent(this, TakePicture.class);
startActivityForResult(intent, 1);
}
break;
case R.id.btn_photo:
if(event.getAction() ==MotionEvent.ACTION_DOWN)
{
// ImageView¶ÔÏó(iv_photo)±ØÐë×öÈçÏÂÉèÖú󣬲ÅÄÜ»ñÈ¡ÆäÖеÄͼÏñ
iv_photo.setDrawingCacheEnabled(true);
// »ñÈ¡ImageViewÖеÄͼÏñ
Bitmap sbmp =Bitmap.createBitmap(iv_photo.getDrawingCache());
// ´ÓImaggeView¶ÔÏó(iv_photo)ÖлñȡͼÏñºó£¬Òª¼ÇµÃµ÷ÓÃsetDrawingCacheEnabled(false)
// Çå¿Õ»Í¼»º³åÇø
iv_photo.setDrawingCacheEnabled(false);