Bir Düzen'i SDCard'ta bir Görüntü içine kaydetmeye çalışıyorum ancak bu hatayı alıyorum. Bu forumda bulduğum birkaç kodu denedim ama hepsinin hata veren aynı sıkıştırma çağrısı var. Geri dönüştürülmüş bir bitmapi sıkıştırılamıyor
Bu
ben görüntüyü kaydetmek için kullanmak kodudur: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;
}
Ve bu sdcard kaydetmek üzere kodudur:
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());
}
Şu hatayı alıyorum:
Can't compress a recycled bitmap in the compress call!
Bu çizgiyi çıkardım ve mükemmel bir şekilde çalıştım! Teşekkürler!!! – Lucia
Çizgiyi çıkarmamalısınız; Önbellekten sağlanan bitmap, sahibi olan görünüm tarafından herhangi bir zamanda geri dönüştürülebilir. Bunun yerine Bitmap'in kendi kopyasını Bitmap.copy() 'yi kullanarak almanız gerekiyor. –
Nasıl kopyalanacağını açıklayabilir misiniz? – Lucia