public byte[] ToPng(CImageByte img) { if (img.Channel != 4) return null; Bitmap bitmap = Bitmap.CreateBitmap((int)img.Width, (int)img.Height, Bitmap.Config.Argb8888); var byteBuffer = Java.Nio.ByteBuffer.Wrap(img.Bytes); bitmap.CopyPixelsFromBuffer(byteBuffer); MemoryStream stream = new MemoryStream(); bitmap.Compress(Bitmap.CompressFormat.Png, 50, stream); return stream.ToArray(); }
public byte[] ToPng(CImageByte img) { var provider = new CGDataProvider(img.Bytes, 0, (int)img.Length); int bitsPerComponent = 8; int components = (int)img.Channel; int bitsPerPixel = components * bitsPerComponent; int bytesPerRow = (int)img.Stride; // Tip: When you create a bitmap graphics context, // you’ll get the best performance if you make sure the data and bytesPerRow are 16-byte aligned. bool shouldInterpolate = false; var colorSpace = CGColorSpace.CreateDeviceRGB(); var cgImage = new CGImage( (int)img.Width, (int)img.Height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpace, CGImageAlphaInfo.PremultipliedLast, provider, null, shouldInterpolate, CGColorRenderingIntent.Default); var uimg = UIImage.FromImage(cgImage); Console.WriteLine("topng info: " + uimg.Size.ToString()); return uimg.AsPNG().ToArray(); }
static public CImageBuffer CImageByteToBuffer(CImageByte img) { return new CImageBuffer(img.Bytes, img.Width, img.Channel); }
public void AddImage(CImageByte img) { imgs.Add(img); }