如何使用 J2ME (CDC/PP 1.1) 创建 alphablending BufferedImage
我创建了一个 BufferedImage
new BufferedImage(wid,hgt,BufferedImage.TYPE_INT_ARGB);
,使用多个其他图像来组装壁纸。 它在 Jave SE 中运行良好,但是当我尝试在 J9 CDC/PP 平台上运行代码时,我发现个人配置文件 BufferedImage 没有构造函数!
谁能告诉我如何使用 CDC 1.0 和 个人资料 1.1 构建 alpha 通道支持图像?
编辑:现在我已经创建了后备代码来处理 NoSuchMethodError (等),然后简单地使用 GraphicsConfiguration.createCompatibleImage(int,int) 创建一个图像。 可能这会创建一个 alpha 混合图像,但由于其他优先事项,我需要几周时间才能专门测试它(手持设备上的测试不是我的直接责任,所以它超出了我的手)。
如果我找到更好的答案,我会将其发布为对此的答案; 同时,如果其他人打败了我,请放心,如果它有效,我会接受你的答案,并且在可预见的将来我会对这个答案感兴趣(我预计在 2-5 年内仍然需要答案) 。
I have a BufferedImage created using
new BufferedImage(wid,hgt,BufferedImage.TYPE_INT_ARGB);
to which I assemble a wallpaper using multiple other images. It works fine in Jave SE, but when I tried to run the code on a J9 CDC/PP platform I discovered that the Personal Profile BufferedImage has no constructors!
Can anyone point me to how I can construct an alpha-channel supporting image using CDC 1.0 and Personal Profile 1.1?
Edit: For now I have created fallback code which handles NoSuchMethodError (et al.) and then simply creates an image with GraphicsConfiguration.createCompatibleImage(int,int). It might be that that creates an alpha-blending image, but it will be a few weeks before I can specifically test that due to other priorities (testing on handhelds is not my direct responsibility, so it's out of my hands).
If I find a better answer, I will post it as an answer to this; in the meantime, if someone else beats me to it, be assured I will accept your answer if it works, and the answer will be of interest to me for the foreseeable future (I expect to still need an answer in 2-5 years).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
图像类 (javax.microedition.lcdui.Image
) 包含一个方法 getRGB(...) ,它将图像解析为图像中每个像素的 RGB+Alpha 值的数组。 一旦获得该格式的图像,就可以在对图像进行分层之前轻松调整 Alpha 值以增加其透明度。 这实际上是我见过的在 J2ME 中编辑图像透明度的唯一动态方法。
要从 rgba 数组中获取 alpha(透明度)值,您必须使用如下所示的位移位:
然后将 alpha(透明度)值更改为不同的值(不更改该像素的颜色),您可以使用位移位插入不同的透明度级别。
然后 Image 中有一个 createImage(...) 方法,它将图像数据的字节数组作为参数,可用于从修改后的像素数据数组中创建新图像。
同样有用的是,索尼爱立信的开发人员网站还有一个包含示例代码的教程,名为“MIDP 2.0 中的淡入和淡出图像" 解释了“如何更改图像的 alpha 值以使其看起来混合”,这本质上是 alpha 混合。
The Image class (javax.microedition.lcdui.Image
) contains a method getRGB(...) which parses the Image into an array of RGB+Alpha values for each pixel in the image. Once you have the image in that format, its easy to tweak the alpha values to increase their transparency before you layer the images. This is really the only dynamic way I've seen to edit the transparency of an image in J2ME.
to get the alpha (transparency) value out of the rgba array you have to use bit-shifting like this:
and then to change the alpha (transparency) value to something different (without changing the color at that pixel), you can use bitshifting to insert a different transparency level.
Then there is a createImage(...) method in Image that takes a byte-array of image data as a parameter, that can be used to create a new image out of your modified pixel data array.
Also helpful, SonyEricsson's developer website also has a tutorial with sample code called "Fade in and out images in MIDP 2.0" which explains "how to change the alpha value of an image to make it appear blended" which is essentially alpha-blending.