当前位置:网站首页>Set the transparency of the picture to gradient from left to right
Set the transparency of the picture to gradient from left to right
2022-06-25 12:17:00 【User 9854323】
One 、 Set the transparency of the picture to gradient from left to right
/**
* Set the transparency of the picture to gradient from left to right , Make a smooth transition to the right edge ( Be careful to follow only x Coordinate change )
*
* @param num The scope is 0-100,0 For full transparency ,100 For opacity
*/
public static Bitmap getTransAlphaBitmap(Bitmap sourceImg, float num) {
if (sourceImg == null) {
return null;
}
int width = sourceImg.getWidth();
int height = sourceImg.getHeight();
int[] bitArr = new int[width * height];
sourceImg.getPixels(bitArr, 0, width, 0, 0, width, height);
float number = num;
int start = width / DEFAULT_PERCENT;
float range = width - start;
try {
float step = (number * 1.0f) / range;
for (int j = 0; j < height; j++) {
number = num;
for (int i = start + j * width; i < width * (j + 1); i++) {
number = number - step;
float alpha = number * ALPAH_FULL / NUMBER_FULL;
bitArr[i] = ((int) alpha << DEFAULT_BIT) | (bitArr[i] & DEFAULT_ALPHA);
}
}
return Bitmap.createBitmap(bitArr, width, height, Bitmap.Config.ARGB_8888);
} catch (Throwable e) {
return sourceImg;
}
}
Two 、 Set the transparency of the picture to gradient from top to bottom
/**
* Set the transparency of the picture to gradient from top to bottom , Make a smooth transition at the bottom edge ( Be careful to follow only Y Coordinate change )
*
* @param sourceImg
* @return
*/
public static Bitmap getTransAlphaBitmap(Bitmap sourceImg) {
int[] argb = new int[sourceImg.getWidth() * sourceImg.getHeight()];
sourceImg.getPixels(argb, 0, sourceImg.getWidth(), 0, 0, sourceImg
.getWidth(), sourceImg.getHeight());// Get pictures of ARGB value
//number For the range of 0-100,0 For full transparency ,100 For opacity
float number = 100;
// Transparency value
float alpha = number * 255 / 100;
// The range of the image gradient ( Set the gradient from top to bottom for only half of the picture , There is no gradient on it , That is, the half close to the edge )
float range = sourceImg.getHeight() / 2.0f;
// Transparency gradient , Every time with Y The amount of coordinate change , Because at the end it will become 0
float pos = (number * 1.0f) / range;
// Subscript at the beginning of the loop , When does the setting change
int start = sourceImg.getWidth() * (sourceImg.getHeight() - (int) range);
for (int i = start; i < argb.length; i++) {
// The same line alpha The value does not change , Because with Y Coordinates change from top to bottom
if (i % sourceImg.getWidth() == 0) {
number = number - pos;
alpha = number * 255 / 100;
}
argb[i] = ((int) alpha << 24) | (argb[i] & 0x00FFFFFF);
}
sourceImg = Bitmap.createBitmap(argb, sourceImg.getWidth(), sourceImg
.getHeight(), Bitmap.Config.ARGB_8888);
return sourceImg;
}
边栏推荐
- 做自媒体视频需要怎么做才能年收入一百万?
- PyCaret 成功解决无法从‘sklearn.model_selection._search‘导入名称“_check_param_grid”
- ArcGIS services query filter by time field
- Cesium editing faces
- Is it safe to open an account and buy stocks? Who knows
- 【数据中台】数据中台的OneID是个什么鬼,主数据它不香吗?
- Le détour d'un ingénieur en matériel
- 20、wpf之MVVM命令绑定
- 刷入Magisk通用方法
- R language uses GLM function to build Poisson logarithmic linear regression model, processes three-dimensional contingency table data to build saturation model, and poisgof function of epidisplay pack
猜你喜欢
揭秘GaussDB(for Redis):全面對比Codis
Understanding and construction of devsecops and Devops
刷入Magisk通用方法
Using DBF of VFP to web salary query system
Continue to cut the picture after the ArcGIS Server is disconnected
Caused by: org. xml. sax. SAXParseException; lineNumber: 1; columnNumber: 10; Processing matching '[xx][mm][ll]' is not allowed
20、wpf之MVVM命令绑定
PD1.4转HDMI2.0转接线拆解。
flutter常用命令及问题
19. Implementation of MVVM architecture based on WPF event to command
随机推荐
Dark horse shopping mall ---2 Distributed file storage fastdfs
Dark horse shopping mall ---8 Microservice gateway and JWT token
Caused by: org. xml. sax. SAXParseException; lineNumber: 1; columnNumber: 10; Processing matching '[xx][mm][ll]' is not allowed
Develop two modes of BS mode verification code with VFP to make your website more secure
SDN系统方法 | 9. 接入网
plt. GCA () picture frame and label
A detour taken by a hardware engineer
Network related encapsulation introduced by webrtc native M96 basic base module
ARM 立即数
JS judge whether a number is in the set
Effective reading of literature
Arm immediate
实现领域驱动设计 - 使用ABP框架 - 系列文章汇总
一套自动化无纸办公系统(OA+审批流)源码:带数据字典
An easy-to-use seal design tool - (can be converted to ofd file)
Oracle Spatial creating spatial tables
Encapsulation of practical methods introduced by webrtc native M96 basic base module (MD5, Base64, time, random number)
Uncover gaussdb (for redis): comprehensive comparison of CODIS
R语言dplyr包summarise_at函数计算dataframe数据中多个数据列(通过向量指定)的计数个数、均值和中位数、在每个函数内部指定na.rm参数、通过list指定函数列表
Why should Apple change objc_ Type declaration for msgsend