------ Solution ---------------------------------------- ----
data is raw data , which is stored in the data format and the format you want to convert is not the same , I was transformed into ARGB_8888 format , paste the code I deal
获取屏幕大小:
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);
------ reference ------------------------------------- -
er er. . Yes, I try . Thank you . . Sorry, did not reply for a long time , most recently in other busy . . Oh . .
------ reference --------------------------------------- < br>
landlord realized it, I get is a black screen , seeking guidance
------ reference ------------------- --------------------
I get is a black screen. . . .
------ reference --------------------------------------- < br> colors [m / 4] = (a << 24) + (r << 16) + (g << 8) + b;
If a black screen , then try their own change of the position of each value , or you can use a pure red and other colors to test which position is maintained by the r value
------ reference - -------------------------------------
Why do I get the picture , mess , and is part of , part of , you can not get the whole screen
------ reference ----------------------------- ----------
Guixie landlord ah. . !
没有评论:
发表评论