Android rgb 转bitmap
来源:互联网 发布:ica负熵的迭代算法 编辑:程序博客网 时间:2024/05/18 03:30
Android rgb转bitmap
int width = 11; int height = 8; Integer r[][]={ {000,000,255,000,000,000,000,000,255,000,000}, {000,000,000,255,000,000,000,255,000,000,000}, {000,000,255,255,255,255,255,255,255,000,000}, {000,255,255,255,255,255,255,255,255,255,000}, {255,255,255,255,255,255,255,255,255,255,255}, {255,000,255,255,255,255,255,255,255,000,255}, {255,000,255,000,000,000,000,000,255,000,255}, {000,000,000,255,255,000,255,255,000,000,000}}; Integer g[][]={ {000,000,255,000,000,000,000,000,255,000,000}, {000,000,000,255,000,000,000,255,000,000,000}, {000,000,255,255,255,255,255,255,255,000,000}, {000,255,255,000,255,255,255,000,255,255,000}, {255,255,255,255,255,255,255,255,255,255,255}, {255,000,255,255,255,255,255,255,255,000,255}, {255,000,255,000,000,000,000,000,255,000,255}, {000,000,000,255,255,000,255,255,000,000,000}}; Integer b[][]={ {000,000,255,000,000,000,000,000,255,000,000}, {000,000,000,255,000,000,000,255,000,000,000}, {000,000,255,255,255,255,255,255,255,000,000}, {000,255,255,000,255,255,255,000,255,255,000}, {255,255,255,255,255,255,255,255,255,255,255}, {255,000,255,255,255,255,255,255,255,000,255}, {255,000,255,000,000,000,000,000,255,000,255}, {000,000,000,255,255,000,255,255,000,000,000}};//char* rgba = (char*)malloc(width*height*4); int[] pixels=new int[width*height*4]; int offset=0; int alpha = 0xFF << 24; for(int i=0; i < height; ++i) { for (int j=0; j < width; j++) {//这个会放大四倍
pixels[4*offset] = r[i][j]; pixels[4*offset+1] = g[i][j]; pixels[4*offset+2] = b[i][j].byteValue(); pixels[4*offset+3] = 0; offset ++;//这个计算的不对 // int grey =(r[i][j] & 0x00FF0000)>> 16 + (g[i][j] & 0x0000FF00) >> 8 +b[i][j]& 0x000000FF;// grey = alpha | (grey << 16) | (grey << 8) | grey;// pixels[width * i + j] = grey;这个能出图 pixels[width * i + j] = 0xFF << 24 | r[i][j] << 16| g[i][j] << 8 | b[i][j];}
}//失败// Bitmap bmp = Bitmap.createBitmap(pixels, 0, width, width, height,// Bitmap.Config.ARGB_8888);//成功,但是图好像不对sonarBitmap =new MyBitmap().createMyBitmap(pixels,width,height);
//成功
sonarBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
sonarBitmap.setPixels(pixels, 0, width, 0, 0, width, height);
// sonarBitmap=result;// createBimap(result); sonarImage.setImageBitmap(sonarBitmap);public class MyBitmap{ public Bitmap createMyBitmap(int[] data, int width, int height){ int []colors = convertByteToColor(data); if (colors == null){ return null; } Bitmap bmp = Bitmap.createBitmap(colors, 0, width, width, height, Bitmap.Config.ARGB_8888); return bmp; } // 将一个byte数转成int// 实现这个函数的目的是为了将byte数当成无符号的变量去转化成int public int convertByteToInt(int data){ int heightBit = (int) ((data>>4) & 0x0F); int lowBit = (int) (0x0F & data); return heightBit * 16 + lowBit; } // 将纯RGB数据数组转化成int像素数组 public int[] convertByteToColor(int[] data){ int size = data.length; if (size == 0){ return null; } int arg = 0; if (size % 3 != 0){ arg = 1; } // 一般情况下data数组的长度应该是3的倍数,这里做个兼容,多余的RGB数据用黑色0XFF000000填充 int []color = new int[size / 3 + arg]; int red, green, blue; if (arg == 0){ for(int i = 0; i < color.length; ++i){ red = convertByteToInt(data[i * 3]); green = convertByteToInt(data[i * 3 + 1]); blue = convertByteToInt(data[i * 3 + 2]); // 获取RGB分量值通过按位或生成int的像素值 color[i] = (red << 16) | (green << 8) | blue | 0xFF000000; } }else{ for(int i = 0; i < color.length - 1; ++i){ red = convertByteToInt(data[i * 3]); green = convertByteToInt(data[i * 3 + 1]); blue = convertByteToInt(data[i * 3 + 2]); color[i] = (red << 16) | (green << 8) | blue | 0xFF000000; } color[color.length - 1] = 0xFF000000; } return color; } }
阅读全文
0 0
- Android rgb 转bitmap
- android bitmap 中RGB
- RGB转bitmap byteToInt
- ffmpeg 转 RGB 填充 bitmap
- android中 bitmap 获取像素的RGB
- android中 bitmap 获取像素的RGB
- Android 修改Bitmap图片像素的信息 RGB颜色值
- RGB数据转换Bitmap
- opengles RGB数组及Android Bitmap中int color[] RGB存储顺序
- android YUV转RGB
- android ARGB 转 RGB
- RGB转化成bitmap格式
- RGB和Bitmap互相转换
- android Drawable转Bitmap| Bitmap转byte[]
- android bitmap转image
- Android Bitmap转Drawable
- Android Drawable 转Bitmap
- android view转bitmap
- css画图案
- SimPHP框架介绍
- app接口安全性设计浅析
- 第一章
- windows dos操作命令
- Android rgb 转bitmap
- spmi_get_resource
- 三种常见字符编码简介:ASCII、Unicode和UTF-8
- mybatis dao层执行sql时,方法执行后没有任何反应
- 迭代、循环和遍历的区别
- ADB 搜索文件
- 微型 Python Web 框架: Bottle
- 关于Git忽略文件
- Unity3d 鼠标点住物体拖动物体