简体   繁体   English

Android渐变图形质量(比例位图)

[英]Android gradient graphics quality (scaled bitmap)

I want to display a splash screen with an gradient in my app. 我想在我的应用程序中显示带有渐变的初始屏幕。 But the quality of the gradient in the background is pretty bad. 但是背景中的渐变质量非常差。 So I create a simple radiant gradient to have a closer look. 因此,我创建了一个简单的辐射渐变以更仔细地观察。

Edit: Maybe I should have mentioned that I am using BitmapFactory.createScaledBitmap(); 编辑:也许我应该提到我正在使用BitmapFactory.createScaledBitmap();。 and BitmapFactory.decodeStream() (The graphics are in the assets folder.) 和BitmapFactory.decodeStream()(图形位于资产文件夹中。)

Thats the result: 那就是结果:

Original *.jpg (Quality 100%) 原始* .jpg(质量100%) 在此处输入图片说明

Screenshot Xperia X10 (I took the screenshot with Eclipse) 屏幕快照Xperia X10(我使用Eclipse拍摄了屏幕截图) 在此处输入图片说明

You can do it without any jpg file, but using a shape drawable . 您可以在不使用任何jpg文件的情况下执行此操作,而可以使用可绘制形状 Create rectangle and provide necessary parmas for gradient tag. 创建矩形并为gradient标签提供必要的parma。

In order to scale a bitmap and keep ARGB_8888 I created a new bitmap in the desired size. 为了缩放位图并保持ARGB_8888,我创建了所需大小的新位图。 Then I use canvas to draw the intrinsic bitmap on the new bitmap with drawBitmap . 然后,我使用canvas通过drawBitmap在新位图上绘制固有位图。 This method allows me to scale the bitmap before I draw it on the new bitmap. 这种方法使我可以在将位图绘制到新位图上之前对其进行缩放。

inputStream = assetManager.open(path);
originalBitmap = BitmapFactory.decodeStream(inputStream, null, opts);

Bitmap resizedBitmap = Bitmap.createBitmap(desiredX, desiredY, Config.ARGB_8888);

Canvas canvas = new Canvas(resizedBitmap);
canvas.drawBitmap(originalBitmap, null, new Rect(0, 0, desiredX, desiredY), null);

inputStream.close();
return resizedBitmap;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM