Android - 拆分 Drawable

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

问题描述

我正在尝试将图像拆分为多个部分,例如 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.

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

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 - 拆分 Drawable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
appearance().setBackgroundImage Not Working On Custom Class(外观().setBackoundImage在自定义类上不起作用)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)