使用NinePatch(.9.png)制作缩放的位图 [英] Using NinePatch (.9.png) for making scaled Bitmaps

查看:109
本文介绍了使用NinePatch(.9.png)制作缩放的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为新的Android应用程序绘制一个位图.由于我的内容视图设置为我创建的Game-Panel类.我想通过位图显示图像.仅仅因为它更方便,并且更容易做其他事情. 从研究中收集到的信息来看,Android中使用了九个补丁图像(.9.png)来比常规Drawable图像更正确地缩放.它还说:这可用于在背景中正确缩放.例如常规按钮背景...".如果制作了九个补丁图像,则可以更好地缩放图像.您可以使用九个补丁制作特定宽度和高度的位图,因为它可以更适当地缩放吗?例如

I need to draw a Bitmap for my new Android Application. Since my content view is set to a Game-Panel class I've created. I want to display images through Bitmap. Just because its more convenient, and easier to do then anything else. From what I've gathered from researching, Nine Patch images (.9.png) are used in android to scale more properly then regular Drawable images. It also says "This can be used for scaling properly in backgrounds. For example a regular button background...". If Nine Patch images are made to scale better. Can You use a Nine Patch for making a Bitmap in a specific width and height because it would scale more properly? For example

Bitmap b = createBitmap(BitmapFactory.decodeResource(NinePatchImage), x, y, width, height);

这可能吗?我应该用其他方式吗?我应该先创建一个位图,然后再缩放位图吗?这甚至有必要吗?请帮忙.

Is this possible? Should I do it a different way? Should I create a bitmap first and then just scale the bitmap? Is this even necessary? Please help.

推荐答案

Bitmap bitmap = Bitmap.createBitmap(canvasWidth, canvasHeight, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
NinePatchDrawable drawable = (NinePatchDrawable) getResources().getDrawable(R.drawable.myDrawable);
drawable.setBounds(new Rect(x, y, width, height));
drawable.draw(canvas);

这篇关于使用NinePatch(.9.png)制作缩放的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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