public static bool Reshape(ANDROIDBITMAP bmp, ANDROIDBITMAP.Config fmt, int w, int h) { if (bmp == null) { throw new ArgumentNullException(nameof(bmp)); } if (fmt == null) { throw new Diagnostics.PixelFormatNotSupportedException(fmt, nameof(fmt)); } if (w <= 0) { throw new ArgumentOutOfRangeException(nameof(w)); } if (h <= 0) { throw new ArgumentOutOfRangeException(nameof(h)); } if (bmp.Width == w && bmp.Height == h && bmp.GetConfig() == fmt) { return(false); } if (!bmp.IsMutable) { throw new ArgumentException(nameof(bmp)); } bmp.Reconfigure(w, h, fmt); return(true); }
public Bitmap ToBitmap(Bitmap.Config config) { System.Drawing.Size size = Size; if (config == Bitmap.Config.Argb8888) { Bitmap result = Bitmap.CreateBitmap(size.Width, size.Height, Bitmap.Config.Argb8888); using (BitmapArgb8888Image bi = new BitmapArgb8888Image(result)) using (Image <Rgba, Byte> tmp = ToImage <Rgba, Byte>()) { tmp.Copy(bi, null); } return(result); } else if (config == Bitmap.Config.Rgb565) { Bitmap result = Bitmap.CreateBitmap(size.Width, size.Height, Bitmap.Config.Rgb565); using (BitmapRgb565Image bi = new BitmapRgb565Image(result)) using (Image <Bgr, Byte> tmp = ToImage <Bgr, Byte>()) bi.ConvertFrom(tmp); return(result); } else { throw new NotImplementedException("Only Bitmap config of Argb888 or Rgb565 is supported."); } }
public static PixelFormat ToInterop(ANDROIDBITMAP.Config fmt, bool isPremultiplied, PixelFormat?defFmt = null) { if (isPremultiplied) { throw new Diagnostics.PixelFormatNotSupportedException(fmt, nameof(fmt)); } if (fmt == ANDROIDBITMAP.Config.Alpha8) { return(Pixel.Alpha8.Format); } if (fmt == ANDROIDBITMAP.Config.Rgb565) { return(Pixel.BGR565.Format); } if (fmt == ANDROIDBITMAP.Config.Argb4444) { return(Pixel.BGRA4444.Format); } if (fmt == ANDROIDBITMAP.Config.Argb8888) { return(Pixel.RGBA32.Format); } if (defFmt.HasValue) { return(defFmt.Value); } throw new Diagnostics.PixelFormatNotSupportedException(fmt, nameof(fmt)); }
public static PixelFormat ToInterop(this ANDROIDBITMAP.Config fmt, bool isAlphaPremul = false, PixelFormat?defFmt = null) { if (fmt == null) { throw new ArgumentNullException(nameof(fmt)); } return(_Implementation.ToInterop(fmt, isAlphaPremul, defFmt)); }
internal AndroidFactory(BitmapInfo binfo, ANDROIDBITMAP.Config defFmt = null) { if (defFmt == null) { defFmt = ANDROIDBITMAP.Config.Argb8888; } _Info = binfo; _Exact = _Implementation.ToAndroidBitmapConfig(_Info.PixelFormat, null); _Compatible = _Implementation.ToAndroidBitmapConfig(_Info.PixelFormat, defFmt); }
public static ANDROIDBITMAP.Config ToAndroidBitmapConfig(PixelFormat fmt, ANDROIDBITMAP.Config defval = null) { switch (fmt.Code) { case Pixel.Alpha8.Code: return(ANDROIDBITMAP.Config.Alpha8); case Pixel.BGR565.Code: return(ANDROIDBITMAP.Config.Rgb565); case Pixel.BGRA4444.Code: return(ANDROIDBITMAP.Config.Argb4444); case Pixel.RGBA32.Code: return(ANDROIDBITMAP.Config.Argb8888); default: return(defval); } }
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)); }
public static Adapters.AndroidFactory ToAndroidFactory(this BitmapInfo binfo, ANDROIDBITMAP.Config defCfg = null) { return(new Adapters.AndroidFactory(binfo, defCfg)); }
public static bool Reshape(ref ANDROIDBITMAP bmp, BitmapInfo info, ANDROIDBITMAP.Config defFmt) { var bmpCfg = ToAndroidBitmapConfig(info.PixelFormat, bmp != null ? bmp.GetConfig() : defFmt); return(Reshape(ref bmp, bmpCfg, info.Width, info.Height)); }