首页 > 解决方案 > 是否可以在 Android 中将图像拆分为多个部分?

问题描述

我正在创建一个益智游戏,玩家可以在其中选择一张图片,然后程序将其分成多个部分。

我试图在很多帖子上搜索我的问题的答案,但他们都在谈论 BufferedImage 或 Graphic 组件。我在 android studio 上编写代码以便稍后导出我的应用程序,而 BufferedImage、Graphics 和其他内容不为 android 所知。所以我认为我应该使用 BitmapDrawable 来操作我的图像。

public void initImage(int image) {
    this.base = setImage(puzzle.getApplicationContext(), image, 800, 800);
}

public BitmapDrawable setImage(final Context c, final int ressource, final int w, final int h)
{
    try {
        Drawable dr = c.getResources().getDrawable(ressource);
        Bitmap bitmap = ((BitmapDrawable) dr).getBitmap();
        return new BitmapDrawable(c.getResources(), Bitmap.createScaledBitmap(bitmap, w, h, true));
    } catch(ClassCastException cce) { cce.printStackTrace(); return null; }
}

@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    canvas.drawBitmap(this.base.getBitmap(), 0, 0, null);
}

我画了我的第一张图片,现在我想把它分成多个部分。

如果有人可以帮助我,我将不胜感激。:)

标签: javaandroidimagesplitbitmapimage

解决方案


推荐阅读