Beispiel #1
0
        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();
        }
Beispiel #2
0
        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();
        }
Beispiel #3
0
 static public CImageBuffer CImageByteToBuffer(CImageByte img)
 {
     return new CImageBuffer(img.Bytes, img.Width, img.Channel);
 }
Beispiel #4
0
        public void AddImage(CImageByte img)
        {
            imgs.Add(img);

        }