Beispiel #1
0
            public override void onPictureTaken(sbyte[] bytes)
            {
                Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.Length);

                if (bitmap != null)
                {
                    outerInstance.showPicture(bitmap);
                }
                else
                {
                    Toast.makeText(outerInstance, [email protected]_picture_failed, Toast.LENGTH_LONG).show();
                }
            }
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;
                }
            }
        }
Beispiel #3
0
        private Bitmap captureBitmap(I420Frame i420Frame)
        {
            YuvImage yuvImage            = i420ToYuvImage(i420Frame);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            Rect rect = new Rect(0, 0, yuvImage.Width, yuvImage.Height);

            // Compress YuvImage to jpeg
            yuvImage.compressToJpeg(rect, 100, stream);

            // Convert jpeg to Bitmap
            sbyte[] imageBytes = stream.toByteArray();
            Bitmap  bitmap     = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.Length);
            Matrix  matrix     = new Matrix();

            // Apply any needed rotation
            matrix.postRotate(i420Frame.rotationDegree);
            bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, matrix, true);

            return(bitmap);
        }
        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)
                    {
                    }
                }
            }
        }
Beispiel #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private ImageAndroid(java.net.URL imageUrl) throws java.io.IOException
        private ImageAndroid(URL imageUrl)
        {
            bitmap = BitmapFactory.decodeStream((InputStream)imageUrl.Content);
        }
Beispiel #6
0
 private ImageAndroid(string filePath)
 {
     bitmap = BitmapFactory.decodeFile(filePath);
 }
Beispiel #7
0
 private ImageAndroid(File imageFile)
 {
     bitmap = BitmapFactory.decodeFile(imageFile.AbsolutePath);
 }