Android - Split Drawable

寵の児 提交于 2019-11-29 00:10:37

问题


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

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?

Should I use a GridView to hold the split images?

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.


回答1:


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




回答2:


BufferedImage in Java SE is like a Bitmap in Android. Drawable is just an interface that tells you that something is drawable. It can be a bitmap, shape, color, etc.



来源:https://stackoverflow.com/questions/4754985/android-split-drawable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!