Android - Split 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android - 拆分 Drawable
基础教程推荐
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
