ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

Android¿ª·¢£ºÓÃgetDrawingCache·½·¨»ñÈ¡ImageViewÖеÄͼÏñÐèҪעÒâµÄÎÊÌâ(¶þ)
2014-11-24 11:36:41 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:2´Î
Tags£ºAndroid ¿ª·¢ getDrawingCache ·½·¨ »ñÈ¡ ImageView ͼÏñ ÐèÒª ×¢Òâ ÎÊÌâ
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);

Ê×Ò³ ÉÏÒ»Ò³ 1 2 3 ÏÂÒ»Ò³ βҳ 2/3/3
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºJavaµÄ·´É䣨reflect£©»úÖÆµÄѧϰ ÏÂһƪ£ºAndroid¿ª·¢£º³ÌÐòÖж¯Ì¬É趨×é¼þ..

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Spring Boot Java£º (2025-12-26 16:20:19)
¡¤Spring Boot¤ÇHello (2025-12-26 16:20:15)
¡¤Spring ¤Î»ù±¾¤«¤éŒ (2025-12-26 16:20:12)
¡¤C++Ä£°å (template) (2025-12-26 15:49:49)
¡¤C ÓïÑÔÖÐÄ£°åµÄ¼¸ÖÖ (2025-12-26 15:49:47)