从imageadapter将图像uri发送到裁剪屏幕

时间:2013-07-05 21:55:58

标签: android android-imageview android-adapter

我在一个gallerry应用程序上尝试使用android上的imagecrop。我有标准的图像适配器和图像细节页面。 imagedetail页面上有壁纸和裁剪两个功能。但我可能犯了大错,但我无法理解我如何发送信息并从作物页面获取信息。

我尝试使用以下代码将imageview上的图像发送到图像裁剪屏幕。

    /* image-detail.java */    
    public class imageDetail extends Activity {
            int position;
            private Uri imgUri;
            Intent i;
            ImageView iv;
            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.imagedetail);
                i=getIntent();
                position=(Integer) i.getExtras().get("id");

                iv = (ImageView) findViewById(R.id.imageViewBig);
                iv.setImageResource(ImageAdapter.mThumbIds[position]);

            }
            public boolean onCreateOptionsMenu(Menu menu){
                MenuInflater inflater = getMenuInflater();
                inflater.

inflate(R.menu.detailoption,menu);
            return true;
        }
        public boolean onOptionsItemSelected(MenuItem item){
            if (item.getItemId()==R.id.dowallpaper){
                WallpaperManager myWM=WallpaperManager.getInstance(getApplicationContext());
                try {
                    myWM.setResource(ImageAdapter.mThumbIds[position]);
                    Toast.makeText(getApplicationContext(),"I did it !", Toast.LENGTH_SHORT).show();
                } catch (IOException e) {
                    Toast.makeText(getApplicationContext(), "I can't set the Wallpaper :(", Toast.LENGTH_SHORT).show();
                    e.printStackTrace();
                }
            }
            else if (item.getItemId()==R.id.cropimage){
                final Intent intent = new Intent("com.android.camera.action.CROP");
                imgUri=iv.getResources(); // I can't get URI
                intent.setDataAndType(imgUri, "image/*");
                String messageUri = imgUri.toString();
                Log.e("heyooo", messageUri);
                intent.putExtra("crop", "true");
                //indicate aspect of desired crop
                intent.putExtra("aspectX", 1);
                intent.putExtra("aspectY", 1);
                //indicate output X and Y
                intent.putExtra("outputX", 256);
                intent.putExtra("outputY", 256);
                //retrieve data on return
                //intent.putExtra("return-data", true);
                //start the activity - we handle returning in onActivityResult
                startActivityForResult(intent, 2);

            }
            return true;



}

}

0 个答案:

没有答案