Android - 拆分可绘制对象

标签 android image gridview grid split

我正在尝试将图像拆分成多个部分,例如 16 个 block (4x4)。

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

我对如何做有一个不错的想法,但我真的不知道从哪里开始。

我应该使用位图还是可绘制对象?

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

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

我不想给人留下新手的印象,也不想让别人为我做这件事,我想要自己做这件事的满足感,但我不知道从哪里开始,因为我是新手到 Java 和 Android 中的图形。

希望我的大部分问题都能得到解答,甚至可能有可用的示例,但由于某种原因我找不到。

最佳答案

我想你需要这个

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

关于Android - 拆分可绘制对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4754985/

相关文章:

c# - Gridview 使用图像排序

c# - ASP.NET GridView 删除 'Input string was not in a correct format'

java - TextView 设置可见性不起作用

android - 没有默认启动的 Intent ACTION_SEND

android - 使用处理程序从服务更新 Activity

java - Android 限制用户输入

javascript - Javascript 对悬停在图像上的影响

database - Yii2 显示存储在 BLOB 数据库字段中的图像

html - Shopify 图像 slider - 始终扩展到用户全屏

asp.net - 在 GridView 中禁用 JavaScript