के साथ लोड किए गए इमेज व्यू से बिटमैप प्राप्त करें मेरे पास एक विधि है जो छवियों को लोड करती है, अगर छवि को सर्वर पर लोड करने से पहले लोड नहीं किया गया है। फिर यह इसे ऐप्स फ़ाइल सिस्टम में संग्रहीत करता है। यदि यह फ़ाइल सिस्टम में है तो यह उस छवि को लोड करता है क्योंकि यह सर्वर से छवियों को खींचने से बहुत तेज़ है। यदि आपने ऐप को बंद किए बिना पहले छवि लोड की है तो इसे एक स्थिर शब्दकोश में संग्रहीत किया जाएगा ताकि स्मृति त्रुटियों से बचने के लिए इसे और अधिक मेमोरी का उपयोग किए बिना पुनः लोड किया जा सके।पिकासो
यह सब ठीक काम किया जब तक कि मैंने पिकासो छवि लोडिंग लाइब्रेरी का उपयोग शुरू नहीं किया। अब मैं छवियों को एक छवि दृश्य में लोड कर रहा हूं लेकिन मुझे नहीं पता कि बिटमैप को वापस कैसे किया जाए ताकि मैं इसे फ़ाइल या स्थिर शब्दकोश में संग्रहीत कर सकूं। इसने चीजों को और अधिक कठिन बना दिया है। क्योंकि इसका मतलब है कि यह हर बार सर्वर से छवि लोड करने का प्रयास करता है, जो कुछ ऐसा नहीं करना चाहता है। क्या कोई तरीका है कि मैं इसे छविव्यू में लोड करने के बाद बिटमैप प्राप्त कर सकता हूं? नीचे मेरा कोड है:
public Drawable loadImageFromWebOperations(String url,
final String imagePath, ImageView theView, Picasso picasso) {
try {
if (Global.couponBitmaps.get(imagePath) != null) {
scaledHeight = Global.couponBitmaps.get(imagePath).getHeight();
return new BitmapDrawable(getResources(),
Global.couponBitmaps.get(imagePath));
}
File f = new File(getBaseContext().getFilesDir().getPath()
.toString()
+ "/" + imagePath + ".png");
if (f.exists()) {
picasso.load(f).into(theView);
**This line below was my attempt at retrieving the bitmap however
it threw a null pointer exception, I assume this is because it
takes a while for Picasso to add the image to the ImageView**
Bitmap bitmap = ((BitmapDrawable)theView.getDrawable()).getBitmap();
Global.couponBitmaps.put(imagePath, bitmap);
return null;
} else {
picasso.load(url).into(theView);
return null;
}
} catch (OutOfMemoryError e) {
Log.d("Error", "Out of Memory Exception");
e.printStackTrace();
return getResources().getDrawable(R.drawable.default1);
} catch (NullPointerException e) {
Log.d("Error", "Null Pointer Exception");
e.printStackTrace();
return getResources().getDrawable(R.drawable.default1);
}
}
किसी भी मदद की सराहना की जाएगी, धन्यवाद!
पिकासो हर बार सर्वर से छवियों को लोड नहीं करेगा। केवल पहली बार तो यह कैश निर्देशिका से लोड होता है। – intrepidkarthi