private static Stretch GetStretch(Xamarin.Forms.Aspect aspect) { switch (aspect) { case Xamarin.Forms.Aspect.AspectFill: return(Stretch.UniformToFill); case Xamarin.Forms.Aspect.Fill: return(Stretch.Fill); default: return(Stretch.Uniform); } }
public ImageSlideAdapter(Context _context, List <string> _imageItems, Xamarin.Forms.Aspect aspect) { imageItems = _imageItems; context = _context; switch (aspect) { case Xamarin.Forms.Aspect.Fill: scaleType = ImageView.ScaleType.FitXy; break; case Xamarin.Forms.Aspect.AspectFill: scaleType = ImageView.ScaleType.CenterCrop; break; case Xamarin.Forms.Aspect.AspectFit: scaleType = ImageView.ScaleType.FitCenter; break; } }
public void DrawImage(IImage image, float x, float y, float width, float height, Xamarin.Forms.Aspect aspect) { if (image != null) { CGImage cgImage = ((Image)image).NativeImage; if (cgImage != null) { if (aspect == Xamarin.Forms.Aspect.Fill) { context.DrawImage(new CGRect(x, y, width, height), cgImage); } else { Xamarin.Forms.Size bounding = new Xamarin.Forms.Size(width, height); if (aspect == Xamarin.Forms.Aspect.AspectFill) { Xamarin.Forms.Rectangle imageBox = MathHelper.Fill(new Xamarin.Forms.Rectangle(Xamarin.Forms.Point.Zero, image.Size), bounding); using (CGImage newImage = cgImage.WithImageInRect(new CGRect(imageBox.X, imageBox.Y, imageBox.Width, imageBox.Height))) context.DrawImage(new CGRect(x, y, width, height), newImage); } else { Xamarin.Forms.Rectangle boundingBox = MathHelper.Fit(image.Size, new Xamarin.Forms.Rectangle(x, y, width, height)); context.DrawImage(new CGRect(boundingBox.X, boundingBox.Y, boundingBox.Width, boundingBox.Height), cgImage); } } } context.DrawImage(new CGRect(x, y, width, height), cgImage); } }
public void DrawImage(IImage image, float x, float y, float width, float height, Xamarin.Forms.Aspect aspect) { if (image != null) { CanvasBitmap bitmap = ((Image)image).NativeBitmap; if (bitmap != null) { if (aspect == Xamarin.Forms.Aspect.Fill) { ds.DrawImage(bitmap, new Rect(x, y, width, height)); } else { Xamarin.Forms.Size bounding = new Xamarin.Forms.Size(width, height); if (aspect == Xamarin.Forms.Aspect.AspectFill) { Xamarin.Forms.Rectangle imageBox = MathHelper.Fill(new Xamarin.Forms.Rectangle(Xamarin.Forms.Point.Zero, image.Size), bounding); ds.DrawImage(bitmap, new Rect(x, y, width, height), new Rect(imageBox.X, imageBox.Y, imageBox.Width, imageBox.Height)); } else { Xamarin.Forms.Rectangle boundingBox = MathHelper.Fit(image.Size, new Xamarin.Forms.Rectangle(x, y, width, height)); ds.DrawImage(bitmap, new Rect(boundingBox.X, boundingBox.Y, boundingBox.Width, boundingBox.Height)); } } } } }
public void DrawImage(IImage image, float x, float y, float width, float height, Xamarin.Forms.Aspect aspect) { if (image != null) { Bitmap bitmap = ((Image)image).NativeImage; if (bitmap != null) { if (aspect == Xamarin.Forms.Aspect.Fill) { using (RectF rect = new RectF(x, y, x + width - 1, y + height - 1)) canvas.DrawBitmap(bitmap, null, rect, null); } else { Xamarin.Forms.Size bounding = new Xamarin.Forms.Size(width, height); if (aspect == Xamarin.Forms.Aspect.AspectFill) { Xamarin.Forms.Rectangle imageBox = MathHelper.Fill(new Xamarin.Forms.Rectangle(Xamarin.Forms.Point.Zero, image.Size), bounding); using (RectF rectB = new RectF(x, y, x + width - 1, y + height - 1)) using (Rect rectI = new Rect((int)imageBox.X, (int)imageBox.Y, (int)imageBox.X + (int)imageBox.Width - 1, (int)imageBox.Y + (int)imageBox.Height - 1)) canvas.DrawBitmap(bitmap, rectI, rectB, null); } else { Xamarin.Forms.Rectangle boundingBox = MathHelper.Fit(image.Size, new Xamarin.Forms.Rectangle(x, y, width, height)); using (RectF rect = new RectF((float)boundingBox.X, (float)boundingBox.Y, (float)boundingBox.X + (float)boundingBox.Width - 1, (float)boundingBox.Y + (float)boundingBox.Height - 1)) canvas.DrawBitmap(bitmap, null, rect, null); } } } } }