`
lukew
  • 浏览: 51639 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Fade in and out images in MIDP 2.0

阅读更多
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.zip

    《Fade In Pro剧本软件 3.0.578:行业教育与学习的高效工具》 Fade In Pro是一款专为编剧和电影制作人设计的专业剧本写作软件,它在行业教育和学习领域扮演着重要的角色。这款3.0.578版本的软件,集成了诸多功能,...

    Fade in pro 3.0562 for Mac

    Fade In Pro 3.0562 是一款专为Mac用户设计的专业剧本写作软件,它提供了全面的功能,帮助编剧们高效地创作剧本。这款软件以其直观的界面、强大的格式工具和丰富的特性,使得剧本创作变得更为简单。在本文中,我们将...

    android 屏幕保护程序--------Fade In 与 Fade Out 特效与运行线程

    本主题将探讨如何在Android屏保中实现Fade In(淡入)和Fade Out(淡出)特效,并理解如何利用多线程来优化性能。我们将以"EX07_03"这个文件作为示例,探讨具体的实现细节。 1. **Fade In 和 Fade Out 效果** - **...

    react-native-fade-in-out-slideshow

    npm i react-native-fade-in-out-slideshow 导入React Native import Slideshow from ' react-native-fade-in-out-slideshow ' 例子 const items = [ { image: ' ...

    echo_fadein_fadeout_dsp.rar_Fade Out_fadeOut

    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.

    Simulation of capacity fade in lithiumion batteries.pdf

    根据提供的文件信息,我们可以从中提炼出与锂离子电池容量衰减模拟相关的几个关键知识点: ### 锂离子电池容量衰减的概念 锂离子电池是目前电动汽车(EV)中最常用的储能装置之一。随着时间的推移和充电循环次数的...

    WPF呼吸闪烁效果例子

    &lt;BeginStoryboard Storyboard="{StaticResource FadeInAndOut}" /&gt; &lt;BeginStoryboard Storyboard="{StaticResource FadeInAndOut}" /&gt; ``` 如果你想要同时改变元素的大小,可以添加类似的方法来操作...

    FadeOutBottom.rar_Fade Out

    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, ...

    plymouth-theme-fade-in-0.8.9-0.34.20140113.el7.centos.x86_64.rpm

    官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装

    jQuery实现淡入淡出效果

    用fadeIn、fadeOut、fadeToggle来实现淡入淡出。

    3D折叠二级下拉菜单代码.zip_beautiful

    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 ...

    aos.js动画的用法

    &lt;div aos="fade-zoom-in" aos-offset="200" aos-easing="ease-in-sine" aos-duration="600"&gt; &lt;div aos="fade-up" aos-anchor-placement="top-center"&gt; 如果你担心HTML5校验的问题,可以为上面的属性添加data-前缀。...

    react-fade-in:简单的组件可以淡入元素的子元素中

    安装npm install react-fade-in 用法react-fade-in import FadeIn from 'react-fade-in';// ...&lt;FadeIn&gt; &lt;div&gt;Element 1&lt;/div&gt; &lt;div&gt;Element 2&lt;/div&gt; &lt;div&gt;Element 3&lt;/div&gt; &lt;div&gt;Element 4&lt;/div&gt; &lt;div&gt;Element 5...

    moviepy音视频开发:audio_fadein、fadeout实现声音淡入淡出.rar

    my_audio_faded_in = my_audio.fx(audio_fadein, 2) ``` 这会创建一个新的音频片段,其中音频的前两秒逐渐从无声渐变为完全的声音。 2. `audio_fadeout` `audio_fadeout`函数则用于在音频结束时添加淡出效果。同样...

    图像去雾质量评价源码Referenceless Prediction of Perceptual Fog Density and Perceptual Imag

    4. `border_in.m` 和 `border_out.m`:这两个文件可能涉及到图像边缘处理,可能用于处理图像边缘的去雾效果,确保边界一致性。 5. `FADE_example.m`:这可能是一个示例脚本,演示如何使用FADE算法进行图像去雾质量...

    unity模型高亮插件Highlighting System5.0.rar

    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:谷歌地图标记淡入淡出的简单演示

    请注意,这个例子是基于给定的“google-maps-marker-fade-in-out”项目,可能需要根据实际的项目文件结构和需求进行适当的调整。在实际项目中,你还需要考虑与其他功能的集成,如用户交互、事件监听等。 通过结合...

    HTML5 js DIV文字淡入淡出(fadein fadeout)效果.rar

    HTML5 js DIV文字淡入淡出(fadein fadeout)效果,当鼠标放在DIV上的时候,该DIV的背景渐变淡入淡出,效果平滑,更像是Flash动画的效果,用HTML5实现类似的动画效果还是比较轻松的。

Global site tag (gtag.js) - Google Analytics