简体   繁体   English

图像中的透明背景颜色

[英]Transparent background color in image

How can I delete or make transparent a specific background color in an image or backgroundimage?如何删除图像或背景图像中的特定背景颜色或使其透明 For example, I have an image and I want remove all the white pixels in it to show what is "behind" them on the page.例如,我有一个图像,我想删除其中的所有白色像素以显示页面上它们“背后”的内容。

<div style="
    background-color: #F4F4F7;
    background-image: url('wa.jpg');
    background-repeat: no-repeat;
    background-position: right bottom;
    background-size: 200px 280px;"
align="left">

What functions or attributes can accomplish this?有哪些功能或属性可以做到这一点?

add the below line in the css在 css 中添加以下行

mix-blend-mode: multiply;

You can see the background color and white pixles will go off您可以看到背景颜色和白色像素将 go 关闭

I believe there is no javascript or HTML o CSS property, attribute or function that can do what you are asking.我相信没有 javascript 或 HTML 或 CSS 属性、属性或 ZC1C425268E68385D1AB5074C1 你在问什么。

You need to remove the background in an image editor and save the image as.gif, or png with transparent background.您需要在图像编辑器中删除背景并将图像另存为 .gif 或具有透明背景的 png。

I use to do it with Paint.Net but you could do it with whatever image editor you have.我以前用Paint.Net 来做,但你可以用你拥有的任何图像编辑器来做。

When setting the background Property in CSS you can add a transparent background to the div, with the image like this:在 CSS 中设置background属性时,您可以为 div 添加透明背景,图像如下:

#myDiv {
 background:transparent url(myImage);
 }

You can only see through transparent images with PNG format.您只能通过 PNG 格式的透明图像查看。 In your example, you are using a JPG format which does not have the ability to be transparent no matter what you do (unless you're gonna use the opacity attribute in css).在您的示例中,您使用的 JPG 格式无论您做什么都无法透明(除非您要在 css 中使用 opacity 属性)。 Either use.gif or.png when saving an image for you to get the result you want.在保存图像时使用 .gif 或 .png 以获得所需的结果。

The solution I use is to remove the background from the image before using it.我使用的解决方案是在使用之前从图像中删除背景。 You can do it by running the image through remove.bg .您可以通过remove.bg运行图像来做到这一点。

Here is one way you can achieve this.这是实现这一目标的一种方法。

  1. Draw your image on a canvas.在 canvas 上绘制图像。

  2. Remove all white (or preferred color) pixels.移除所有白色(或首选颜色)像素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM