コード例 #1
0
ファイル: ImageTool.cs プロジェクト: femiosinowo/sssadl
        private void LoadSelectedImageInformation()
        {
            RetrieveFileSize();

            // use cximage library instead of asp.net routines
            ImageGalleryInterop.CImageResizerClass ig = new ImageGalleryInterop.CImageResizerClass();
            ig.GetImageDimensions(m_originalFile, out m_width, out m_height, out m_depth);

            /*
            System.Drawing.Image img = System.Drawing.Image.FromFile(m_originalFile);

            PixelFormat pixFormat;
            pixFormat = img.PixelFormat;
            m_depth = Image.GetPixelFormatSize(pixFormat);

            m_width = img.Width;
            m_height = img.Height;

            img.Dispose();
            */
        }
コード例 #2
0
ファイル: ImageTool.cs プロジェクト: femiosinowo/sssadl
        /// <summary>
        /// Rotates an image.
        /// </summary>
        /// <param name="rotateValue">The ImageRotation enumeration value.</param>
        /// <param name="originalPathFile">Source file, could be the same as the change file.</param>
        /// <param name="changeImagePathFile">The file to receive the change.</param>
        /// <returns>True for success.</returns>
        public bool Rotate(ImageRotation rotateValue, string originalPathFile, string changeImagePathFile)
        {
            bool bRet = false;

            if (null == originalPathFile) return false;
            if (null == changeImagePathFile) return false;

            if (originalPathFile.Length > 0)  // may have been set at creation, so not given
                m_originalFile = originalPathFile;

            // Fix slashes - never trust that they have done this.
            m_originalFile = m_originalFile.Replace('/', '\\').Replace("\\\\", "\\");
            changeImagePathFile = changeImagePathFile.Replace('/', '\\').Replace("\\\\", "\\");

            // use cximage library instead of .Net code
            if (m_originalFile != changeImagePathFile)
            {
                // copy file to new if needed
                StorageClient.Context.File.Copy(m_originalFile, changeImagePathFile, true);
                MakeWriteable(changeImagePathFile); // in case the original was readonly
            }
            ImageGalleryInterop.CImageResizerClass ig = new ImageGalleryInterop.CImageResizerClass();
            int angle = 0;
            switch (rotateValue)
            {
                case ImageRotation.Half180:
                    angle = 180;
                    break;
                case ImageRotation.Left90:
                    angle = -90;
                    break;
                case ImageRotation.Right90:
                    angle = 90;
                    break;
            }
            ig.RotateImageFile(changeImagePathFile, angle);

            /*
            RotateFlipType rfAction = RotateFlipType.Rotate90FlipNone;

            System.Drawing.Image img = System.Drawing.Image.FromFile(m_originalFile);

            switch (rotateValue)
            {
                case ImageRotation.None:
                    break;

                case ImageRotation.Half180:
                    rfAction = RotateFlipType.Rotate180FlipNone;
                    break;

                case ImageRotation.Left90:
                    rfAction = RotateFlipType.Rotate270FlipNone;
                    break;

                case ImageRotation.Right90:
                    rfAction = RotateFlipType.Rotate90FlipNone;
                    break;
            }

            img.RotateFlip(rfAction);

            img.Save(changeImagePathFile);

            // Save for convenient use.
            m_width = img.Width;
            m_height = img.Height;
            img.Dispose();
            */

            m_localResultFile = changeImagePathFile;

            bRet = true;

            return bRet;
        }
