姜饼上的渐变
已更新
我在 android 2.3 上遇到渐变位图问题。我读了这篇很棒的文章并且使用下一个选项解码我的位图:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inDither = true;
And on android 2.2 everything is great, but on android 2.3 gradient artifacts remain even after that decoding.我使用我的位图在 2.3 上运行 文章中的应用程序,所有变体都是 不好:16/32 位,(不)抖动和 RBG_565、ARGB_8888 和 ARGB_4444 - 渐变有伪影。我还尝试在没有选项的情况下进行解码。 一切都很好。抱歉,问题出在
opts.inScaled=true;
opts.inDensity=100;
opts.inTargetDensity=800;
但是现在我需要在 android 2.3 上运行此代码,但它仍然会产生错误的渐变(在 android 2.2 上一切正常):
ImageView imageView = (ImageView) tabView.findViewById(R.id.tabsImage);
// decode bitmaps
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inDither = true;
Bitmap tabImageOn = BitmapFactory.decodeResource(mainActivity.getResources(), tabImageResourceOnId, options);
Bitmap tabImageOff = BitmapFactory.decodeResource(mainActivity.getResources(), tabImageResourceOffId, options);
// create new selector
StateListDrawable tabImage = new StateListDrawable();
tabImage.addState(new int[] { android.R.attr.state_selected }, new BitmapDrawable(mainActivity.getResources(), tabImageOn));
tabImage.addState(new int[] {}, new BitmapDrawable(mainActivity.getResources(), tabImageOff));
tabImage.setDither(true);
// set selector to tab
imageView.setImageDrawable(tabImage);
I tried to set window pixel format in onCreate
/before/after that method next way: WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(getWindow().getAttributes());
lp.format = PixelFormat.RGBA_8888;
getWindow().setAttributes(lp);
但没有任何改变(它是姜饼,它使用 32 位窗口格式)。
为什么会出现这种行为以及如何解决我的问题?
谢谢。再会!
Updated
I have a problem with gradient bitmaps on android 2.3. I read this great article and decode my bitmaps using next options:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inDither = true;
And on android 2.2 everything is great, but on android 2.3 gradient artifacts remain even after that decoding.
I run application from article on 2.3 with my bitmaps and all variants are bad: 16/32 bit, (not) dither and RBG_565, ARGB_8888 and ARGB_4444 - gradient has artifacts. Also I tried to decode without options. Everything is ok. Sorry, problem was in
opts.inScaled=true;
opts.inDensity=100;
opts.inTargetDensity=800;
But now I need to make working this code on android 2.3 and its still produce bad gradient (on android 2.2 everything is ok):
ImageView imageView = (ImageView) tabView.findViewById(R.id.tabsImage);
// decode bitmaps
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inDither = true;
Bitmap tabImageOn = BitmapFactory.decodeResource(mainActivity.getResources(), tabImageResourceOnId, options);
Bitmap tabImageOff = BitmapFactory.decodeResource(mainActivity.getResources(), tabImageResourceOffId, options);
// create new selector
StateListDrawable tabImage = new StateListDrawable();
tabImage.addState(new int[] { android.R.attr.state_selected }, new BitmapDrawable(mainActivity.getResources(), tabImageOn));
tabImage.addState(new int[] {}, new BitmapDrawable(mainActivity.getResources(), tabImageOff));
tabImage.setDither(true);
// set selector to tab
imageView.setImageDrawable(tabImage);
I tried to set window pixel format in onCreate
/before/after that method next way:
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(getWindow().getAttributes());
lp.format = PixelFormat.RGBA_8888;
getWindow().setAttributes(lp);
But nothing has been changed (it's gingerbread, it's using 32 bit window format).
Why do so behaviour appear and how can i solve my problem?
Thanks. Good day!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过将可绘制对象移动到 hdpi 文件夹来解决。
solved with moving drawables to
hdpi
folder.