MonoDroid图像条带

时间:2012-06-27 12:52:09

标签: android image bitmap xamarin.android

我的背景有问题。在使用渐变设置背景图像时,我会得到可怕的图像条纹。当我在根布局中设置背景时,我按如下方式进行:

        android:background="@drawable/GradientImage" 

我也尝试在代码中设置我的根布局的背景(从axml中删除背景后):

        Window.SetFormat(Android.Graphics.Format.Rgbx8888); 
        Window.AddFlags(Android.Views.WindowManagerFlags.Dither); 

        BitmapFactory.Options options = new BitmapFactory.Options(); 
        options.InPreferredConfig = Bitmap.Config.Argb8888; 
        Bitmap gradient = BitmapFactory.DecodeResource(Resources, Resource.Drawable.Background_640,options); 
        sv.SetBackgroundDrawable(new BitmapDrawable(gradient)); 

这是在OnCreate中完成的,遗憾的是无法解决问题,

有没有人遇到过这个问题?现在有人如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

此代码适用于我(在onCreate())

getWindow().setFormat(PixelFormat.RGBA_8888);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);

此外,使用PNG图像时,请确保它们使用的是32位颜色深度,
因为某些图像编辑程序默认将它们保存为24位 例如,在GIMP中,您可以强制将PNG图像保存为32位 通过添加alpha通道。

相关问题