This tip describes how to change the alpha value of an image to make it
appear blended. There's also an example MIDlet with source code.
In MIDP 2.0 there's a new method in the Image class,
getRGB(...)
that will get all Alpha, Red, Green, Blue (ARGB) values from the image
to an int array. We can use this method, and the resulting array, to
change the alpha value of the image.
Integers in J2ME are four bytes, each pixel in the image is described
by the ARGB values where each color is one byte 0 to 255. If the alpha
value is 0, the corresponding pixel will be transparent, if the alpha
is 255, the pixel will be opaque.
To get a specific color from the int array, it's possible to use the
AND '&' operator and to accomplish the blending effect we need to get the colors, without the alpha value, from the int array.
<!---->FF = 11111111 = 255
0xFFFFFFFF - Alpha = 255, Red =255 Green = 255, Blue = 255
(0xFFFFFFFF & 0x00FFFFFF) = 0x00FFFFFF
By doing this we'll only get the RGB colors from the int array, alpha equals zero.
Now when we just have the RGB colors and alpha equals zero, we can just add our new alpha value.
If we have the alpha value 255 and want to add this to our color, we need to use the shift left operator.
To change:
<!---->(00000000 00000000 00000000 11111111) to
(11111111 00000000 00000000 00000000)
use the shift left '<<' operator.
(0xFF << 24) = 0xFF000000.
With this knowledge we now can change the alpha value or do masking for specific colors.
- Use the getRGB(...) method in the image class to get all the ARGB values from the image to a int array.
- Use the blend function below to change the alpha value for each value in the array.
- Use the createRGBImage(...) method in the image class to create a new image from the edited int array.
There are examples on how to use the getRGB and createRGBImage methods in the MIDlet below.
<!---->public static void blend(int[] raw, int alphaValue){
int len = raw.length;
// Start loop through all the pixels in the image.
for(int i=0; i<len; i++){
int a = 0;
int color = (raw[i] & 0x00FFFFFF); // get the color of the pixel.
a = alphaValue; // set the alpha value we want to use 0-255.
a = (a<<24); // left shift the alpha value 24 bits.
// if color = 00000000 11111111 11111111 00000000 (0xFFFF00 = Yellow)
// and alpha= 01111111 00000000 00000000 00000000
// then c+a = 01111111 11111111 11111111 00000000
// and the pixel will be blended.
color += a;
raw[i] = color;
}
}
example code
分享到:
相关推荐
《Fade In Pro剧本软件 3.0.578:行业教育与学习的高效工具》 Fade In Pro是一款专为编剧和电影制作人设计的专业剧本写作软件,它在行业教育和学习领域扮演着重要的角色。这款3.0.578版本的软件,集成了诸多功能,...
Fade In Pro 3.0562 是一款专为Mac用户设计的专业剧本写作软件,它提供了全面的功能,帮助编剧们高效地创作剧本。这款软件以其直观的界面、强大的格式工具和丰富的特性,使得剧本创作变得更为简单。在本文中,我们将...
本主题将探讨如何在Android屏保中实现Fade In(淡入)和Fade Out(淡出)特效,并理解如何利用多线程来优化性能。我们将以"EX07_03"这个文件作为示例,探讨具体的实现细节。 1. **Fade In 和 Fade Out 效果** - **...
npm i react-native-fade-in-out-slideshow 导入React Native import Slideshow from ' react-native-fade-in-out-slideshow ' 例子 const items = [ { image: ' ...
input the sound file and it will perform the fade in, fade out and echo on that. it is a dsp project done on the matlab.
根据提供的文件信息,我们可以从中提炼出与锂离子电池容量衰减模拟相关的几个关键知识点: ### 锂离子电池容量衰减的概念 锂离子电池是目前电动汽车(EV)中最常用的储能装置之一。随着时间的推移和充电循环次数的...
<BeginStoryboard Storyboard="{StaticResource FadeInAndOut}" /> <BeginStoryboard Storyboard="{StaticResource FadeInAndOut}" /> ``` 如果你想要同时改变元素的大小,可以添加类似的方法来操作...
Fade Out Bottom——是一款在网页底部产生淡入淡出效果的JavaScript插件,不管显示在网页底部的是文字或是图片,它都将其修饰为渐变的淡入淡出风格,拖动网页的滚动条之后,它仍会将显示在最底部的内容变为淡入淡出...
3. Constant highlighting (with fade in/out) Can be used to constantly highlight objects (pickable items or currently selected objects for example). This system works with static and skinned meshes, ...
官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装
用fadeIn、fadeOut、fadeToggle来实现淡入淡出。
A very beautiful jQuery fade-in and fade-out focus map advertising rotation plug-in, suitable for shopping mall advertising image switching effect, image switching fade-in and fade-out transition ...
<div aos="fade-zoom-in" aos-offset="200" aos-easing="ease-in-sine" aos-duration="600"> <div aos="fade-up" aos-anchor-placement="top-center"> 如果你担心HTML5校验的问题,可以为上面的属性添加data-前缀。...
安装npm install react-fade-in 用法react-fade-in import FadeIn from 'react-fade-in';// ...<FadeIn> <div>Element 1</div> <div>Element 2</div> <div>Element 3</div> <div>Element 4</div> <div>Element 5...
my_audio_faded_in = my_audio.fx(audio_fadein, 2) ``` 这会创建一个新的音频片段,其中音频的前两秒逐渐从无声渐变为完全的声音。 2. `audio_fadeout` `audio_fadeout`函数则用于在音频结束时添加淡出效果。同样...
4. `border_in.m` 和 `border_out.m`:这两个文件可能涉及到图像边缘处理,可能用于处理图像边缘的去雾效果,确保边界一致性。 5. `FADE_example.m`:这可能是一个示例脚本,演示如何使用FADE算法进行图像去雾质量...
3. Constant (with optional fade in/out) Can be used to constantly highlight objects (e.g. pickable items or currently selected objects). Tested on: • PC • Mac • XBox One • HTC Vive • Android • ...
请注意,这个例子是基于给定的“google-maps-marker-fade-in-out”项目,可能需要根据实际的项目文件结构和需求进行适当的调整。在实际项目中,你还需要考虑与其他功能的集成,如用户交互、事件监听等。 通过结合...
HTML5 js DIV文字淡入淡出(fadein fadeout)效果,当鼠标放在DIV上的时候,该DIV的背景渐变淡入淡出,效果平滑,更像是Flash动画的效果,用HTML5实现类似的动画效果还是比较轻松的。