コード例 #3
0
ファイル: ImageTool.cs プロジェクト: femiosinowo/sssadl
        /// <summary>
        /// Resizes an image.  This is the actual image size, not the display size.
        /// </summary>
        /// <param name="resizeWidth">Width in pixels.</param>
        /// <param name="resizeHeight">Height in pixels.</param>
        /// <param name="maintainAspect">Modify parameters to maintain the aspect ratio.</param>
        /// <param name="originalPathFile">Source file, could be the same as the change file.</param>
        /// <param name="changeImagePathFile">The file to receive the change.</param>
        /// <returns>True for success.</returns>
        public bool Resize(int resizeWidth, int resizeHeight, bool maintainAspect, string originalPathFile,
                    string changeImagePathFile)
        {
            bool bRet = false;

            if (null == originalPathFile) return false;
            if (null == changeImagePathFile) return false;

            UseImage(originalPathFile);     // get current image width/height
            if ((m_width == 0) || (m_height == 0)) return false;

            // OK, users will enter in garbage, since they don't know.
            // Let's help them out.
            // (Negative numbers are seen as 0.)
            if ((0 >= resizeWidth) || (0 >= resizeHeight))
            {
                maintainAspect = true;
            }
            if ((0 >= resizeWidth) && (0 >= resizeHeight))
            {
                resizeWidth = 32;  // default
            }

            if (maintainAspect)
            {
                // We need to be sure that our calculations do not overflow.
                double dOx, dOy, dRx, dRy;
                dOx = m_width;
                dOy = m_height;
                dRy = resizeHeight;
                dRx = resizeWidth;

                if (0 >= resizeWidth)
                {
                    //resizeWidth = (resizeHeight * img.Width) / img.Height;
                    //dRx = (dRy * dOx) / dOy;
                    resizeWidth = Convert.ToInt32((dRy * dOx) / dOy);
                }
                else
                {
                    //resizeHeight = (resizeWidth * img.Height) / img.Width;
                    //dRy = (dRx * dOy) / dOx;
                    resizeHeight = Convert.ToInt32((dRx * dOy) / dOx);
                }
            }

            if (originalPathFile.Length > 0)  // may have been set at creation, so not given
                m_originalFile = originalPathFile;

            // Fix slashes - never trust that they have done this.
            m_originalFile = m_originalFile.Replace('/', '\\').Replace("\\\\", "\\");
            changeImagePathFile = changeImagePathFile.Replace('/', '\\').Replace("\\\\", "\\");

            // use cximage library instead of .Net code
            if (m_originalFile != changeImagePathFile)
            {
                // copy file to new if needed
                StorageClient.Context.File.Copy(m_originalFile, changeImagePathFile, true);
                MakeWriteable(changeImagePathFile); // in case the original was readonly
            }
            ImageGalleryInterop.CImageResizerClass ig = new ImageGalleryInterop.CImageResizerClass();
            ig.ResizeImageFile(changeImagePathFile, resizeWidth, resizeHeight);

            /*
            System.Drawing.Image img = System.Drawing.Image.FromFile(m_originalFile);

            System.Drawing.Image.GetThumbnailImageAbort imgCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ImageResizeCallback);

            System.Drawing.Image imgThumbnail = img.GetThumbnailImage(resizeWidth, resizeHeight, imgCallBack, IntPtr.Zero);

            img.Dispose();  // Free up the file
            imgThumbnail.Save(changeImagePathFile);

            imgThumbnail.Dispose();
            */

            // Save for convenient use.
            m_width = resizeWidth;
            m_height = resizeHeight;
            m_localResultFile = changeImagePathFile;

            RetrieveFileSize();

            bRet = true;

            return bRet;
        }
コード例 #4
0
ファイル: ImageTool.cs プロジェクト: femiosinowo/sssadl
        /// <summary>
        /// Flips the image.
        /// </summary>
        /// <param name="vertical">True if the flip is vertical, otherwise horizontal.</param>
        /// <param name="originalPathFile">Source file, could be the same as the change file.</param>
        /// <param name="changeImagePathFile">The file to receive the change.</param>
        /// <returns>True for success.</returns>
        public bool Flip(bool vertical, string originalPathFile, string changeImagePathFile)
        {
            bool bRet = false;

            if (null == originalPathFile) return false;
            if (null == changeImagePathFile) return false;

            if (originalPathFile.Length > 0)  // may have been set at creation, so not given
                m_originalFile = originalPathFile;

            // Fix slashes - never trust that they have done this.
            m_originalFile = m_originalFile.Replace('/', '\\').Replace("\\\\", "\\");
            changeImagePathFile = changeImagePathFile.Replace('/', '\\').Replace("\\\\", "\\");

            // use cximage library instead of .Net code
            if (m_originalFile != changeImagePathFile)
            {
                // copy file to new if needed
                StorageClient.Context.File.Copy(m_originalFile, changeImagePathFile, true);
                MakeWriteable(changeImagePathFile); // in case the original was readonly
            }
            ImageGalleryInterop.CImageResizerClass ig = new ImageGalleryInterop.CImageResizerClass();
            ig.FlipImageFile(changeImagePathFile, vertical ? 1 : 0);

            /*
            RotateFlipType rfAction = (vertical) ? RotateFlipType.RotateNoneFlipY : RotateFlipType.RotateNoneFlipX;

            System.Drawing.Image img = System.Drawing.Image.FromFile(m_originalFile);

            img.RotateFlip(rfAction);
            img.Save(changeImagePathFile);

            // Save for convenient use.
            m_width = img.Width;
            m_height = img.Height;
            img.Dispose();
            */
            m_localResultFile = changeImagePathFile;

            bRet = true;

            return bRet;
        }
