gpt4 book ai didi

android - 如何在不改变( strip )的情况下在 Android 中添加 PNG 图像作为背景?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:07:51 26 4
gpt4 key购买 nike

我正在尝试添加包含渐变的背景(我确实想使用图像,而不是 android xml 声明的渐变效果)。

这张图片明显被 Android 破坏了,它添加了一些蹩脚的 strip ,无论我尝试什么,结果都是一样的(两次捕获大致相同区域的扭曲/正常图像):

distorted normal

我的图像在我的布局 XML 中用作布局背景:

android:background="@drawable/background_gradient_dithered"

我尝试使用一个中间可绘制对象来强制抖动,其 xml 为:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/background_gradient" android:dither="true" android:antialias="true" android:filter="true"/>

我尝试在我的 onCreate() 中加入以下代码:

getWindow().setFormat(PixelFormat.RGBA_8888);

两次尝试都没有改变。

谢谢

最佳答案

正确的解决方案是......我打赌你已经猜到了:重新启动 Eclipse。我已经了解到,Android 上的每个问题都可能是“重新启动 Eclipse 问题”。

经过一些测试,我可以补充一点,当格式设置为 PixelFormat.RGBA_8888 时,启用去噪功能没有用

请读者看看@TenFour04 给出的答案,这种做法可以避免为了启用抖动而make drawable。

window.addFlags(WindowManager.LayoutParams.FLAG_DITHER);

编辑:

我发现即使使用这些技巧,问题仍然存在。您可以尝试修改您的 PNG 以在其中包含一个 alpha 层(例如将一个像素更改为 99% 的透明度),这将强制 android 编译器不使用它。

关于android - 如何在不改变( strip )的情况下在 Android 中添加 PNG 图像作为背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7741547/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com