Esempio n. 1
0
        /// <summary>
        /// Convert bytes[] to image
        /// </summary>
        /// <param name="byteArrayIn"></param>
        /// <returns></returns>
        public Image byteArrayToImage(byte[] byteArrayIn)
        {
            utilidades a       = new utilidades();
            Image      retorno = a.byteArrayToImage(byteArrayIn);

            a = null;
            return(retorno);
        }
Esempio n. 2
0
        /// <summary>
        /// Convert image to bytes[]
        /// </summary>
        /// <param name="imageIn"></param>
        /// <returns></returns>
        public byte[] imageToByteArray(Image imageIn)
        {
            utilidades a = new utilidades();

            byte[] retorno = a.imageToByteArray(imageIn);
            a = null;
            return(retorno);
        }
Esempio n. 3
0
        /// <summary>
        /// Image resize
        /// </summary>
        /// <param name="maxWidth"></param>
        /// <param name="maxHeight"></param>
        /// <param name="imageBytes"></param>
        /// <returns></returns>
        public static byte[] ResizeImage(int maxWidth, int maxHeight, byte[] imageBytes)
        {
            utilidades a     = new utilidades();
            Image      Image = a.byteArrayToImage(imageBytes);

            int width  = Image.Width;
            int height = Image.Height;

            if (width > maxWidth || height > maxHeight)
            {
                //The flips are in here to prevent any embedded image thumbnails -- usually from cameras
                //from displaying as the thumbnail image later, in other words, we want a clean
                //resize, not a grainy one.
                Image.RotateFlip(RotateFlipType.Rotate180FlipX);
                Image.RotateFlip(RotateFlipType.Rotate180FlipY);

                float ratio;
                if (width < height)
                {
                    ratio  = width / (float)height;
                    width  = maxWidth;
                    height = Convert.ToInt32(Math.Round(width / ratio));
                }
                else
                {
                    ratio  = height / (float)width;
                    height = maxHeight;
                    width  = Convert.ToInt32(Math.Round(height / ratio));
                }

                //return the resized image
                imageBytes = a.imageToByteArray(Image.GetThumbnailImage(width, height, null, IntPtr.Zero));
            }
            //return the original resized image
            return(imageBytes);
        }