background:rgba(200, 54, 54, 0.5);
.footer {
background: linear-gradient(to top, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0));
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 50px;
}
1. filter:Alpha(enabled=bEnabled,style=iStyle,
2. opacity=iOpacity,finishOpacity=iFinishOpacity,
3. startX=iPercent,startY=iPercent,
4. finishX=iPercent,finishY=iPercent);
5.
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TransparentColorExample extends JPanel {
private static final Color RED = new Color(255, 0, 0);
private static final Color GREEN = new Color(0, 255, 0);
private static final Color BLUE = new Color(0, 0, 255);
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
// 扇区1
g2d.setColor(RED);
g2d.fillArc(50, 50, 200, 200, 0, 72);
// 扇区2
g2d.setColor(GREEN.withAlpha(0));
g2d.fillArc(50, 50, 200, 200, 72, 108);
// 扇区3
g2d.setColor(BLUE);
g2d.fillArc(50, 50, 200, 200, 180, 180);
}
public static void main(String[] args) {
JFrame frame = new JFrame("Pie Chart");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setResizable(false);
frame.add(new TransparentColorExample());
frame.setVisible(true);
}
}
import matplotlib.pyplot as plt
# 创建一个色条
colors = ['red', 'green', 'blue']
plt.bar(range(len(colors)), [1, 2, 3], color=colors, alpha=0.5)
# 显示图表
plt.show()
import javax.swing.*;
import java.awt.*;
public class TransparentTableExample extends JFrame {
public TransparentTableExample() {
// 设置窗口标题
setTitle("透明表格示例");
// 设置窗口大小
setSize(400, 300);
// 设置窗口关闭时的操作
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
TransparentTableExample example = new TransparentTableExample();
// 显示窗口
example.setVisible(true);
}
}
1 import java.awt.Color;
2 import java.awt.Container;
3 import javax.swing.JComponent;
4 import javax.swing.JFrame;
5 import javax.swing.JLabel;
6 import javax.swing.JPanel;
7 import javax.swing.JRootPane;
8
9 public class BackGround {
10 //设置窗口
11 JFrame f = new JFrame("panel test");
12 //设置按钮
13 JLabel label=new JLabel("ABC");
14 public BackGround(){
15 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
16 f.setSize(300, 200);
17 label.setBounds(80, 50, 100, 80);
18 //第四层
19 Container root = (JRootPane) f.getRootPane();
20 root.setBackground(Color.green);
21 //第三层
22 Container layer=f.getLayeredPane();
23 layer.setBackground(Color.yellow);
24 //第二层
25 Container content = (JPanel) f.getContentPane();
26 content.setBackground(Color.orange);
27 //第一层
28 JComponent glass=(JComponent) f.getGlassPane();
29 glass.setBackground(Color.red);
30 //添加组件
31 content.setLayout(null);
32 content.add(label);
33 f.setVisible(true);
34 }
35 public static void main(String[] args) {
36 new BackGround();
37 }
38 }
import numpy as np
import cv2
from PIL import Image
img = cv2.cvtColor(cv2.imread("animal-horse.jpg"), cv2.COLOR_BGR2RGB)
print(img.shape, img.dtype) # (1200, 1600, 3) uint8
# 找白色背景部分
mask = (255 == img[:, :, 0]) & (255 == img[:, :, 1]) & (255 == img[:, :, 2])
# 计算 alpha 通道:反选前景并设为 255 不透明
# 转成 uint8,与原 RGB 的类型一致
alpha = (1 - mask.astype(np.uint8)) * 255
# 升维、拼接:RGB -> RGBA
img_rgba = np.concatenate((img, alpha[:, :, np.newaxis]), 2)
# 转成 PIL.Image
img_rgba = Image.fromarray(img_rgba)
# 保存
img_rgba.save("animal-horse.png")
import matplotlib.pyplot as plt
# 创建示例数据
x = [1, 2, 3, 4, 5]
y = [2, 4, 6, 8, 10]
# 绘制折线图
plt.plot(x, y)
plt.show()
width:300px;
height:200px;
margin:0 auto;
border:1px solid #ccc;
background:red;
opacity:0.2;
}
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000"
...>
...
</LinearLayout>
// 创建一个完全透明的颜色
Color transparentColor = new Color(0, 0, 0, 0);
// 创建一个半透明的红色
Color translucentRed = new Color(255, 0, 0, 128);
// 创建一个半透明的蓝色
int blue = 0x0000FF;
Color translucentBlue = new Color(blue | 0x80000000, true);