i am loading html data into webview , after that i need to capture webview data and stored that image into sd card. Its working fine for small images, but it gives out of memory exception for big images. i am using the following logic to do this.
private void generateImg() {
// TODO Auto-generated method stub
try{
Picture p = webview.capturePicture();
Bitmap bitmap=pictureDrawable2Bitmap(p);
String root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).toString();
File myDir = new File(root + "/Aack");
if(myDir.exists())
{
//Log.e("Directory","Existed");
}
else
{
myDir.mkdir();
}
String fname = System.currentTimeMillis()+".png";
//Log.e("file name...",""+fname);
file = new File (myDir, fname);
try
{
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
}
catch (Exception e)
{
e.printStackTrace();
}
file_name=myDir+"/"+fname;
}catch(Exception e)
{
e.printStackTrace();
}
}
private static Bitmap pictureDrawable2Bitmap(Picture picture){
PictureDrawable pictureDrawable = new PictureDrawable(picture);
Bitmap bitmap = Bitmap.createBitmap(pictureDrawable.getIntrinsicWidth(),pictureDrawable.getIntrinsicHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawPicture(pictureDrawable.getPicture());
return bitmap;
}
so, please guide me how to handle this. Thank you
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…