2013-11-01 3 views
5

Hello StackOverflow 커뮤니티. 작은 조각으로 비트 맵을 나눌 수있는 가능한 방법에 대한 정보가 필요합니다. 더 중요한 것은 내가 판단 할 옵션이 필요하다는 것입니다. 나는 많은 지위를 점검했고, 나는 여전히 무엇을해야하는지에 대해 완전히 확신하지 못했다. 비트 맵을 비트 맵으로 나누는 방법도

How do I cut out the middle area of ​​the bitmap?

이 두 링크

cut the portion of bitmap

내가 찾은 좋은 옵션입니다,하지만 난 각 방법의 CPU와 RAM 비용을 계산하지 못할, 아니면 내가 모든이 계산 신경 쓰지한다. 그럼에도 불구하고 내가 무엇인가하려고한다면, 처음부터 최선의 방법을 시도해보십시오.

비트 맵 압축에 대한 몇 가지 팁과 링크를 얻게되어 감사하게 생각하고 두 가지 방법을 결합하여 더 나은 성능을 얻을 수 있습니다.

미리 감사드립니다.

답변

3

비트 맵을 부분으로 나누고 싶습니다. 비트 맵에서 동일한 부분을 잘라 내고 싶다고 가정합니다. 예를 들어 비트 맵에서 4 등분이 필요합니다.

비트 맵을 4 등분으로 나누고 비트 맵 배열을 사용하는 방법입니다.

public Bitmap[] splitBitmap(Bitmap picture) 
{ 

Bitmap[] imgs = new Bitmap[4]; 
imgs[0] = Bitmap.createBitmap(picture, 0, 0, picture.getWidth()/2 , picture.getHeight()/2); 
imgs[1] = Bitmap.createBitmap(picture, picture.getWidth()/2, 0, picture.getWidth()/2, picture.getHeight()/2); 
imgs[2] = Bitmap.createBitmap(picture,0, picture.getHeight()/2, picture.getWidth()/2,picture.getHeight()/2); 
imgs[3] = Bitmap.createBitmap(picture, picture.getWidth()/2, picture.getHeight()/2, picture.getWidth()/2, picture.getHeight()/2); 

return imgs; 


} 
4

이 기능을 사용하면 비트 맵을 행과 열의 수로 나눌 수 있습니다.

예제 Bitmap [] [] bitmaps = splitBitmap (bmp, 2, 1); 2 차원 배열로 저장된 수직으로 분할 된 비트 맵을 생성합니다. 2 열 1 행

예제 Bitmap [] [] bitmaps = splitBitmap (bmp, 2, 2); 비트 맵을 2 차원 배열로 저장된 4 개의 비트 맵으로 분할합니다. 2 열 2 행

public Bitmap[][] splitBitmap(Bitmap bitmap, int xCount, int yCount) { 
    // Allocate a two dimensional array to hold the individual images. 
    Bitmap[][] bitmaps = new Bitmap[xCount][yCount]; 
    int width, height; 
    // Divide the original bitmap width by the desired vertical column count 
    width = bitmap.getWidth()/xCount; 
    // Divide the original bitmap height by the desired horizontal row count 
    height = bitmap.getHeight()/yCount; 
    // Loop the array and create bitmaps for each coordinate 
    for(int x = 0; x < xCount; ++x) { 
     for(int y = 0; y < yCount; ++y) { 
      // Create the sliced bitmap 
      bitmaps[x][y] = Bitmap.createBitmap(bitmap, x * width, y * height, width, height); 
     } 
    } 
    // Return the array 
    return bitmaps;  
} 
+1

대답 할 때 코드를 설명하기보다는 설명을 시도해야합니다. – ThP

+0

앞으로 답장을 보내실 텍스트로 답하십시오. –

관련 문제