0

我在一个gallery应用程序上尝试了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;



}

}
4

0 回答 0