2012-06-11 22 views
10

मैं व्यावहारिक बुकशेल्फ से टच V2 उदाहरण का उपयोग एक लोड बिटमैप छवि के साथ एक RelativeLayout है गैलरी से छवि। गतिविधि पर परिणाम छवि RelativeLayout में एक बिटमैप के रूप में भरी हुई है:view.getDrawingCache() केवल एक बार काम करता है

public void getPictureFromFile(Uri targetUri){ 
    try { 
     BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inSampleSize = scale(getContentResolver() 
       .openInputStream(targetUri)); 
     workinprogress = BitmapFactory.decodeStream(
       getContentResolver().openInputStream(targetUri), 
       null, options); 
     view.setImageBitmap(workinprogress); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } 
} 

एक अगला बटन क्लिक करें, मैं का उपयोग कर relativelayout की छवि हड़पने:

   thepicture.buildDrawingCache(true); 
      Bitmap bm = Bitmap.createBitmap(thepicture.getDrawingCache()); 

प्रक्रिया भयानक काम करता है - पहली छवि के लिए। जब मैं एक और छवि फिर से लोड करता हूं, तो पास बिटमैप मूल के समान ही होता है। मैंने getpicture.invalidate() और theictict.resetDrawableState() को getDrawingCache() से पहले कोशिश की है, लेकिन न ही नई लोड की गई तस्वीर में छवि को अपडेट करना प्रतीत होता है, हालांकि फ्रेम लेआउट सही छवि प्रदर्शित करता है।

क्या कुछ ऐसा है जो मुझे रीफ्रेशिंग ड्राइंग के बारे में समझ में नहीं आता है जिसे मैं दूसरी छवि के लिए लागू करने की आवश्यकता है?

उत्तर

38

इसे प्रत्येक बार प्रत्येक बार view.getDrawingCache() पर कॉल करने के बाद प्रत्येक बार view.setDrawingCacheEnabled(true) का उपयोग करने के बाद इसे और अधिक काम करने के लिए। उदाहरण देखें:

imageView.setDrawingCacheEnabled(true); 
imageView.buildDrawingCache(true); 
File imageFile = new File(Environment.getExternalStorageDirectory(), 
     "Pictures/image.jpg"); 
FileOutputStream fileOutputStream = new FileOutputStream(imageFile); 
imageView.getDrawingCache(true).compress(CompressFormat.JPEG, 100, 
     fileOutputStream); 
fileOutputStream.close(); 
imageView.setDrawingCacheEnabled(false); 
+2

+1 इसने मुझे काम के घंटों को बर्बाद करने से बचाया। अच्छा एक dmytro –

+5

ड्राइंग कैश को सक्षम करने के लिए एक वैकल्पिक विधि के रूप में, आप 'imageView.buildDrawingCache()' को भी कॉल कर सकते हैं, फिर ड्रॉइंग कैश प्राप्त करें, फिर 'imageView.destroyDrawingCache() 'पर कॉल करें। Http://developer.android.com/reference/android/view/View.html#buildDrawingCache() – lilbyrdie

+0

ने नौकरी की, धन्यवाद। –

संबंधित मुद्दे