2017-08-03 95 views
-1

如何使用兩個不同的按鈕在兩個單獨的圖像視圖上添加兩個圖像?如何使用兩個不同的按鈕在兩個單獨的圖像視圖上添加兩個圖像

我使用下面的代碼來裁剪和設置圖像,僅用於單個按鈕和單個圖像視圖。

那麼我應該怎麼做兩個單獨的圖像視圖與單個屏幕上的兩個單獨的按鈕?

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if(requestCode == 0 && resultCode == RESULT_OK) 
     CropImage(); 
    else if(requestCode == 2) 
    { 
     if(data != null) 
     { 
      uri = data.getData(); 
      CropImage(); 
     } 
    } 
    else if (requestCode == 1) 
    { 
     if(data != null) 
     { 
      Bundle bundle = data.getExtras(); 
      Bitmap bitmap = bundle.getParcelable("data"); 
      ImageView imageView = (ImageView) findViewById(R.id.imgHead); 
      imageView.setImageBitmap(bitmap); 
     } 
    } 
} 


private void CropImage() { 

    try{ 
     CropIntent = new Intent("com.android.camera.action.CROP"); 
     CropIntent.setDataAndType(uri,"image/*"); 

     CropIntent.putExtra("crop","true"); 
     CropIntent.putExtra("outputX",180); 
     CropIntent.putExtra("outputY",180); 
     CropIntent.putExtra("aspectX",3); 
     CropIntent.putExtra("aspectY",3); 
     CropIntent.putExtra("scaleUpIfNeeded",true); 
     CropIntent.putExtra("return-data",true); 

     startActivityForResult(CropIntent,1); 
    } 
    catch (ActivityNotFoundException ex) 
    { 

    } 

} 


private void GalleryOpen() { 
    GalIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 
    startActivityForResult(Intent.createChooser(GalIntent,"Select Image from Gallery"),2); 

} 
+0

嗨Sandeep,我刪除了圖像鏈接,因爲它似乎只是你包含的代碼的一部分的屏幕截圖。如果這是不正確的,請在相關代碼中作爲文本[編輯],而不是*圖像。 – whrrgarbl

回答

3

您可以保留一個全局布爾變量buttonOne並將其設置爲默認值false。現在,如果buttonOne被點擊,請設置buttonOne =True。在此之後,在你的onActivityResult()方法,添加其他條件語句

if (buttonOne){ 
imageViewOne.setImage(); 
} 
else if(!buttonOne){ 
    imageViewTwo.setImage(); 
} 

我希望這會工作,如果我理解正確你的問題。

+0

我還沒有得到它可以請你幫我 –

相關問題