数据是raw数据,里面存储的数据格式和你要转换的格式不一样,我是转成ARGB_8888格式的,贴上我处理的代码获取屏幕大小:
DisplayMetrics metrics =new DisplayMetrics();
WindowManager WM = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
Display display = WM.getDefaultDisplay();
display.getMetrics(metrics);
int height = metrics.heightPixels; //屏幕高
int width = metrics.widthPixels; //屏幕的宽
// 获取显示方式
int pixelformat = display.getPixelFormat();
PixelFormat localPixelFormat1 =new PixelFormat();
PixelFormat.getPixelFormatInfo(pixelformat, localPixelFormat1);
int deepth = localPixelFormat1.bytesPerPixel;//位深
InputStream stream =getInputStream();
byte[] piex = new byte[height * width * deepth];
DataInputStream dStream = new DataInputStream(stream);
int i=0;
while(dStream.read(piex, 0, height * width * deepth) != -1){
// 保存图片
int[] colors = new int[height * width];
for(int m=0;m<piex.length;m++){
if(m%4 == 0){
int r = (piex[m] & 0xFF);
int g = (piex[m+1] & 0xFF);
int b = (piex[m+2] & 0xFF);
int a = (piex[m+3] & 0xFF);
colors[m/4]= (a << 24) + (r <<16) + (g <<8) + b;
}
}
// piex生成bitmap
Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888);
// bitmap保存为png格式:
FileOutputStream out = new FileOutputStream("/mnt/sdcard/test"+x+".png");
bitmap.compress(Bitmap.CompressFormat.PNG, 100,out);
DisplayMetrics metrics =new DisplayMetrics();
WindowManager WM = (WindowManager)this.getSystemService(Context.WINDOW_SERVICE);
Display display = WM.getDefaultDisplay();
display.getMetrics(metrics);
int height = metrics.heightPixels; //屏幕高
int width = metrics.widthPixels; //屏幕的宽
// 获取显示方式
int pixelformat = display.getPixelFormat();
PixelFormat localPixelFormat1 =new PixelFormat();
PixelFormat.getPixelFormatInfo(pixelformat, localPixelFormat1);
int deepth = localPixelFormat1.bytesPerPixel;//位深
InputStream stream =getInputStream();
byte[] piex = new byte[height * width * deepth];
DataInputStream dStream = new DataInputStream(stream);
int i=0;
while(dStream.read(piex, 0, height * width * deepth) != -1){
// 保存图片
int[] colors = new int[height * width];
for(int m=0;m<piex.length;m++){
if(m%4 == 0){
int r = (piex[m] & 0xFF);
int g = (piex[m+1] & 0xFF);
int b = (piex[m+2] & 0xFF);
int a = (piex[m+3] & 0xFF);
colors[m/4]= (a << 24) + (r <<16) + (g <<8) + b;
}
}
// piex生成bitmap
Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888);
// bitmap保存为png格式:
FileOutputStream out = new FileOutputStream("/mnt/sdcard/test"+x+".png");
bitmap.compress(Bitmap.CompressFormat.PNG, 100,out);
解决方案 »
- 新手请教简单的android问题,请指教 谢谢哈
- 如何获取发出去的短信内容
- 怎么将数据库获取的数据显示在Spinner中
- linux和windows平台下,如何下载android sdk的源代码(转)
- 保存数组到数据库
- 关于aidl的问题???????
- android 音频传输问题
- 在android 2.1模拟器中无法输入&,*,(等字符!
- android sata 文件系统
- 关于android手机浏览器的若干疑问
- android opengl GLSurfaceView背景透明问题
- 编译出错:undefined reference to 'JNI_GetCreatedJavaVMs',请大侠帮忙
要是黑屏的话,自己试试换换每个值的位置,或者可以用纯的red等颜色来测试 哪个位置存的是r值
)