-1

I am trying to draw lines in my app. After it is done, i want to save the screen as an image. But i don't want the button to be in the image. I want to crop it and then save it. I have tried to use this code to crop my bitmap in onclicklistener. But it didn't work. Bitmap.createBitmap(bitmap, 5, 5, 5, 5); this is my all code:

    content.setDrawingCacheEnabled(true); 
    content.buildDrawingCache(); 
    Bitmap bitmap = Bitmap.createBitmap(content.getDrawingCache()); // Bitmap
    Bitmap.createBitmap(bitmap, 5, 5, 5, 5);
    content.setDrawingCacheEnabled(false);

    File file = new File("/sdcard/SurucuImza.jpg");
    FileOutputStream ostream = null;



    try {
        if (bitmap != null) {
            file.createNewFile();
            ostream = new FileOutputStream(file);
            bitmap.compress(CompressFormat.JPEG, 100, ostream); 
            ostream.flush();
            ostream.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    bitmap.recycle();
    bitmap = null;
    ostream = null;
    content.setDrawingCacheEnabled(false);

}
Patrick
  • 11
  • 6

2 Answers2

1

You should assign the result of this line to a variable:

Bitmap.createBitmap(bitmap, 5, 5, 5, 5);

//Ex:
Bitmap croppedBitmap = Bitmap.createBitmap(bitmap, 5, 5, 5, 5);

and then save the croppedBitmap instead of bitmap.

One more thing, are you sure your button is 5x5 pixel? The last two parameters of createBitmap() specifies the width and height.

Andy Res
  • 15,963
  • 5
  • 60
  • 96
0

Due to the variable size of Android screens sizes and densities I would suggest you to NOT use the content, but on your XML layout you have a ViewGroup that will be "printscreenable" and the other area (outside the viewgroup) with the button.

That way you'll have to do the same operation but using the viewGroup instead of the content

Budius
  • 39,391
  • 16
  • 102
  • 144