2016-07-02 20 views
0

写真を保存する際に問題が発生した場合は、私は助けが必要です。私はイメージを編集するためにadobe photo sdkを使用しています。ドキュメントリンク(https://creativesdk.adobe.com/docs/android/#/articles/imageediting/index.html)。彼らは、.withOutput(Uri)を使って私が作成したイメージを保存しますが、エラーが発生したイメージを取得します。画像をファイルに保存するandroid

public class MainActivity extends AppCompatActivity { 
    private static final int IMG_CODE_EDIT = 263; 
    private Button mPickbtn; 
    private Button mCapturebtn; 
    private static int RESULT_LOAD_IMAGE = 1; 
    private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100; 
    private String mCurrentPhotoPath; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     mPickbtn = (Button) findViewById(R.id.pick_image); 
     mCapturebtn = (Button) findViewById(R.id.button2); 

     Intent cdsIntent = AdobeImageIntent.createCdsInitIntent(getBaseContext(), "CDS"); 
     startService(cdsIntent); 

    } 

    public void takePicture(View view) { 
     // create Intent to take a picture and return control to the calling application 
     Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
     // start the image capture Intent 
     startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); 
    } 

    public void onClick(View view) { 

     Intent i = new Intent(
       Intent.ACTION_PICK, 
       android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 

     startActivityForResult(i, RESULT_LOAD_IMAGE); 
    } 

    @Override 
    protected void onResume() { 
     super.onResume(); 
    } 

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

     //Gets the gallery image uri 
     if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) { 
      Uri selectedImage = data.getData(); 
      String[] filePathColumn = {MediaStore.Images.Media.DATA}; 

      Cursor cursor = getContentResolver().query(selectedImage, 
        filePathColumn, null, null, null); 
      cursor.moveToFirst(); 

      int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 
      String picturePath = cursor.getString(columnIndex); 
      cursor.close(); 

      editPic(selectedImage); 
     } 

     //picture from camera 
     if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { 
      if (resultCode == RESULT_OK) { 
       Uri mPicTaken = data.getData(); 
       editPic(mPicTaken); 
      } else if (resultCode == RESULT_CANCELED) { 
       // User cancelled the image capture 
      } else { 
       // Image capture failed, advise user 
      } 
     } 

     if (resultCode == RESULT_OK) { 
      switch (requestCode) { 

       /* 4) Make a case for the request code we passed to startActivityForResult() */ 
       case 263: 

        /* 5) Show the image! */ 
        Uri editedImageUri = data.getData(); 
        Intent intent = new Intent("com.ayyogames.photoapp.Share"); 
        intent.putExtra("imageUri", editedImageUri); 
        startActivity(intent); 

        break; 
      } 
     } 

    } 

public void editPic(Uri uri) { 

     // Create the File where the photo should go 
     File photoFile = null; 
     try { 
      photoFile = createImageFile(); 
     } catch (IOException ex) { 
      // Error occurred while creating the File 
     } 

     if (photoFile != null) { 
      Uri photoURI = FileProvider.getUriForFile(this, 
        "com.ayyogames.photoapp.fileprovider", 
        photoFile); 

      Intent intent = new AdobeImageIntent.Builder(this) 
        .setData(uri) 
        .withOutputSize(MegaPixels.Mp10) 
        .withOutputQuality(100) 
        .withOutput(photoURI) 
        .build(); 

      startActivityForResult(intent, IMG_CODE_EDIT); 
     } 
    } 


private File createImageFile() throws IOException { 
     // Create an image file name 
     String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); 
     String imageFileName = "JPEG_" + timeStamp + "_"; 
     File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); 
     File image = File.createTempFile(
       imageFileName, /* prefix */ 
       ".jpg",   /* suffix */ 
       storageDir  /* directory */ 
     ); 

     // Save a file: path for use with ACTION_VIEW intents 
     mCurrentPhotoPath = "file:" + image.getAbsolutePath(); 
     return image; 
    } 

シェアクラスは

public class Share extends AppCompatActivity { 

    private ImageView mEditedImageView; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_share); 

     Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar); 
     setSupportActionBar(myToolbar); 
     ActionBar ab = getSupportActionBar(); 
     ab.setDisplayHomeAsUpEnabled(true); 

     mEditedImageView = (ImageView) findViewById(R.id.editedImageView); 

     Intent intent = getIntent(); 
     Uri uri = intent.getParcelableExtra("imageUri"); 

     mEditedImageView.setImageURI(uri); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 

     MenuInflater inflater = getMenuInflater(); 
     inflater.inflate(R.menu.main_menu,menu); 

     return true; 
    } 
} 

答えて

0

Image Editor developer guideは現在、あなたがUriwithOutput()に渡すべきであると述べているが、これは正しくありません。

Fileを渡して試してみてください。

​​

Fileコンストラクタへのあなたの引数はあなたが望むものは何でも場所に変更する必要があります。

関連する問題