Android RGB565颜色byte数组转图片

来源:互联网 发布:ubuntu默认密码环 编辑:程序博客网 时间:2024/06/05 03:36

RGB565数据转图片方法如下


    /**     * RGB 565图片颜色数组封装成图片     * @param data          颜色数组     * @param height        高度     * @param width         宽度     * @return     */    public static Bitmap getOriginalBitmap(byte[] data, int height, int width) {        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);        ByteBuffer buffer = ByteBuffer.wrap(data);        bitmap.copyPixelsFromBuffer(buffer);        return bitmap;    }

由于硬件拍照局限性的问题,接收的数据长宽其实是翻转,可参考使用Camera类拍照获取到图片,而且前后摄像头翻转的角度不一致,主摄像头翻转角度一般为-90度,所以还需要把得到的图片翻转回来。

   /**     * 旋转照片     *     * @param bitmap     * @param degress  翻转角度     * @return     */    public static Bitmap rotateBitmap(Bitmap bitmap, int degress) {        if (bitmap != null) {            Matrix m = new Matrix();            m.postRotate(degress);            bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),                    bitmap.getHeight(), m, true);            return bitmap;        }        return bitmap;    }


0 0