Ejemplo n.º 1
0
        public static async Task <byte[]> ResizeImageTizen(byte[] imageData, float width, float height)
        {
            using (JpegDecoder jpegDecoder = new JpegDecoder())
            {
                Size newImageSize = new Size((int)width, (int)height);
                IEnumerable <BitmapFrame> image = await jpegDecoder.DecodeAsync(imageData);

                Size   oldImageSize = image.First().Size;
                byte[] rawImageData = image.First().Buffer;
                using (MediaPacket mediaPacket = MediaPacket.Create(new VideoMediaFormat(MediaFormatVideoMimeType.Rgba, oldImageSize)))
                {
                    mediaPacket.VideoPlanes[0].Buffer.CopyFrom(rawImageData, 0, rawImageData.Length);
                    using (ImageTransformer imageTransformer = new ImageTransformer())
                    {
                        using (MediaPacket newMediaPacket = await imageTransformer.TransformAsync(mediaPacket, new ResizeTransform(newImageSize)))
                        {
                            IMediaBuffer buffer          = newMediaPacket.VideoPlanes[0].Buffer;
                            byte[]       newRawImageData = new byte[buffer.Length];
                            buffer.CopyTo(newRawImageData, 0, buffer.Length);
                            using (var jpegEncoder = new JpegEncoder())
                            {
                                jpegEncoder.Quality = 100;
                                jpegEncoder.SetResolution(newImageSize);
                                using (MemoryStream ms = new MemoryStream())
                                {
                                    await jpegEncoder.EncodeAsync(newRawImageData, ms);

                                    return(ms.ToArray());
                                }
                            }
                        }
                    }
                }
            }
        }