コード例 #1
0
ファイル: MainActivity.cs プロジェクト: pulmuone/FileData2
        private void ImagePrint(Android.Net.Uri uri)
        {
            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Q)
            {
                var source = ImageDecoder.CreateSource(this.ContentResolver, uri);
                var bitmap = ImageDecoder.DecodeBitmap(source);
                imageview.SetImageBitmap(bitmap);
            }
            else
            {
                imageview.SetImageURI(uri);

                //var cursor = this.ContentResolver.Query(uri, null, null, null, null);

                //if (cursor != null)
                //{
                //    cursor.MoveToNext();
                //    // 이미지 경로를 가져온다.
                //    var index = cursor.GetColumnIndexOrThrow(MediaStore.Images.Media.InterfaceConsts.Data);
                //    var source = cursor.GetString(index);

                //    //var contentUri = ContentUris.WithAppendedId(MediaStore.Images.Media.ExternalContentUri, id);

                //    // 이미지를 생성한다.
                //    var bitmap = BitmapFactory.DecodeFile(source);
                //    imageview.SetImageBitmap(bitmap);
                //}
            }
        }
コード例 #2
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            if (resultCode == Result.Ok && requestCode == CAPTURE_PHOTO && ImageUri != null)
            {
                Android.Util.Log.Info("CameraScanning", "Getting Picture");

                var src = ImageDecoder.CreateSource(ContentResolver, ImageUri);

                Bitmap img = ImageDecoder.DecodeBitmap(src, new OnHeaderDecodedListener());

                CurrImage = ImageProcessing.Grayscale_ColorMatrixColorFilter(img);

                img.Recycle();
                img.Dispose();

                imageView1.SetImageBitmap(CurrImage);

                Java.IO.File xFile = new Java.IO.File(ImageUri.Path);
                if (xFile.Exists())
                {
                    xFile.Delete();
                }
                ImageUri = null;
            }
        }
コード例 #3
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var view = convertView;

            if (view == null)
            {
                view = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.userRow, parent, false);

                var photo = view.FindViewById <ImageView>(Resource.Id.photoImageView);

                view.Tag = new ViewHolder()
                {
                    Photo = photo
                };
            }

            var holder = (ViewHolder)view.Tag;

            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Q)
            {
                var source = ImageDecoder.CreateSource(parent.Context.ContentResolver, _photoList[position]);
                var bitmap = ImageDecoder.DecodeBitmap(source);
                holder.Photo.SetImageBitmap(bitmap);
            }
            else
            {
                holder.Photo.SetImageURI(_photoList[position]);
            }

            return(view);
        }
コード例 #4
0
        //Result
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            try
            {
                if (requestCode == CropImage.CropImageActivityRequestCode && resultCode == Result.Ok)
                {
                    //wael
                    var result = CropImage.GetActivityResult(data);
                    if (result.IsSuccessful)
                    {
                        var resultUri = result.Uri;

                        if (!string.IsNullOrEmpty(resultUri.Path))
                        {
                            File file2    = new File(resultUri.Path);
                            var  photoUri = FileProvider.GetUriForFile(this, PackageName + ".fileprovider", file2);

                            //MNiceArtEditor?.AddImage(bitmap);
                            //GlideImageLoader.LoadImage(this, resultUri.Path, Image, ImageStyle.CenterCrop, ImagePlaceholders.Drawable);
                        }
                        else
                        {
                            Toast.MakeText(this, GetText(Resource.String.Lbl_something_went_wrong), ToastLength.Long).Show();
                        }
                    }

                    if (result.IsSuccessful)
                    {
                        ResultUri = result.Uri;
                        try
                        {
                            if (!string.IsNullOrEmpty(ResultUri.Path))
                            {
                                ImageDecoder.Source source = ImageDecoder.CreateSource(ContentResolver, ResultUri);
                                if (source != null)
                                {
                                    var bitmap = ImageDecoder.DecodeBitmap(source);
                                    MNiceArtEditor?.AddImage(bitmap);
                                }
                            }
                            else
                            {
                                Toast.MakeText(this, GetText(Resource.String.Lbl_Error_Path_Image), ToastLength.Long).Show();
                            }
                        }
                        catch (FileNotFoundException e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #5
0
        public static Bitmap ProcessGalleryResult(Context context, Intent data)
        {
            // TODO: What in the world is the correct way to import images these days?
            return(MediaStore.Images.Media.GetBitmap(context.ContentResolver, data.Data));

            var    imageUri = data.Data;
            Bitmap bitmap   = null;

            if (imageUri != null)
            {
                try
                {
                    var source = ImageDecoder.CreateSource(context.ContentResolver, imageUri);
                    bitmap = ImageDecoder.DecodeBitmap(source);
                }
                catch (Exception)
                {
                }
            }

            return(bitmap);
        }
コード例 #6
0
ファイル: AssetLoader.cs プロジェクト: kraxarn/CubeQuest
 private static Bitmap DecodeBitmap(string path) =>
 Build.VERSION.SdkInt >= BuildVersionCodes.P
         ? ImageDecoder.DecodeBitmap(ImageDecoder.CreateSource(assets, path))
         : BitmapFactory.DecodeStream(assets.Open(path));