android ARGB 转 RGB

转自:http://hxluo.blog.163.com/blog/static/1966022762013111766216/,感谢这位作者,因为在java代码当中利用调色板得到的是一串十六进制的,需要传入到js代码中,使用RGB的颜色值,找到如下文章:


首先ARGB区别于RGB的地方就是RGB色彩模式附加上Alpha(透明度)通道,常见于32位位图的存储结构。
RGB编码格式如下:
 RGB Red Green Blue
 共24bit 16-24bit 8-15bit 0-7bit

而ARGB则在RGB的基础上加了一个透明的通道
ARGB的编码格式:
 ARGB AlphaRed Green Blue
 共32bit 25-32bit 16-24bit 8-15bit 0-7bit
   
怎么转化相信大家很清楚了。
这里贴一个方法:
 Java Code 
1
2
3
4
5
6
7
8
public  static  int[] getArgb( int color){
     final  int a = (color >>>  24);
     final  int r = (color >>   16) & 0xFF;
     final  int g = (color >>    8) & 0xFF;
     final  int b = (color)        & 0xFF;

     return  new  int[]{ClippedColorPart(a), ClippedColorPart(r), ClippedColorPart(g), ClippedColorPart(b)};
}

也可以调用color的方法:android.graphics.Color;包
 Java Code 
1
2
3
red = Color.red(newARGBColor);
green = Color.green(newARGBColor);
blue = Color.blue(newARGBColor);
同样可以~
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android 中,使用 Camera API 获取的图像数据通常是以 YUV 格式传输的。要将 YUV 数据换为 RGB,可以使用以下方法: 1. 使用 Android 提供的 YUV 换工具类:YuvImage 和 BitmapFactory。这种方法的缺点是比较耗时,而且需要将 YUV 数据先换为 JPEG 或 PNG 格式,然后再换为 RGB。代码示例: ``` YuvImage yuvImage = new YuvImage(data, ImageFormat.NV21, width, height, null); ByteArrayOutputStream out = new ByteArrayOutputStream(); yuvImage.compressToJpeg(new Rect(0, 0, width, height), 50, out); byte[] imageBytes = out.toByteArray(); Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length); ``` 2. 使用 RenderScript 进行 YUV 换。RenderScript 是 Android 提供的高性能计算引擎,可以在 GPU 上进行并行计算,比 CPU 要快很多。代码示例: ``` RenderScript rs = RenderScript.create(context); ScriptIntrinsicYuvToRGB yuvToRgb = ScriptIntrinsicYuvToRGB.create(rs, Element.U8_4(rs)); Type.Builder yuvType = new Type.Builder(rs, Element.U8(rs)).setX(data.length); Allocation in = Allocation.createTyped(rs, yuvType.create(), Allocation.USAGE_SCRIPT); in.copyFrom(data); Type.Builder rgbaType = new Type.Builder(rs, Element.RGBA_8888(rs)).setX(width).setY(height); Allocation out = Allocation.createTyped(rs, rgbaType.create(), Allocation.USAGE_SCRIPT); yuvToRgb.setInput(in); yuvToRgb.forEach(out); Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); out.copyTo(bitmap); rs.destroy(); ``` 注意:以上代码示例中的参数 data 是 byte[] 类型的 YUV 数据,width 和 height 分别是图像宽度和高度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值