/// <summary> /// 将图片逆时针旋转degress度,返回旋转后的图片对象。 /// </summary> /// <param name="img">图片</param> /// <param name="x">旋转中心x坐标,默认为图片中点</param> /// <param name="y">旋转中心y坐标,默认为图片中点</param> /// <param name="degree">旋转角度。</param> /// <returns></returns> public ImageWrapper rotate(ImageWrapper img, float x, float y, float degree) { var matrix = new Matrix(); matrix.PostRotate(degree, x, y); return(ImageWrapper.OfBitmap(Bitmap.CreateBitmap(img.Bitmap, 0, 0, img.Width, img.Height, matrix, true))); }
public Bitmap getRoundedShape(Bitmap scaleBitmapImage) { int targetWidth = 110; int targetHeight = 110; Bitmap targetBitmap = Bitmap.CreateBitmap(targetWidth, targetHeight, Bitmap.Config.Argb4444); Canvas canvas = new Canvas(targetBitmap); Android.Graphics.Path path = new Android.Graphics.Path(); path.AddCircle(((float)targetWidth - 1) / 2, ((float)targetHeight - 1) / 2, (Math.Min(((float)targetWidth), ((float)targetHeight)) / 2), Android.Graphics.Path.Direction.Ccw); canvas.ClipPath(path); Bitmap sourceBitmap = scaleBitmapImage; canvas.DrawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.Width, sourceBitmap.Height), new Rect(0, 0, targetWidth, targetHeight), null); return(targetBitmap); }
/// <summary> /// 从图片img的位置(x, y)处剪切大小为w * h的区域,并返回该剪切区域的新图片。 /// </summary> /// <param name="img">图片</param> /// <param name="x">剪切区域的左上角横坐标</param> /// <param name="y">剪切区域的左上角纵坐标</param> /// <param name="x2">剪切区域的宽度</param> /// <param name="y2">剪切区域的高度</param> /// <returns></returns> public ImageWrapper clip(ImageWrapper img, int x, int y, int x2, int y2) { var w = x2 - x; var h = y2 - y; return(ImageWrapper.OfBitmap(Bitmap.CreateBitmap(img.Bitmap, x, y, w, h))); }
private SkiaSharp.SKSurface CreateSurface(out SkiaSharp.SKImageInfo info) { // get context details info = this.info; // if there are no pixels, clean up and return if (info.Width == 0 || info.Height == 0) { Dispose(); return(null); } // if the memory size has changed, then reset the underlying memory if (bitmap?.Handle == IntPtr.Zero || bitmap?.Width != info.Width || bitmap?.Height != info.Height) { FreeBitmap(); } // create the bitmap data if we need it if (bitmap == null) { bitmap = ABitmap.CreateBitmap(info.Width, info.Height, ABitmap.Config.Argb8888); } return(SkiaSharp.SKSurface.Create(info, bitmap.LockPixels(), info.RowBytes)); }
//LA ACTIVIDAD RESULTADO DEL INTENTO DE ARRIBA protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if ((requestCode == PickImageId) && (resultCode == Result.Ok) && (data != null)) { ISharedPreferences preff = PreferenceManager.GetDefaultSharedPreferences(this); var jee = preff.GetString("Usuario", ""); //SE AGREGA LA IMAGEN AL IMAGEVIEW Y SU URL INTERNO string path; Uri uri = data.Data; path = GetPathToImage(uri); Bitmap cool = BitmapFactory.DecodeFile(path); logoimage.SetImageBitmap(cool); //MEDIANTE EL URL INTERNO SE CREA UN BITMAP INTERNO PARA POSTERIORMENTE SER CONVERTIDO EN BYTE[] Y ALMACENADO EN MYSQL Bitmap seco = Bitmap.CreateBitmap(BitmapFactory.DecodeFile(path)); var nel = new MemoryStream(); seco.Compress(Bitmap.CompressFormat.Png, 0, nel); byte [] bitmapData = nel.ToArray(); //FORMA CORRECTA PARA SUBIR UNA IMAGEN A MYSQL var final = new MySqlCommand("UPDATE `TapFood`.`Restaurantes` SET `LogoRestaurante`= @logo WHERE(`IdRestaurante` = @iduser)", conn); final.Parameters.Add(new MySqlParameter("logo", MySqlDbType.MediumBlob)).Value = bitmapData; final.Parameters.Add(new MySqlParameter("iduser", MySqlDbType.String)).Value = jee.ToString(); final.ExecuteNonQuery(); Toast.MakeText(this, "Listo, hemos actualizado la imagen".ToString(), ToastLength.Long).Show(); } }
private Bitmap CreateBufferImage() { if (paths == null || paths.Count == 0) { return(null); } var size = new SizeF(Width, Height); var image = Bitmap.CreateBitmap((int)size.Width, (int)size.Height, Bitmap.Config.Argb8888); using (var canvas = new Canvas(image)) using (var paint = new Paint()) { paint.StrokeJoin = Paint.Join.Round; paint.StrokeCap = Paint.Cap.Round; paint.AntiAlias = true; paint.SetStyle(Paint.Style.Stroke); foreach (var path in paths) { paint.Color = path.Color; paint.StrokeWidth = path.Width * ScreenDensity; canvas.DrawPath(path.Path, paint); path.IsDirty = false; } } return(image); }
public void DrawBitmap(Bitmap bmp, Rect sourceRect, Rect rect) { var bitmap = AndroidBitmap.CreateBitmap(bmp.Width, bmp.Height, AndroidBitmap.Config.Argb8888); bitmap.SetPixels(bmp.Bytes.ToIntArray(), 0, bmp.Width, 0, 0, bmp.Width, bmp.Height); canvas.DrawBitmap(bitmap, sourceRect.ToRect(), rect.ToRectF(), null); }
public IBitmapImplementation Crop(IntRectangle cropArea) { return(new BitmapImplementation( AndroidBitmap.CreateBitmap( Bitmap, cropArea.Left, cropArea.Top, cropArea.Width, cropArea.Height))); }
public BitmapImplementation(Color4[] data, int width, int height) { var colors = new int[data.Length]; for (int i = 0; i < data.Length; i++) { var pixel = data[i]; colors[i] = Color4.CreateArgb(pixel.A, pixel.R, pixel.G, pixel.B); } Bitmap = AndroidBitmap.CreateBitmap(colors, width, height, AndroidBitmap.Config.Argb8888); Bitmap.HasAlpha = Lime.Bitmap.AnyAlpha(data); }
private MemoryStream RenderToBitmapStreamPrivate(IViewport viewport, IEnumerable <ILayer> layers) { Bitmap target = Bitmap.CreateBitmap((int)viewport.Width, (int)viewport.Height, Bitmap.Config.Argb8888); var canvas = new Canvas(target); Render(canvas, viewport, layers, ShowDebugInfoInMap); var stream = new MemoryStream(); target.Compress(Bitmap.CompressFormat.Png, 100, stream); target.Dispose(); canvas.Dispose(); return(stream); }
public static bool Reshape(ref ANDROIDBITMAP bmp, ANDROIDBITMAP.Config fmt, int w, int h) { if (w <= 0 || w <= 0) { if (bmp == null) { return(false); } System.Threading.Interlocked.Exchange(ref bmp, null)?.Dispose(); return(true); } if (bmp == null) { bmp = ANDROIDBITMAP.CreateBitmap(w, h, fmt); return(true); } return(Reshape(bmp, fmt, w, h)); }
/// <summary> /// 连接两张图片,并返回连接后的图像。如果两张图片大小不一致,小的那张将适当居中。 /// </summary> /// <param name="img1">图片1</param> /// <param name="img2">图片2</param> /// <param name="direction">连接方向,默认为"RIGHT",可选的值有: /// LEFT 将图片2接到图片1左边 /// RIGHT 将图片2接到图片1右边 /// TOP 将图片2接到图片1上边 /// BOTTOM 将图片2接到图片1下边 /// </param> /// <returns></returns> public ImageWrapper concat(ImageWrapper img1, ImageWrapper img2, GravityFlags direction) { int width; int height; if (direction == GravityFlags.Left || direction == GravityFlags.Top) { var tmp = img1; img1 = img2; img2 = tmp; } if (direction == GravityFlags.Left || direction == GravityFlags.Right) { width = img1.Width + img2.Width; height = Math.Max(img1.Height, img2.Height); } else { width = Math.Max(img1.Width, img2.Height); height = img1.Height + img2.Height; } var bitmap = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888); var canvas = new Canvas(); var paint = new Paint(); if (direction != GravityFlags.Left && direction != GravityFlags.Right) { return(ImageWrapper.OfBitmap(bitmap)); } canvas.DrawBitmap(img1.Bitmap, (width - img1.Width) / 2, 0, paint); canvas.DrawBitmap(img2.Bitmap, (width - img2.Width) / 2, img1.Height, paint); return(ImageWrapper.OfBitmap(bitmap)); }
public ANDROIDBITMAP CreateCompatibleBitmap() { return(ANDROIDBITMAP.CreateBitmap(_Info.Width, _Info.Height, _Compatible)); }