현재 루팅된 갤럭시 S4를 가지고 화면 캡쳐 하는것을 하고있습니다.
http://blog.daum.net/green7night/23
에서 좋은 내용을 얻어 작업중인데
본코드를 적용해서 비트맵 객체를 얻으면 빈파일만 받아옵니다. 소스코드 첨부합니다
C
#include <string.h>
#include <jni.h>
#include <stdio.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <asm/page.h>
#include <unistd.h>
JNIEXPORT jint
Java_com_rgb_RectActivity_getFrameBuffer( JNIEnv* env,
jobject thiz,
jbyteArray jByte)
{
int WIDTH = 1080;
int HEIGHT = 1920;
int BYTE_PER_PIXEL = 4;
int SCREEN_NUM = 1; // 화면 갯수
const int READ_BYTE = WIDTH * HEIGHT * BYTE_PER_PIXEL * SCREEN_NUM;
// open fb0
int fp= open("/dev/graphics/fb0", O_RDONLY);
if(fp<0)
{
return errno;
}
// get pointer
unsigned short * pFrame=NULL;
pFrame = mmap(0, READ_BYTE, PROT_READ, MAP_SHARED, fp,0 );
if( pFrame==MAP_FAILED )
{
close(fp);
return errno;
}
// set buffer
(*env)->SetByteArrayRegion(env, jByte, 0, READ_BYTE, (jbyte*)pFrame );
munmap(pFrame,READ_BYTE);
close(fp);
return 0;
}
Java
private void getScreen(){
// get frame buffer
int WIDTH = 1080;
int HEIGHT = 1920;
int BYTE_PER_PIXEL = 4;
int SCREEN_NUM = 1; // 화면 갯수
int size = WIDTH * HEIGHT * BYTE_PER_PIXEL * SCREEN_NUM;
byte[] buffer = new byte[size];
// crate bitmap
BitmapFactory.Options bfo = new BitmapFactory.Options();
bfo.inPreferredConfig = Bitmap.Config.ARGB_8888;
bfo.outWidth = WIDTH;
bfo.outHeight = HEIGHT;
bitmap1 = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
// bitmap2 = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.RGB_565);
int ret = getFrameBuffer(buffer);
if (ret != 0) {
// 에러
bitmap1.eraseColor(Color.RED);
// bitmap2.eraseColor(Color.RED);
Log.e("kjw", "error = "+ret);
return;
}
// copy to bitmap
ByteBuffer BB = ByteBuffer.allocate(size/SCREEN_NUM);
// 화면 1 그림
BB.put(buffer, 0, size / SCREEN_NUM);
BB.rewind();
bitmap1.copyPixelsFromBuffer(BB);
FileOutputStream fos;
try
{
fos = new FileOutputStream(Config.PICTURE_FILE_DIR + "i.jpg");
bitmap1.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
Log.d("kjw", "222");
}
보시는바와같이
캡쳐된 비트맵파일을 파일로쓰고 이미지뷰에 바로 적용하거나 해봐도
투명된 이미지로밖에 받아올수가 없습니다.
이게 왜이런건지 알고싶어 질문글올립니다..
답변 부탁드려요!