android-image-filter icon indicating copy to clipboard operation
android-image-filter copied to clipboard

Getting java.lang.OutOfMemoryError

Open 4tis opened this issue 10 years ago • 1 comments

Hi there,

Two things I would like to understand -

  1. After following the instructions (clean and building project),

I have tried this simple code -

    im = (ImageView) findViewById(R.id.imageView1);
    Bitmap bm = BitmapFactory.decodeResource(getResources(),R.drawable.pic);

      Bitmap newBitmap = BitmapFilter.changeStyle(bm, BitmapFilter.BLUR_STYLE);
      im.setImageBitmap(newBitmap);

The thing is that the app is crushing and i get the java.lang.OutOfMemoryError.

  1. Is it possible to save the bitmap with the filter (that are being shown at the ImageView)? and if so how can it be done?

4tis avatar Mar 19 '14 14:03 4tis

The first problem, it the algorithm issue, I will try to fixed this by optimize the algorithm and the second problem, the filter function output is a Bitmap object, so I think you can save it in your phone you android API, for example, you can write a function like this:

public void saveMyBitmap(String fileName,Bitmap mBitmap){
    File f = new File(Environment.getExternalStorageDirectory(), fileName);
    FileOutputStream fOut = null;
    try {
        f.createNewFile();
        fOut = new FileOutputStream(f);
    } catch (IOException e) {
        e.printStackTrace();
    }
    mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    try {
        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

ragnraok avatar Mar 20 '14 09:03 ragnraok