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); //} } }
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; } }
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); }
//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); } }
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); }
private static Bitmap DecodeBitmap(string path) => Build.VERSION.SdkInt >= BuildVersionCodes.P ? ImageDecoder.DecodeBitmap(ImageDecoder.CreateSource(assets, path)) : BitmapFactory.DecodeStream(assets.Open(path));