rgba

Determine RGBA colour received by combining two colours

不打扰是莪最后的温柔 提交于 2019-11-26 21:37:25
问题 I have two colours defined as RGBA (in my specific examples, one of the set is [white with alpha 0.85] and [57, 40, 28 with alpha 0.25]. The second colour is drawn over the first one (i.e. white with alpha is the background and the second colour is used for drawing). How can I figure out what the RGBA colour of the combination is going to be? I need to do this one-off - so any tools is fine (e.g. I'm happy to draw something in photoshop and see what comes out). I have several sets to combine,

Convert RGB to RGBA over white

泄露秘密 提交于 2019-11-26 21:14:08
I have a hex color, e.g. #F4F8FB (or rgb(244, 248, 251) ) that I want converted into an as-transparent-as-possible rgba color (when displayed over white). Make sense? I'm looking for an algorithm, or at least idea of an algorithm for how to do so. For Example: rgb( 128, 128, 255 ) --> rgba( 0, 0, 255, .5 ) rgb( 152, 177, 202 ) --> rgba( 50, 100, 150, .5 ) // can be better(lower alpha) Ideas? FYI solution based on Guffa's answer: function RGBtoRGBA(r, g, b){ if((g == null) && (typeof r === 'string')){ var hex = r.replace(/^\s*#|\s*$/g, ''); if(hex.length === 3){ hex = hex.replace(/(.)/g, '$1$1'

CSS hexadecimal RGBA?

て烟熏妆下的殇ゞ 提交于 2019-11-26 18:42:25
I know you can write ... background-color: #ff0000; ... if you want something that is red. And you can write ... background-color: rgba(255, 0, 0, 0.5); ... if you want something red and translucent. Is there any terse way of writing partially transparent colors in hexadecimal? I want something like: background-color: #ff000088; <--- the 88 is the alpha ... or ... background-color: #ff0000 50%; I am getting all my colors in hexadecimal, and having to convert them all to the decimal 0-255 scale is annoying. James Donnelly The CSS Color Module Level 4 will probably support 4 and 8-digit

Convert RGBA PNG to RGB with PIL

故事扮演 提交于 2019-11-26 18:12:49
I'm using PIL to convert a transparent PNG image uploaded with Django to a JPG file. The output looks broken. Source file Code Image.open(object.logo.path).save('/tmp/output.jpg', 'JPEG') or Image.open(object.logo.path).convert('RGB').save('/tmp/output.png') Result Both ways, the resulting image looks like this: Is there a way to fix this? I'd like to have white background where the transparent background used to be. Solution Thanks to the great answers, I've come up with the following function collection: import Image import numpy as np def alpha_to_color(image, color=(255, 255, 255)): """Set

How can I stop the alpha-premultiplication with canvas imageData?

六月ゝ 毕业季﹏ 提交于 2019-11-26 14:17:47
问题 Is there a way to stop the premultiplication of the alpha channel for canvas data, or a workaround? I want to generate an image (in this case some random rgba values) and save the canvas as an image. During the second step, I want to compare the original image with the generated image using the imageData, however this won't work due to the premultiplication of the alpha channel of my rgba pixels in the generated image. The example function drawImage(ctx) { var img = ctx.createImageData(canvas

【原创】Javascript实现Web颜色值转换

老子叫甜甜 提交于 2019-11-26 14:17:22
最近一直忙碌于完成业务需求,好长时间没有写博客了。今天稍微有些时间,翻看了一下最近项目中的一些前端代码,看到Web颜色转换功能的时候,突然想到当我们在做一些颜色设置/编辑的需求时,经常会涉及到各种颜色值格式的互换。于是我决定记录一下我在做这一部分功能的时候是如何实现的,写下来和大家分享一下,希望读者们各抒己见,多多交流。 先看看问题 问题一,当我们在进行网页前端开发的时候,经常会使用 dom.style.backgroundColor = "#f00" 来设置某个 DOM 元素的背景颜色,也会通过类似(为什么是类似?情况比较多,这里可以自由发挥想象) var bgc = dom.style.backgroundColor 的代码来获取某个 DOM 元素的背景颜色。那么问题来了,请看下图: 如果这里的对比还不够明显,我们再继续往下看: 很显然,同一个颜色值,本来应该相等,但结果却并非如此。而这并非个例,笔者在Chrome开发工具和Firefox控制台,得到的结果是一致的。 问题二,前端开发工作,往往是从还原UI设计稿开始。而在编码过程中我们经常会发现这样的设计:某个盒子背景纯色(假设:#f00),但带有 75% 的不透明度。很显然,这种情况我们不能简单的通过 dom.style.backgroundColor = "#f00" 来设置,因为达不到半透明的效果。话锋回转,我们知道

Is it possible to change only the alpha of a rgba background colour on hover?

蓝咒 提交于 2019-11-26 14:10:08
问题 I have a set of <a> tags with differing rgba background colours but the same alpha. Is it possible to write a single css style that will change only the opacity of the rgba attribute? A quick example of the code: <a href="#"><img src="" /><div class="brown">Link 1</div></a> <a href="#"><img src="" /><div class="green">Link 2</div></a> And the styles a {display: block; position: relative} .brown {position: absolute; bottom: 0; background-color: rgba(118,76,41,.8);} .green {position: absolute;

Convert RGB to RGBA over white

时间秒杀一切 提交于 2019-11-26 12:15:34
问题 I have a hex color, e.g. #F4F8FB (or rgb(244, 248, 251) ) that I want converted into an as-transparent-as-possible rgba color (when displayed over white). Make sense? I\'m looking for an algorithm, or at least idea of an algorithm for how to do so. For Example: rgb( 128, 128, 255 ) --> rgba( 0, 0, 255, .5 ) rgb( 152, 177, 202 ) --> rgba( 50, 100, 150, .5 ) // can be better(lower alpha) Ideas? FYI solution based on Guffa\'s answer: function RGBtoRGBA(r, g, b){ if((g == null) && (typeof r === \

Overlay a background-image with an rgba background-color

我的梦境 提交于 2019-11-26 09:29:46
问题 I have a div with a background-image . I want to overlay the background-image with an rgba color ( rgba(0,0,0,0.1) ) when the user hovers the div. I was wondering if there\'s a one-div solution (i.e. not with multiple divs, one for the image and one for the color, etc.). I tried multiple things: <div class=\"the-div\" id=\"test-1\"></div> <div class=\"the-div\" id=\"test-2\"></div> <div class=\"the-div\" id=\"test-3\"></div> And this CSS: .the-div { background-image: url(\'the-image\');

OpenCV Android Green Color Detection

别来无恙 提交于 2019-11-26 08:26:43
问题 currently I\'m making an app where user will detect green colors. I use this photo for testing: My problem is that I can not detect any green pixel. Before I worked with blue color and everything worked fine. Now I can\'t detect anything though I tried different combinations of RGB . I wanted to know whether it\'s problem with green or my detection range, so I made an image in paint using (0, 255, 0) and it worked. Why it can\'t see this circle then? I use this code for detection: Core