本文介绍了安卓:从调用绘制图像,并显示在屏幕上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计一个形象拼图(拼图)游戏。我被困在这,当我开始比赛就说明当我点击该选项新形象,但出了问题,它提供了一个错误信息,是指从文件夹中绘制的图像不加载。

I am designing a Image Puzzle(JigSaw) game. I am stuck in a problem that, when I start the game it shows the option "New Image" but, when I click on that, it gives an error message, means images from the drawable folder are not loading.

我做研究,我来到了这一点,我有我的code实现这一点。但是,它提供了一个错误。无法加载。

I did research and i came with this, i have implemented this in my code. but, it gives an error.. "Could not Load."

    protected void newImage()
{
    LinkedList<Uri> availableImages = new LinkedList<Uri>();


    findInternalImages(availableImages);

    if(availableImages.isEmpty())
    {
        Toast.makeText(this, getString(R.string.error_could_not_load_image), Toast.LENGTH_LONG).show();
        return;
    }

    int index = new Random().nextInt(availableImages.size());
    loadBitmap(availableImages.get(index));
}

protected void findInternalImages(List<Uri> list)
{

    Field[] fields = R.drawable.class.getFields();


    for(Field field: fields)
    {
        //String name = field.getName();

        //if(name.startsWith(FILENAME_IMAGE_PREFIX))
        //{
            //int id = getResources().getIdentifier(name, "drawable", getPackageName());
    for(int j=1;j<13;j++)
    {
            Drawable drawable = getResources().getDrawable(getResources()
                      .getIdentifier("image_"+j, "drawable", getPackageName()));

    }
        //}
    }
}

我的问题是,
当我运行程序它应该显示从绘制文件夹的图像,当我选择之一,那么实际争先恐后应该开始。因此,可以玩的竖锯比赛。

My Problem is,when i run the program it should show images from drawable folder and when i choose the one then actual scrambling should start. so, one can play the jig saw game.

推荐答案

通过检查你的图片都在Android的兼容格式启动,这是造成我的问题开始。我通常坚持现在.png格式。

Start by checking that your images are in a Android compatible format, that was causing me problems to begin with. I normally stick to .png now.

这是code,你将需要修改的图片

This is the code you will need to modify the image

ImageView pwrSwap = (ImageView) beaconitems.findViewById(R.id.yourImageID);
pwrSwap.setImageResource(R.drawable.yourImage);

这篇关于安卓:从调用绘制图像,并显示在屏幕上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 16:44