Exemple #1
0
        public static byte[] ScaleImage(byte[] sourceImageBytes, int frameWidth, int frameHeight, out ImageFormat imageFormat)
        {
            System.Drawing.Image image;
            try
            {
                image       = System.Drawing.Image.FromStream(new MemoryStream(sourceImageBytes), true, false);
                imageFormat = ImageUtility.GetTargetImageFormat(image.RawFormat);
            }
            catch
            {
                imageFormat = null;
                return(null);
            }
            int num = Math.Max(image.Width / frameWidth, image.Height / frameHeight);

            System.Drawing.Image image2;
            if (num > 1)
            {
                int width  = image.Width / num;
                int height = image.Height / num;
                image2 = new Bitmap(width, height);
                using (Graphics graphics = Graphics.FromImage(image2))
                {
                    graphics.DrawImage(image, 0, 0, width, height);
                }
                image.Dispose();
            }
            else
            {
                if (ImageUtility.IsSupportedBySilverlight(image.RawFormat))
                {
                    return(sourceImageBytes);
                }
                image2 = image;
            }
            MemoryStream memoryStream = new MemoryStream();

            image2.Save(memoryStream, imageFormat);
            image2.Dispose();
            return(memoryStream.GetBuffer());
        }
Exemple #2
0
        public static byte[] ScaleImage(byte[] sourceImageBytes, RVUnit frameWidth, RVUnit frameHeight)
        {
            ImageFormat imageFormat = default(ImageFormat);

            return(ImageUtility.ScaleImage(sourceImageBytes, (int)ImageUtility.ConvertToPixels(frameWidth), (int)ImageUtility.ConvertToPixels(frameHeight), out imageFormat));
        }