绘图缩放位图上的SurfaceView - 无抗锯齿 [英] Drawing scaled bitmaps on a SurfaceView -- no antialiasing

查看:912
本文介绍了绘图缩放位图上的SurfaceView - 无抗锯齿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉,如果这个话题已经被提交,但是网络和谷歌团体我所有的搜索并没有帮助我。

I'm sorry if this topic has been brought before, but all my searches on the web and google groups did not help me.

我目前正在开发的Andr​​oid SDK中的一个小游戏,并使用我相应调整,以匹配设备的分辨率(让系统做到这一点对我来说是高分辨率的位图 不是脆就够了)。

I'm currently developing a little game with the Android SDK, and use hi-res bitmaps that I resize accordingly to match the device's resolution (letting the system do it for me is not "crisp" enough).

我使用SurfaceView,其上我画在一次通过画布填充整个表面上。该涂料采用setXfermode(新PorterDuffXfermode(PorterDuff.Mode.SRC_IN)),以便屏蔽。 在此之前,我找回各种各样的位图 - 这是调整大小在初始化与createScaledBitmap(),并放入高速缓存 - 我使用位图用涂料这个画布上,在SurfaceView绘制这个画布前。

I use a SurfaceView, on which I paint in one pass a canvas filling the whole surface. The paint uses setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)) to allow masking. Beforehand, I retrieve various bitmaps -- which are resized at initialization with createScaledBitmap() and put in a cache -- and I apply the bitmaps with a paint on this canvas, before drawing this canvas on the SurfaceView.

我的问题是,无论我试试,不管漆设置我使用(抖动,反锯齿等),调整大小后的位图不抗锯齿和绘图present锯齿状边缘。我什么都试过。 唯一的小成功,我是用inSampleSize接近所需的缩放大小和强制抗锯齿的第一遍,在检索调用createScaledBitmap前 高分辨率的位图,但它不是不够漂亮。我只是不能让创建pre大小的位图众人分辨率的每个组合。我错过了什么?

My problem is, whatever I try, whatever paint settings I use (dithering, antialias, etc..), the resized bitmaps are not antialiased and the drawing present jagged edges. I tried everything. The only little success I had was using inSampleSize to approach the desired scaled size and force a first pass of antialiasing, before invoking createScaledBitmap on the retrieved hi-res bitmap, but it is not beautiful enough. I just can't allow to create multitudes of pre-sized bitmaps for every combination of resolution. What did I miss ?

感谢很多提前

推荐答案

首先,当你加载的位图,你要确保你不设置选项丢失任何的图像质量argb_8888:

First when you load your bitmap you make sure that you don't lose any image quality by settings options to argb_8888:

Options options = new Options();    
options.inScaled = false; 
options.inPreferredConfig = Bitmap.Config.ARGB_8888; 
Bitmap pic = BitmapFactory.decodeResource(getResources(), R.id.pic, options);

当您缩放过滤器上的位图依次为:

When you scale the bitmap turn on the filter:

pic = Bitmap.createScaledBitmap(pic, screenW, screenH, true);

但是,如果一个streaches图像过多不可避免地会降低质量。

However if one streaches the image too much inevitably it degrades in quality.

当您使用底漆可以提高质量,而且通过打开ditherig和过滤丧失速度:

When you use paint you can improve quality but lose on speed with turning on ditherig and filtering:

Paint paint = new Paint(); 
paint.setFlags(Paint.DITHER_FLAG);
paint.setFilterBitmap(true);

最后,整个活动窗口,可以在argb_4444而不是在argb_8888(; 2.3 OS&LT)设置。如果你instert这条线,你可以恰克此之前的setContentView:

Finally the entire activity window could be set on argb_4444 instead on argb_8888 (OS < 2.3). You can chage this if you instert this line before setContentView:

getWindow().setFormat(PixelFormat.RGBA_8888); 

这篇关于绘图缩放位图上的SurfaceView - 无抗锯齿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