天嵌 ARM开发社区

 找回密码
 注册
查看: 2592|回复: 2

ANDROID ov9650 數據格式 是RGB565??

[复制链接]
hayvane 发表于 2013-8-14 14:48:30 | 显示全部楼层 |阅读模式
如題。
我在應用層 通過 public void onPreviewFrame(byte[] data, Camera camera){},中data 的數據格式是 565的?
如何保存將這byte[] data  數據保存爲圖片呢?
wbz073 发表于 2013-8-14 17:49:50 | 显示全部楼层
数据格式客户是可以自己设的,不一定是RGB565.
 楼主| hayvane 发表于 2013-8-15 09:55:34 | 显示全部楼层
wbz073 发表于 2013-8-14 17:49
数据格式客户是可以自己设的,不一定是RGB565.

現在的數據格式已經是RGB565了。那 public void onPreviewFrame(byte[] data, Camera camera){}中能否用byte[] data 保存爲圖片呢?
我都方法是將 rgb555的數據轉換成 ARGB888,再保存,但是保存都圖片失真很嚴重!附代碼:
  1. int tmpColor[] = new int[width*height];
  2.       for(int j=0; j<width*height;j++){
  3.           int tmpint = data[j*2+0]+data[j*2+1]*256;
  4.           int a = 0xff;
  5.           int r = (tmpint & 0xf800) >> 11;
  6.           int g = (tmpint & 0x07e0) >> 5;
  7.           int b = (tmpint & 0x001f);
  8.          
  9.           r  = r << 3;
  10.           g  = g << 2 ;
  11.           b  = b << 3;
  12.           tmpColor[j] = (a << 24) | (r << 16) | (g << 8) | (b);
  13.       }

  14. Bitmap bmp = Bitmap.createBitmap(width, height,
  15.                       Bitmap.Config.ARGB_8888);
  16.                bmp.setPixels(tmpColor, 0, width, 0, 0, width, height);
  17.                String bmpName = "t.jpg";
  18.                String path =  "/scan_test";
  19.                System.out.println("########### path = " + path);
  20.                 // 文件目录
  21.                File root = new File(path);
  22.                if (!root.isDirectory() || !root.exists()) {
  23.                    root.mkdirs();
  24.                }
  25.                File myCaptureFile = new File(path, bmpName);
  26.                try {
  27.                    myCaptureFile.createNewFile();
  28.                } catch (IOException e1) {
  29.                    // TODO Auto-generated catch block
  30.                    e1.printStackTrace();
  31.                }
  32.                try {
  33.                    BufferedOutputStream bos = new BufferedOutputStream(
  34.                           new FileOutputStream(myCaptureFile));
  35.                    // 采用压缩转档方法
  36.                    bmp.compress(Bitmap.CompressFormat.JPEG, 100, bos);
  37.                    bos.flush();
  38.                    bos.close();
  39.          
  40.                } catch (Exception e) {
  41.                    myCaptureFile.delete();                              
  42.                }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-5-18 13:38 , Processed in 1.046875 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表