मैं एसडीकार्ड में एक लेआउट को एक छवि में सहेजने की कोशिश कर रहा हूं लेकिन मुझे यह त्रुटि मिलती है। मैंने इस मंच में कई कोडों की कोशिश की लेकिन उनमें से सभी को एक ही संपीड़न कॉल है जो त्रुटि दे रहा है।एक पुनर्नवीनीकरण बिटमैप को संकुचित नहीं कर सकता
इस कोड मैं छवि को बचाने के लिए उपयोग करते हैं:
private Bitmap TakeImage(View v) {
Bitmap screen = null;
try {
v.setDrawingCacheEnabled(true);
v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.buildDrawingCache(true);
screen = v.getDrawingCache();
v.setDrawingCacheEnabled(false); // clear drawing cache
} catch (Exception e) {
e.printStackTrace();
}
return screen;
}
और यह SDCard में सहेजने के लिए कोड है:
private void saveGraph(Bitmap graph, Context context) throws IOException {
OutputStream fOut = null;
File file = new File(Environment.getExternalStorageDirectory()
+ File.separator + "test.jpg");
fOut = new FileOutputStream(file);
graph.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush();
fOut.close();
MediaStore.Images.Media.insertImage(getContentResolver(),
file.getAbsolutePath(), file.getName(), file.getName());
}
मैं त्रुटि हो रही है:
Can't compress a recycled bitmap in the compress call!
यह वह था! मैंने उस रेखा को बाहर निकाला और पूरी तरह से काम किया! धन्यवाद!!! – Lucia
आपको लाइन नहीं लेनी चाहिए; कैश से प्रदान किए गए बिटमैप को किसी भी समय उस दृश्य के द्वारा पुनर्नवीनीकरण किया जा सकता है, जिसका मालिक है। आपको वास्तव में 'बिटमैप.copy()' का उपयोग करके बिटमैप की अपनी प्रतिलिपि लेने की आवश्यकता है। –
क्या आप इसे कॉपी करने की व्याख्या कर सकते हैं? – Lucia