Android memory error with images

plugins

#1

Hi, I’m having problems with my phone memory. I have a list of items to take a picture, I’m using the fresco already, but even so in the 4th photo it gives the error :

java.lang.OutOfMemoryError: Failed to allocate a 1352612 byte allocation with 945552 free bytes and 923KB until OOM

I’m doing this:

 takePhoto(index) {
    let options = { width: 640, height: 480, keepAspectRatio: false, saveToGallery: false };
    requestPermissions().then(
      () => {
        takePicture(options)
          .then((imageAsset: any) => {
            let source = new ImageSource();
            //this.setPhoto(index, imageAsset);
            source.fromAsset(imageAsset).then((source) => {
              //this.teste = source.toBase64String('png');
              this.setPhoto(index, source.toBase64String('jpeg'));
            });
          }, (error) => {
            console.log("Error: " + error);
          });
      },
      () => alert('Sem permissão para acessar a câmera!')
    );
  }

setPhoto(index, photo) {
    this.imgs[index] = "data:image/jpeg;base64,"+photo;
  }

In my view :

 <FrescoDrawee rowSpan="2" width="72" height="72" margin="3" backgroundColor="lightgray"
        verticalAlignment="top" placeholderImageUri="res://ic_logo" aspectRatio="2" [imageUri]="imgs[i] ? imgs[i] : ''"></FrescoDrawee>

#2

Did you try?


#3

I tried, with this solution I was able to take 13 photos, and on 14th I gave the error. I need to take 22 photos. I did not find anything on the forums about this.


#4

If you are not cleaning up any files from memory, do it so you can reclaim the memory after processing each photo. Try Android Device Monitor to find where it leaks.


#5

I was able to solve by removing the Fresco. And changing to not generate the base64. As I have saved, I converts in time to upload to the server. It looks like this:

setPhoto(index, photo) {
    this.imgs[index] = photo;
  }

  takePhoto(index) {
    let options = { width: 640, height: 480, keepAspectRatio: false, saveToGallery: false };
    requestPermissions().then(
      () => {
        takePicture(options)
          .then((imageAsset: any) => {
            this.setPhoto(index, imageAsset);
          }, (error) => {
            console.log("Error: " + error);
          });
      },
      () => alert('Sem permissão para acessar a câmera!')
    );
  }

In view :

<Image [src]="imgs[i] ? imgs[i] : ''" [id]="i" rowSpan="2" width="72" height="72" margin="3" backgroundColor="lightgray"
          verticalAlignment="top"></Image>

What do you think ?