2013-04-18 2 views
0

나는 C++과 Java 양쪽 모두에서 조작해야하는 비트 맵을 가지고있다. 따라서, this 게시물에 따라 나는 C++로 버퍼를 할당하고 참조를 Java에 전달했습니다. 자바에서는 copyPixelsToBuffer 메서드를 사용하여 비트 맵에서 버퍼를 채 웁니다. 해당 버퍼에서 임의의 조작없이 비트 맵을 만들려고하면 decodeByteArray이 null을 반환했습니다. 그리고 나는 내 잘못이 무엇인지 이해하지 못한다. 내가 사용한 코드 아래.네이티브 버퍼를 할당하고 JAVA에서 사용 하시겠습니까?

BitmapFactory.Options options = new BitmapFactory.Options(); 
    options.inPreferredConfig = Bitmap.Config.ARGB_8888; 
    mCurrentBitmap = BitmapFactory.decodeFile(hardCodedPath, options); 

    // 4- bytes count per pixel 
    bytesCount = mCurrentBitmap.getWidth() * mCurrentBitmap.getHeight() * 4; 

    pixels = (ByteBuffer) allocNativeBuffer(bytesCount); 
    pixels.order(ByteOrder.nativeOrder()); 

    mCurrentBitmap.copyPixelsToBuffer(pixels); 
    pixels.flip(); 
    pixels.order(ByteOrder.BIG_ENDIAN); 
    byte[] bitmapdata = new byte[pixels.remaining()]; 

    pixels.get(bitmapdata); 

    BitmapFactory.Options opt = new BitmapFactory.Options(); 
    opt.inDither = true; 
    opt.inPreferredConfig = Bitmap.Config.ARGB_8888; 

    Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapdata, 0, bitmapdata.length, opt); 

모든 의견 및 제안을 부탁드립니다.

답변

0

내가 어떻게하는지.

ByteBuffer mPixels = ByteBuffer.allocateDirect( saveWidth*saveHeight*4).order(ByteOrder.nativeOrder()); GLES20.glReadPixels(0, 0, mWidth, mHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, mPixels);

resultBitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); 
resultBitmap.copyPixelsFromBuffer(mPixels); 

관련 문제