2015-11-02 88 views
0

我剛剛從codecanyon昨天買了一個益智遊戲源代碼,它不是我所期望的。用戶必須從圖庫中選擇一個圖像來開始拼圖,但我希望以這種方式更改>「選擇拼圖」活動,那麼用戶必須選擇該活動中列出的圖像(而不是從圖庫中,從繪圖中)。如何從益智遊戲中的Drawable中選擇圖像?

進出口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」 ......這就是它

+0

HM。你需要新的活動來顯示你所有的可繪製圖像(所以你不需要打開圖庫) –

+0

首先嚐試學習android和java語言的基礎知識!您需要了解此代碼的大部分內容才能完善它 – behrooz

+0

感謝您的回覆。你能給我舉個例子嗎?以及如何將此代碼與新活動中顯示的可繪製圖像連接起來? – user5514348

回答

0

試試這個,

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