2017-10-02 6 views
0

캔버스에서 하나 이상의 비트 맵 이미지를 생성하고 있지만 자주 메모리가 부족하여 어디에서 비트 맵 이미지를 압축해야하는지 잘 모릅니다.언제 비트 맵을 압축해야합니까

// create a bitmap from the canvas 
    canvas.drawBitmap(printOutBitmap, width, 0, null); 

    // should printOutBitmap be compressed here? 

    // Initialize a new ByteArrayStream 
    ByteArrayOutputStream stream = new ByteArrayOutputStream(); 

    Bitmap[] imgs = new Bitmap[numImages]; 
    Bitmap bitmapImage; 

    // splitting the bitmaps 
    for (int i = 0 ; i < imgs.length; i++) 
    { 
     // create a single bitmap from the area of the original bitmap 
     bitmapImage = Bitmap.createBitmap(printOutBitmap, 0, y, printOutBitmap.getWidth(), h); 

     // the returned bitmap needs to be a predefined width/height 
     bitmapImage = Bitmap.createScaledBitmap(bitmapImage, width, height, false); 

     bitmapImage.compress(Bitmap.CompressFormat.PNG, 100, stream); 
     imgs[i] = bitmapImage; 
    } 

압축 된 printOutBitmap이지만 메모리가 부족한 반면 모든 비트 맵을 압축하는 데 너무 많은 시간이 걸립니다. 어떤 도움이나 '우수 사례'라도 크게 감사 할 것입니다. 고맙습니다!

답변

0

compress()은 압축 형식 (PNG, JPEG, WebP)으로 디스크에 Bitmap을 저장합니다. 이 아닌의 메모리 사용량을 변경하면 Bitmap이됩니다.

ByteArrayOutputStreamcompress() 호출을 제거하십시오. 사용하지 않는 메모리를 할당하는 것뿐입니다.