簡體   English   中英

如何在益智游戲中從Drawables中選擇圖像?

[英]How to Select image from Drawables in puzzle game?

我昨天剛從codecanyon購買了一個益智游戲的源代碼,它不是我期望的。 用戶必須從圖庫中選擇一個圖像才能啟動拼圖,但是我希望通過這種方式>活動“選擇拼圖”對其進行更改,然后用戶必須選擇該活動中列出的圖像(而不是從圖庫,可繪制對象中)。

我90%的人確定這是“從圖庫中選擇”按鈕的功能代碼

    public void pickImageOnClick(View view){
        shouldSwitch = false;

        //startActivityForResult(i, PHOTO_FROM_MEMORY_REQUESTED); 
        Intent localIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        localIntent.setType("image/*");
        localIntent.setAction(Intent.ACTION_GET_CONTENT);
        localIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
        startActivityForResult(localIntent, PHOTO_FROM_MEMORY_REQUESTED);
    }

    private File createGameFile(String part, String ext) throws Exception
    {
        //Getting external storage path, and .temp directory in it.
        File mainDir= Environment.getExternalStorageDirectory();
        mainDir=new File(mainDir.getAbsolutePath()+MAIN_FOLDER);

        //If .temp does not exists, it is created.
        if(!mainDir.exists()) mainDir.mkdir();       

        return new File(mainDir.getAbsolutePath().toString(), part+ext);
       // return File.createTempFile(part, ext, mainDir);

    }

    public void playOnClick(View View){
        Intent intent = new Intent(this, PuzzleActivity.class);
        String[] gameSizes = getResources().getStringArray(R.array.gamesizes);
        intent.putExtra(EXTRA_GAMESIZE, gameSizes[gameSizeSpinner.getSelectedItemPosition()]);
        intent.putExtra(EXTRA_IMGURI, imageUri);
        //Toast.makeText(getApplicationContext(), "Hi"+imageUri, 400).show();
        int orientation;    //Determining screen orientation.
        orientation = (selectedImage.getWidth()>selectedImage.getHeight()) ? 
                GameBoard.ORIENTATION_HORIZONTAL : GameBoard.ORIENTATION_PORTRAIT;
        intent.putExtra(EXTRA_BOARD_ORIENTATION, orientation);

//      String str = orientation == 0 ? "PORTRAIT" : "HORIZONTAL";
//      Log.d("KAMIL", "Orientation : " + str);

        shouldSwitch = true;
        startActivity(intent);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if(requestCode == PHOTO_FROM_MEMORY_REQUESTED && resultCode == RESULT_OK){
            //updateSelectedPicture(data.getData());
            try
            {
            imageUri = data.getData();
            //scaleImage(uri, 2048);

            BitmapFactory.Options options=new BitmapFactory.Options();
            options.inSampleSize = 9;

            //Opening the input stream and receiving Bitmap.
            InputStream imageStream = getContentResolver().openInputStream(imageUri);
            //selectedImage = BitmapFactory.decodeStream(imageStream);
            selectedImage = BitmapFactory.decodeStream(imageStream,null,options);
            //.selectedImage = BitmapFactory.decodeFile(i);
            //Bitmap thumbnail = BitmapFactory.decodeFile(mFileTemp.getPath());
            if (selectedImage.getHeight() > 1200)
                selectedImage = Bitmap.createScaledBitmap(selectedImage, selectedImage.getWidth() * 1200 / selectedImage.getHeight(), 1200, false);
            //Toast.makeText(getApplicationContext(), ""+selectedImage.getHeight(), 400).show();
            System.gc();
            playButton.setEnabled(true);
            }
              catch (FileNotFoundException localFileNotFoundException)
              {
                localFileNotFoundException.printStackTrace();
              }
        }    

“ pickImageOnClick” ...就這樣

嘗試這個,

 ImageView imageview = (ImageView)findViewById(R.id.imageView);
 imageview.setImageDrawable(getResources().getDrawable(R.drawable.ic_launcher));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM