WindowManager.LayoutParams.MATCH_PARENT; content.addView(view, params); } 第二步:设置颜色的方法,由于要考虑透明度所以使用Color.argb r = (int) (129); // int g = (int) (116); // int b = (int) (38); return Color.argb
前言 有时会看到别人使用bitmap是用到ARGB_8888/RGB_565这类参数,那么这些参数是什么?对bitmap有什么影响? ARGB分别是alpha透明度和red、green、blue三色 ARGB_8888:分别用8位来记录4个值,所以每个像素会占用32位。 这里都以ARGB_8888为基准来进行对比。 ARGB_4444:内存占用减少一半,但是每个值图片失真度很严重,这个参数本身已经不推荐使用了。 ARGB_4444 首先,使用ARGB_4444发现内存没有变化,看看官方的解释 /** Each pixel is stored on 2 bytes. . **/ @Deprecated ARGB_4444 (4), 原来在KITKAT,即Android 19之后,这个参数就彻底无效了,只用这个参数会被默认替换为ARGB_8888,所以内存大小没有变化
背景 服务端下发的颜色值字符串由于一开始依据 iOS 端的 RGBA 格式,Android 端(Android 使用 ARGB 方式)需要进行兼容,需要对此字符串转换。 举例:RGBA #ABCDEF99 => ARGB #99ABCDEF 方式 ①字符串截取和组合 String argbStr = rgba.substring(0, 1) + rgba.substring = Color.parseColor(tempStr.toString()); ③位操作 int rgba = Color.parseColor(rgbaStr); int argb = (rgba 扩展:ARGB 转 RGBA 以下算法临时改写而成,未经实际产品应用,建议先跑一些测试用例进行验证。 // 1. 位操作 int argb = Color.parseColor(argbStr); int rgba = (argb << 8) | (argb >>> (32-8));
序 本文主要来聊一下使用ImageIO在BufferedImage.TYPE_INT_ARGB默认下操作jpg格式图片显示黑色的bug。 height = 400; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB doc Colors appear wrong in image file if image type is TYPE_INT_ARGB and writing with ImageIO jpeg image
Android布局中颜色表示都是使用十六进制来表示的,使用RGB和ARGB,后者多了一个透明度,而UI设计师通常在标注图中标注的透明度通常为百分比,这就需要我们做一些转换才能使用。
UI界面读取一张图片,鼠标选中一个position,计算出对应图片的像素坐标,传给c++ c++中读取图片地址,解析出*char数组,根据ARGB协议,解析出ARGB的值,传递给UI界面 在UI界面中解析 ARGB值,显示对应的颜色和16进制的字符串表示 bitmap 中每个像素的ARGB内存分布 因为大小端的缘故,和我们理解的ARGB的顺序相反,大小端读者有兴趣可以深入了解, 参考:https:// + 3]; argb[1] = srcData[pos + 2]; argb[2] = srcData[pos + 1]; argb[3] = srcData[pos + 0]; [4]; f_getPixel(data, w, h, stride, x, y, argb); QVariantList list; list<<argb[0]<<argb[1 ]<<argb[2]<<argb[3]; emit getPixDone(QVariant::fromValue(list)); } qml中接收信号,展示结果。
SmartPlayerSetFlipHorizontal(long handle, int is_flip);如果需要把快照数据按照设定角度旋转,通常的做法,可以在解码后的yuv数据先做旋转,然后再做argb 的转换,也可以转成argb后,针对argb旋转即可,旋转后的数据,再做png编码写入文件即可,以Libyuv为例(数据在jni层处理):如果需要旋转yuv数据,可用的接口如下:// Rotate I420 dst_stride_v, int width, int height, enum RotationMode mode);如果是ARGB 数据:// Rotate ARGB frameLIBYUV_APIint ARGBRotate(const uint8_t* src_argb, int src_stride_argb , uint8_t* dst_argb, int dst_stride_argb, int src_width,
), Allocation.USAGE_SCRIPT); final Bitmap bmpout = Bitmap.createBitmap(W, H, Bitmap.Config.ARGB
_4444 public static final Bitmap.Config ARGB_8888 public static final Bitmap.Config RGB_565 一看,有点蒙了 ,ALPHA_8, ARGB_4444,ARGB_8888,RGB_565 到底是什么呢? 说白了就ALPHA_8就是Alpha由8位组成 ARGB_4444就是由4个4位组成即16位, ARGB_8888就是由4个8位组成即32位, RGB_565就是R为5位,G为6位,B为5 位共16位 由此可见: ALPHA_8 代表8位Alpha位图 ARGB_4444 代表16位ARGB位图 ARGB_8888 代表32位ARGB位图 RGB_565 代表8位RGB位图 使用RGB_565会比使用ARGB_8888少消耗2倍的内存,很多时候默认是ARGB_8888,所以我们需要主动设置为RGB_565.
_4444 public static final Bitmap.Config ARGB_8888 public static final Bitmap.Config RGB_565 一看,有点蒙了 ,ALPHA_8, ARGB_4444,ARGB_8888,RGB_565 到底是什么呢? 说白了就ALPHA_8就是Alpha由8位组成 ARGB_4444就是由4个4位组成即16位, ARGB_8888就是由4个8位组成即32位, RGB_565就是R为5位,G为6位,B为5 位共16位 由此可见: ALPHA_8 代表8位Alpha位图 ARGB_4444 代表16位ARGB位图 ARGB_8888 代表32位ARGB位图 RGB_565 代表8位RGB位图 例子: Bitmap bg = Bitmap.createBitmap(width, height, Config.ARGB_8888);
转换思路 总体分为两步完成目标: 将plt或fig对象转为argb string的对象 将argb string对象图像转为array 或 Image 步骤一 区分对象为plt和fig的情况,具体使用哪种根据对象类型确定 转换plt对象为argb string编码对象 代码在plt对象中构建了图像内容,生成了plt图像,但还没有savefig 和 show: 例如: plt.figure() plt.imshow 图像 buf = np.fromstring(canvas.tostring_argb(), dtype=np.uint8) 转换fig对象为argb string编码对象 以 matplotlab w, h = fig.canvas.get_width_height() # 获取 argb 图像 buf = np.fromstring(fig.canvas.tostring_argb(), dtype =np.uint8) 步骤二 转换argb string编码对象为PIL.Image或numpy.array图像 此时的argb string不是我们常见的uint8 w h rgb的图像,还需要进一步转化
} } return Bitmap.createBitmap(bitArr, width, height, Bitmap.Config.ARGB * @return */ public static Bitmap getTransAlphaBitmap(Bitmap sourceImg) { int[] argb (), 0, 0, sourceImg .getWidth(), sourceImg.getHeight());// 获得图片的ARGB值 //number [i] = ((int) alpha << 24) | (argb[i] & 0x00FFFFFF); } sourceImg = Bitmap.createBitmap (argb, sourceImg.getWidth(), sourceImg .getHeight(), Bitmap.Config.ARGB_8888);
<item name="wire_default" type_name="gh_drawing_color" type_code="36"> <ARGB>115;0;255;255</ARGB> < /item> <item name="wire_empty" type_name="gh_drawing_color" type_code="36"> <ARGB>180;255;60;0</ARGB ;40</ARGB> </item> <item name="wire_selected_b" type_name="gh_drawing_color" type_code="36"> <ARGB> :【选择a端口时的颜色】 wire_selected_b:【选择b端口时的颜色】 而ARGB则代表Alpha透明度和RGB三个通道组成的颜色值。 简单来说就是改ARGB就完事儿了,直接改然后保存或者用改过的xml替换原文件即可。 喜欢我的配色的朋友,可以在公众号后台回复:Grasshopper GUI ,即可获得我的GUI配置。
首先感谢ST终于推出了ARGB格式的emWin库,可谓千呼万唤始出来,使用STM32的硬件RGB888接口刷新图片慢的问题终于得到解决。 2. 实际测试中发现,将F429配置为16位色的RGB565,刷新800*480分辨率的图片可以做到15ms左右一帧,而测试24位色的RGB888或者32位色的ARGB8888,竟然需要200多ms。 后来经过多次测试,才找到根本原因,因为大部分时间都损耗在ARGB和ABGR格式转换上了。使用ARGB格式库后,刷800*480大小的图片可以做到20ms一帧。 3. 近期,ST新发布的STemWin 5.40版本中加入了ARGB格式的库,这个问题得到了解决,本次专题就是为大家讲解如何使用这个库,替换时有很多需要注意的地方。 4. mod=viewthread&tid=23687 ================================ 使用32位色ARGB8888或者24位色RGB888的好处就是显示效果细腻,看下面效果图
字节数据 ; int var1 : ARGB 字节数据字节个数 ; int[] var3 : 图像宽度 , 传入的是数组 , 只有 1 个元素 , 作为返回值使用 ; int[] var4 : 图像高度 ByteArray 转为 IntArray var data_argb_int = IntArray(data_argb_byte.size / 4) // 使用 nio // 将 ARGB 数据转为 Bitmap 位图图像 var bitmap: Bitmap = Bitmap.createBitmap( data_argb_int : ByteArray 转为 IntArray var data_argb_int = IntArray(data_argb_byte.size / 4) // 使用 nio // 将 ARGB 数据转为 Bitmap 位图图像 var bitmap: Bitmap = Bitmap.createBitmap( data_argb_int
,不像 android 可以直接加载十六进制色值 我在国外论坛上,看到大佬的一种写法,感觉很有用,这里分享给大家 二、实现 下面我将逐步提出几种方案,一步步优化,知道最后可以直接使用:UIColor(argb / 255.0, alpha: CGFloat(a) / 255.0 ) } // let's suppose alpha is the first component (ARGB ) convenience init(argb: Int) { self.init( red: (argb >> 16) & 0xFF, green: (argb >> 8) & 0xFF, blue: argb & 0xFF, a: (argb >> 24) & 0xFF ) } 使用时示例代码如下: let color = UIColor(red: 0xFF, green: 0xFF, blue: 0xFF, a: 0xFF) let color2 = UIColor(argb: 0xFFFFFFFF) 总结 综上所述
720P 1080P 2K 4K 8K (6818开发板屏幕分辨率:800*480) 3.色彩深度: RGB:24位 (6818开发板屏幕色深aRGB:32位=24位RGB+8位灰度) 开发板LCD 把大象塞进去 ——》将像素点写入到LCD中 int color_red = 0x00FF0000; // 纯红色16进制表示aRGB int color_green = 0x0000FF00; // 纯绿色16进制表示aRGB int color_blue = 0x000000FF; // 纯蓝色16进制表示aRGB int x, y; while(1) { lseek(lcd_fd // 纯绿色16进制表示aRGB int color_blue = 0x000000FF; // 纯蓝色16进制表示aRGB int x, y; while(1) { for(y=0; // 纯红色16进制表示aRGB int color_blue = 0x000000FF; // 纯蓝色16进制表示aRGB int x, y; for(y=0; y<480/3; y++)
TolyCV.java]---- public class TolyCV { public static native int faceDetector(Bitmap bitmap, Bitmap.Config argb8888 , String path); public static native Bitmap faceDetectorResize(Bitmap bitmap, Bitmap.Config argb8888 /在srcMat上画矩形 env->ReleaseStringUTFChars(path_, path);//释放指针 return createBitmap(env,srcMat,argb8888 );//返回图片 } ---- 裁剪是非常简单的 createBitmap(env,srcMat(zone),argb8888);//返回图片 ? resize(srcMat(zone),srcMat,Size(width,height));//<----重定义尺寸 return createBitmap(env,srcMat,argb8888
(int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { a = (argb [index] & 0xff000000) >> 24; // a is not used obviously R = (argb[index] & 0xff0000) >> 16; G = (argb[index] & 0xff00) >> 8; B = (argb[index] & 0xff) >> 0 [index] & 0xff000000) >> 24; // a is not used obviously R = (argb[index] & 0xff0000) >> 16; G = (argb[index] & 0xff00) >> 8; B = (argb[index] & 0xff) >> 0
public class HebutHappyBirthday { public BufferedImage hebutImg; public static int rgb2gray(int argb ) { int alpha = (argb >> 24) & 0xFF; int red = (argb >> 16) & 0xFF; int green = (argb >> 8) & 0xFF ; int blue = argb & 0xFF; return (int)(0.3*red + 0.59*green + 0.11*blue); } public static int