安卓:请具体(绿)色的背景图像透明 [英] Android: Make specific (green) color in background image transparent
问题描述
我写为Android的应用程序。
i am writing an app for Android.
在一个XML文件中定义的布局我有一个TabHost 6个选项卡,这都具有相同的大背景图像settingsdlg.gif。
in an xml file defining layout I have a TabHost with 6 Tabs, which all have the same big background image "settingsdlg.gif".
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/settingsdlg" >
..
在styles.xml我指定的窗口必须是透明的:
In styles.xml I specify that the window must be transparent:
<resources>
<style name="my_app_style" parent="@android:style/Theme.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
的问题是,在背景图像settingsdlg.gif是一个的四舍五入的矩形,并在边缘处,这应该是透明的小区域,是绿色的。
The problem is that the background image "settingsdlg.gif" is a rounded rect, and the small areas at the edges, which should be transparent, are green.
我知道,使用透明度在Android上的图像,图像必须是PNG格式,我想透明的像素应该保存为PNG透明。
I know that to use transparency in images on Android, the images must be in PNG format, and the pixels i want transparent should be saved in PNG as transparent.
不幸的是我从一个数据库中的图像,我无法改变他们,因为他们也用在其他一些应用程序的Win32和Mac。
Unfortunately I get the images from a database and I can't change them, because they are also used in some other application for Win32 and Mac.
有没有办法告诉机器人,在背景图像中的绿色像素应该呈现透明?
Is there a way to tell Android that in the background image the green pixels should be rendered transparent?
谢谢!
推荐答案
您将不得不改变每一个绿色像素变成透明的。这里有一个例子:如何改变在Android中的可绘制的颜色?
You would have to change every green pixel into a transparent one. Here is an example: How to change colors of a Drawable in Android?
然而,如果有绿色像素在图像的中间则可以有一个问题。因此,另一种方法是,如果你的形象有一定的大小和形状,以创建模板,并使用XFER模式,创建具有透明圆角的新形象。
However if there are green pixels in the middle of the image then you can have a problem. So the other way is, if your image has constant size and shape, to create a mask and use xfer modes to create a new image with transparent rounded corners.
这篇关于安卓:请具体(绿)色的背景图像透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!