public override void onActivityResult(int requestCode, int resultCode, Intent data)
		{
			base.onActivityResult(requestCode, resultCode, data);

			if (requestCode == REQUEST_CODE_ACTION_PICK)
			{
				if (data != null)
				{
					Uri uri = data.Data;
					System.IO.Stream @is = null;
					try
					{
						@is = ContentResolver.openInputStream(uri);
					}
					catch (FileNotFoundException e)
					{
						Console.WriteLine(e.ToString());
						Console.Write(e.StackTrace);
						return;
					}

					try
					{
					BitmapFactory.Options opts = new BitmapFactory.Options();
					opts.inJustDecodeBounds = false;
					opts.inSampleSize = 1;
					opts.inPreferredConfig = Bitmap.Config.RGB_565;
					Bitmap bm = BitmapFactory.decodeStream(@is, null, opts);
					mImageView.ImageBitmap = bm;
					}
					catch (System.OutOfMemoryException e)
					{
						Console.WriteLine(e.ToString());
						Console.Write(e.StackTrace);
						return;
					}

					ContentResolver cr = ContentResolver;
					Cursor c = cr.query(uri, new string[] {MediaStore.Images.Media.DATA}, null, null, null);
					if (c == null || c.Count == 0)
					{
						return;
					}
					c.moveToFirst();
					int columnIndex = c.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
					string text = c.getString(columnIndex);
					mTextView.Text = text;
				}
			}
		}
Beispiel #2
0
        public override void onActivityResult(int requestCode, int resultCode, Intent data)
        {
            base.onActivityResult(requestCode, resultCode, data);

            if (requestCode == REQUEST_CODE_ACTION_PICK)
            {
                if (data != null)
                {
                    Uri uri = data.Data;
                    System.IO.Stream @is = null;
                    try
                    {
                        @is = ContentResolver.openInputStream(uri);
                    }
                    catch (FileNotFoundException e)
                    {
                        Console.WriteLine(e.ToString());
                        Console.Write(e.StackTrace);
                        return;
                    }

                    try
                    {
                        BitmapFactory.Options opts = new BitmapFactory.Options();
                        opts.inJustDecodeBounds = false;
                        opts.inSampleSize       = 1;
                        opts.inPreferredConfig  = Bitmap.Config.RGB_565;
                        Bitmap bm = BitmapFactory.decodeStream(@is, null, opts);
                        mImageView.ImageBitmap = bm;
                    }
                    catch (System.OutOfMemoryException e)
                    {
                        Console.WriteLine(e.ToString());
                        Console.Write(e.StackTrace);
                        return;
                    }

                    ContentResolver cr = ContentResolver;
                    Cursor          c  = cr.query(uri, new string[] { MediaStore.Images.Media.DATA }, null, null, null);
                    if (c == null || c.Count == 0)
                    {
                        return;
                    }
                    c.moveToFirst();
                    int    columnIndex = c.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                    string text        = c.getString(columnIndex);
                    mTextView.Text = text;
                }
            }
        }
        protected internal override Bitmap doInBackground(params Uri[] @params)
        {
            System.IO.Stream @in = null;
            try
            {
                @in = openConnection(@params[0]);
                BitmapFactory.Options opt = new BitmapFactory.Options();
                opt.inJustDecodeBounds = true;
                opt.inPreferredConfig  = Bitmap.Config.RGB_565;
                BitmapFactory.decodeStream(@in, null, opt);
                @in.Close();
                int width  = opt.outWidth;
                int height = opt.outHeight;
                int scale  = 1;
                while (width > MAX_ICON_SIZE && height > MAX_ICON_SIZE)
                {
                    width  /= 2;
                    height /= 2;
                    scale  *= 2;
                }
                opt.inJustDecodeBounds = false;
                opt.inSampleSize       = scale;
                @in = openConnection(@params[0]);
                Bitmap bitmap = BitmapFactory.decodeStream(@in, null, opt);
                if (bitmap == null)
                {
                    return(null);
                }

                // Add the bitmap to cache.
                if (mIconsCache != null)
                {
                    mIconsCache.put(@params[0], bitmap);
                }
                //return the bitmap only if target image view is still valid
                if (@params[0].Equals(mImageView.Tag))
                {
                    return(bitmap);
                }
                else
                {
                    return(null);
                }
            }
            catch (IOException)
            {
                // Failed to retrieve icon, ignore it
                return(null);
            }
            finally
            {
                if (@in != null)
                {
                    try
                    {
                        @in.Close();
                    }
                    catch (IOException)
                    {
                    }
                }
            }
        }