コード例 #5
0
ファイル: ImageTool.cs プロジェクト: femiosinowo/sssadl
        /// <summary>
        /// Crops an image.
        /// </summary>
        /// <param name="cropStartX">The horizontal start point in pixels.</param>
        /// <param name="cropStartY">The vertical start point.</param>
        /// <param name="cropWidth">The width of the crop, in pixels.</param>
        /// <param name="cropHeight">The hight of the crop.</param>
        /// <param name="originalPathFile">Source file, could be the same as the change file.</param>
        /// <param name="changeImagePathFile">The file to receive the change.</param>
        /// <returns>True for success.</returns>
        public bool Crop(int cropStartX, int cropStartY, int cropWidth, int cropHeight, 
                    string originalPathFile, string changeImagePathFile)
        {
            bool bRet = false;

            if (null == originalPathFile)  return false;
            if (null == changeImagePathFile) return false;

            if (originalPathFile.Length > 0)  // may have been set at creation, so not given
                m_originalFile = originalPathFile;

            // Fix slashes - never trust that they have done this.
            m_originalFile = m_originalFile.Replace('/', '\\').Replace("\\\\", "\\");
            changeImagePathFile = changeImagePathFile.Replace('/', '\\').Replace("\\\\", "\\");

            // use cximage library instead of .Net code
            if (m_originalFile != changeImagePathFile)
            {
                // copy file to new if needed
                StorageClient.Context.File.Copy(m_originalFile, changeImagePathFile, true);
                MakeWriteable(changeImagePathFile); // in case the original was readonly
            }
            ImageGalleryInterop.CImageResizerClass ig = new ImageGalleryInterop.CImageResizerClass();
            ig.CropImageFile(changeImagePathFile, cropStartX, cropStartY, cropWidth, cropHeight);

            /*
            System.Drawing.Image img;
            img = System.Drawing.Image.FromFile(m_originalFile);

            Bitmap bmpImage = new Bitmap(img);
            img.Dispose();  // Free up the file

            Rectangle recCrop = new Rectangle(cropStartX, cropStartY,
               cropWidth, cropHeight);
            Bitmap bmpCrop = new Bitmap
               (cropWidth, cropHeight,
               bmpImage.PixelFormat);
            Graphics gphCrop = Graphics.FromImage(bmpCrop);
            Rectangle recDest = new Rectangle(0, 0,
               cropWidth, cropHeight);

            gphCrop.DrawImage(bmpImage, recDest,
               recCrop.X, recCrop.Y,
               recCrop.Width, recCrop.Height,
               GraphicsUnit.Pixel);

            bmpCrop.Save(changeImagePathFile);
            bmpImage.Dispose();
            bmpCrop.Dispose();
            gphCrop.Dispose();
            */

            // Save for convenient use.
            m_width = cropWidth;
            m_height = cropHeight;
            m_localResultFile = changeImagePathFile;

            bRet = true;

            return bRet;
        }
コード例 #6
0
ファイル: ImageTool.cs プロジェクト: femiosinowo/sssadl
        /// <summary>
        /// Modifies the brightness of the given file.
        /// </summary>
        /// <param name="dblAffect">>How to modify.  Value of 1 leaves alone, 0.x darkens, 1.x is to lightens.</param>
        /// <param name="originalPathFile">Source file, could be the same as the change file.</param>
        /// <param name="changeImagePathFile">The file to receive the change.</param>
        /// <returns>True for success.</returns>
        public bool Brightness(double brightValue, string originalPathFile, string changeImagePathFile)
        {
            bool bRet = false;

            if (null == originalPathFile) return false;
            if (null == changeImagePathFile) return false;

            if (originalPathFile.Length > 0)  // may have been set at creation, so not given
                m_originalFile = originalPathFile;

            // Fix slashes - never trust that they have done this.
            m_originalFile = m_originalFile.Replace('/', '\\').Replace("\\\\", "\\");
            changeImagePathFile = changeImagePathFile.Replace('/', '\\').Replace("\\\\", "\\");

            // use cximage library instead of .Net code
            if (m_originalFile != changeImagePathFile)
            {
                // copy file to new if needed
                StorageClient.Context.File.Copy(m_originalFile, changeImagePathFile, true);
                MakeWriteable(changeImagePathFile); // in case the original was readonly
            }
            if (brightValue != 1.0)
            {
                ImageGalleryInterop.CImageResizerClass ig = new ImageGalleryInterop.CImageResizerClass();
                ig.BrightenImageFile(changeImagePathFile, brightValue);
            }

            /*
            System.Drawing.Image img = System.Drawing.Image.FromFile(m_originalFile);
            Bitmap bmpImage = new Bitmap(img);
            img.Dispose();  // Free up the file for changes

            Color pixel;
            int r, g, b;

            for (int y = 0; y < bmpImage.Height; y++)
            {
                for (int x = 0; x < bmpImage.Width; x++)
                {
                    pixel = bmpImage.GetPixel(x, y);
                    r = (int)((double)pixel.R * brightValue); if (r < 0) r = 0; if (r > 255) r = 255;
                    g = (int)((double)pixel.G * brightValue); if (g < 0) g = 0; if (g > 255) g = 255;
                    b = (int)((double)pixel.B * brightValue); if (b < 0) b = 0; if (b > 255) b = 255;
                    bmpImage.SetPixel(x, y, Color.FromArgb(r, g, b));
                }
            }

            bmpImage.Save(changeImagePathFile);

            // Save for convenient use.
            m_width = bmpImage.Width;
            m_height = bmpImage.Height;

            bmpImage.Dispose();
            */

            m_localResultFile = changeImagePathFile;
            bRet = true;

            return bRet;
        }