Android - 拆分可绘制 [英] Android - Split Drawable

查看:18
本文介绍了Android - 拆分可绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将图像拆分为多个部分,例如 16 个块 (4x4).

I am attempting to split an image into pieces, lets say for example 16 chunks (4x4).

我发现了很多关于 java 的例子,但 Android 没有 BufferedImage 和什么没有......我想.

I have found so many examples with java, but Android does not have BufferedImage and what not... I think.

我有一个不错的想法,但我真的不知道从哪里开始.

I have a decent IDEA on how to, but I don't really know where to start.

我应该使用位图还是 drawable?

Should I use a bitmap or a drawable?

是否有拆分的方法,或者我必须制作自定义方法?

Is there a method to split or will I have to make a custom method?

我应该使用 GridView 来保存分割图像吗?

Should I use a GridView to hold the split images?

我不想给人一种新手的印象,也不想有人为我做这件事,我想要自己做这件事的满足感,但我没有太多想法,因为我是新手到 Java 和 Android 中的图形.

I don't want to com across as newbish and wanting to have someone do this for me, I want the satisfaction of doing it myself, but I don't have to much of an idea where to start since I am new to graphics in Java and Android.

希望我的大部分问题都是可以回答的,甚至可能有我因某种原因找不到的示例.

Hopefully most of my questions are answerable and maybe even have examples available that I can't find for some reason.

推荐答案

我认为你需要这个

void createImageArrays()
{
    Bitmap bMap = BitmapFactory.decodeResource(getResources(), image);
    Bitmap bMapScaled = Bitmap.createScaledBitmap(bMap, 240, 240, true);

    bitmapsArray[0] = Bitmap.createBitmap(bMapScaled, 0, 0, 80, 80);
    bitmapsArray[1] = Bitmap.createBitmap(bMapScaled, 80, 0, 80, 80);
    bitmapsArray[2] = Bitmap.createBitmap(bMapScaled, 160, 0, 80, 80);
    bitmapsArray[3] = Bitmap.createBitmap(bMapScaled, 0, 80, 80, 80);
    bitmapsArray[4] = Bitmap.createBitmap(bMapScaled, 80, 80, 80, 80);
    bitmapsArray[5] = Bitmap.createBitmap(bMapScaled, 160, 80, 80, 80);
    bitmapsArray[6] = Bitmap.createBitmap(bMapScaled, 0, 160, 80, 80);
    bitmapsArray[7] = Bitmap.createBitmap(bMapScaled, 80, 160, 80, 80);
    bitmapsArray[8] = Bitmap.createBitmap(bMapScaled, 160, 160, 80, 80);

}

原图是240x240,我把它分成9块80x80

The original image is 240x240 and I divided it into 9 pieces of 80x80

这篇关于Android - 拆分可绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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