简体   繁体   English

Android - Split Drawable

[英]Android - Split Drawable

I am attempting to split an image into pieces, lets say for example 16 chunks (4x4). 我试图将图像分成碎片,例如16个块(4x4)。

I have found so many examples with java, but Android does not have BufferedImage and what not... I think. 我用java发现了很多这样的例子,但是Android没有BufferedImage,有什么不...我想。

I have a decent IDEA on how to, but I don't really know where to start. 我有一个像样的IDEA,但我真的不知道从哪里开始。

Should I use a bitmap or a drawable? 我应该使用位图还是可绘制的?

Is there a method to split or will I have to make a custom method? 有没有方法可以拆分或者我必须制作自定义方法?

Should I use a GridView to hold the split images? 我应该使用GridView来保存分割图像吗?

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. 我不想和新手一样,想要让某人为我做这件事,我希望自己能够满意地做到这一点,但是我不知道从哪里开始,因为我是新手Java和Android。

Hopefully most of my questions are answerable and maybe even have examples available that I can't find for some reason. 希望我的大部分问题都是可以回答的,甚至可能有一些我无法找到的例子。

I think you need this 我想你需要这个

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);

}

The original image is 240x240 and I divided it into 9 pieces of 80x80 原始图像为240x240,我将其分为9个80x80

BufferedImage in Java SE is like a Bitmap in Android. Java SE中的BufferedImage类似于Android中的Bitmap。 Drawable is just an interface that tells you that something is drawable. Drawable只是一个界面,告诉你某些东西是可绘制的。 It can be a bitmap, shape, color, etc. 它可以是位图,形状,颜色等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM