public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) { ContentResolver cr = context_.ContentResolver; /** 画像をファイルパスから検索 */ BitmapFactory.Options options = new BitmapFactory.Options(); options.InJustDecodeBounds = true; var bitmap = BitmapFactory.DecodeFile(image_[position]); int imageHeight = bitmap.Height; int imageWidth = bitmap.Width; String imageType = options.OutMimeType; int inSampleSize = 1; if (imageHeight > 320 || imageWidth > 240) { int halfHeight = imageHeight / 2; int halfWidth = imageWidth / 2; // Calculate the largest inSampleSize value that is a power of 2 and keeps both // height and width larger than the requested height and width. while ((halfHeight / inSampleSize) >= 320 && (halfWidth / inSampleSize) >= 240) { inSampleSize *= 2; } } options.InSampleSize = inSampleSize; options.InJustDecodeBounds = false; Android.Media.ExifInterface exif = new Android.Media.ExifInterface(image_[position]); //var orientation = int.Parse(exif.GetAttribute(Android.Media.ExifInterface.TagOrientation)); var thumbnail = BitmapFactory.DecodeFile(image_[position], options); Android.Graphics.Matrix mat = new Android.Graphics.Matrix(); if (thumbnail.Width > thumbnail.Height) { mat.SetRotate(90, thumbnail.Width / 2, thumbnail.Height / 2); mat.PreScale(320.0f / thumbnail.Width, 240.0f / thumbnail.Height); } else { mat.PreScale(240.0f / thumbnail.Width, 320.0f / thumbnail.Height); } thumbnail = Android.Graphics.Bitmap.CreateBitmap(thumbnail, 0, 0, thumbnail.Width, thumbnail.Height, mat, true); ((CameraViewHolder)holder).image_.SetImageBitmap(thumbnail); holder.ItemView.Click -= ItemView_Click; holder.ItemView.Click += ItemView_Click; }
private Bitmap Flip(Bitmap source, int sx, int sy) { using (Matrix matrix = new Matrix()) { matrix.PreScale(sx, sy); Bitmap output = Bitmap.CreateBitmap(source, 0, 0, source.Width, source.Height, matrix, false); output.Density = (int)DisplayMetricsDensity.Default; return output; } }
private static Bitmap ReverseBitmap(Bitmap src) { Android.Graphics.Matrix m = new Android.Graphics.Matrix(); m.PreScale(1, -1); Bitmap dst = Bitmap.CreateBitmap(src, 0, 0, src.Width, src.Height, m, false); dst.Density = (int)Android.Util.DisplayMetricsDensity.Default; return(dst); }
public static void Prepend(this AG.Matrix dest, Matrix m) { dest.PreTranslate((float)m.OffsetX, (float)m.OffsetY); dest.PreScale((float)m.M11, (float)m.M22); dest.PreSkew((float)m.M21, (float)m.M12); }
public void DrawImage(IImage image, Rect frame, double alpha = 1.0) { var ii = image as BitmapImage; if (ii != null) { var paint = GetImagePaint(alpha); var isize = new Size(ii.Bitmap.Width, ii.Bitmap.Height); var scale = frame.Size/isize; var m = new Matrix(); m.PreTranslate((float) frame.X, (float) frame.Y); m.PreScale((float) scale.Width, (float) scale.Height); graphics.DrawBitmap(ii.Bitmap, m, paint); } }
public static Bitmap FlipImage(Bitmap bitmap, bool horizontal, bool vertical) { Matrix matrix = new Matrix(); matrix.PreScale(horizontal ? -1 : 1, vertical ? -1 : 1); return Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, matrix, true); }