android 中保存bgra数据为jpg文件


    

       private int videoWidth = 640;
       private int videoHeight = 480;
       private byte[] bgraData = null;
       private int number = 0;


       number++;
       if(bgraData == null) {
            bgraData = new byte[width*height*4];
            System.arraycopy(data, 0, bgraData, 0, width*height*4);
         } else {
            System.arraycopy(data, 0, bgraData, 0, width*height*4);
         }

         Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
         ByteBuffer buf = ByteBuffer.wrap(bgraData);
         bitmap.copyPixelsFromBuffer(buf);
         int n = number;
         String strFileName = "out" + n + ".jpg";

         File file=new File(Environment.getExternalStorageDirectory(), strFileName);
         try {
             FileOutputStream fos = new FileOutputStream(file);
             bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
             fos.flush();
             fos.close();
         } catch (FileNotFoundException e) {
             e.printStackTrace();
         } catch (IOException e) {
             e.printStackTrace();
         }

你可能感兴趣的:(android 中保存bgra数据为jpg文件)