private void SetGifBackground(string gifPath)
        {
            //Image gif = Image.FromFile(gifPath);
            Image gif = Properties.Resources.login;

            System.Drawing.Imaging.FrameDimension fd = new System.Drawing.Imaging.FrameDimension(gif.FrameDimensionsList[0]);
            int count = gif.GetFrameCount(fd);    //获取帧数(gif图片可能包含多帧,其它格式图片一般仅一帧)

            giftimer          = new Timer();
            giftimer.Interval = 10;
            int   i     = 0;
            Image bgImg = null;

            giftimer.Tick += (s, e) => {
                if (i >= count)
                {
                    i = 0;
                }
                gif.SelectActiveFrame(fd, i);
                System.IO.Stream stream = new System.IO.MemoryStream();
                gif.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                if (bgImg != null)
                {
                    bgImg.Dispose();
                }
                bgImg = Image.FromStream(stream);
                panelEnhanced1.BackgroundImage       = bgImg;
                panelEnhanced1.BackgroundImageLayout = ImageLayout.Stretch;
                i++;
            };
            giftimer.Start();
        }
Exemple #2
0
        public void LoadFrames()
        {
            System.Drawing.Imaging.FrameDimension frameDimension = new System.Drawing.Imaging.FrameDimension(Image.FrameDimensionsList[0]);
            Data.FramesCount = Image.GetFrameCount(frameDimension);

            for (int i = 0; i < Data.FramesCount; i++)
            {
                if (Data.CancelLoading)
                {
                    return;
                }

                Image.SelectActiveFrame(frameDimension, i);
                Quantizer = new ImageManipulation.OctreeQuantizer(255, 8);

                System.Drawing.Bitmap quantized = Quantizer.Quantize(Image);
                MemoryStream          stream    = new MemoryStream();
                quantized.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
                Data.Frames.Add(new Texture(stream));

                stream.Dispose();

                if (Data.CancelLoading)
                {
                    return;
                }

                Data.Frames[i].Smooth = Data.Smooth;
                Data.Frames[i].Mipmap = Data.Mipmap;
            }
            Data.FullyLoaded = true;
        }
        public void PlayBackImage(object sender, EventArgs e)
        {
            if (gif == null)
            {
                gif = Image.FromFile(gifPath);
            }
            System.Drawing.Imaging.FrameDimension fd = new System.Drawing.Imaging.FrameDimension(gif.FrameDimensionsList[0]);
            int   count = gif.GetFrameCount(fd); //获取帧数(gif图片可能包含多帧,其它格式图片一般仅一帧)
            Image bgImg = null;

            if (indexImage >= count)
            {
                indexImage = 0;
            }
            gif.SelectActiveFrame(fd, indexImage);
            System.IO.Stream stream = new System.IO.MemoryStream();
            gif.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
            if (bgImg != null)
            {
                bgImg.Dispose();
            }
            bgImg = Image.FromStream(stream);
            fm.BackgroundImage       = bgImg;
            fm.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            indexImage++;
        }
Exemple #4
0
        private static void Main(string[] args)
        {
            if (args.Length > 0 && System.IO.File.Exists(args[0])) {
                // first to regconise if GIF98a & check the resolution of image
                // if still image then open it using Windows Photo Gallery instead
                //http://stackoverflow.com/questions/2848689/c-sharp-tell-static-gifs-apart-from-animated-ones
                System.Drawing.Image regconiseImageSize = System.Drawing.Image.FromFile(args[0]);

                System.Drawing.Imaging.FrameDimension FrameDimensions =
                new System.Drawing.Imaging.FrameDimension(regconiseImageSize.FrameDimensionsList[0]);

                int frames = regconiseImageSize.GetFrameCount(FrameDimensions);

                if (frames > 1) {
                    int width = regconiseImageSize.Size.Width;
                    int height = regconiseImageSize.Size.Height;
                    regconiseImageSize.Dispose();

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm(args[0], width, height));
                } else {
                    regconiseImageSize.Dispose();
                    System.Diagnostics.Process.Start("rundll32.exe",  "\"" + System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\Windows Photo Viewer\\PhotoViewer.dll\", ImageView_Fullscreen " + args[0]);
                    Application.Exit();
                }
            }
            else {
                // Proposed user-friendly file association function
                Application.Exit();
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pFullName"></param>
        private void LoadBitmap(string pFullName)
        {
            // Read from file
            Bitmap aux = (Bitmap)Bitmap.FromFile(pFullName);

            System.Drawing.Imaging.FrameDimension dim = new System.Drawing.Imaging.FrameDimension(aux.FrameDimensionsList[0]);
            int a = aux.GetFrameCount(dim);

            // Ensure bitmap is in 32bppARGB
            this.mBitmapOriginal         = aux.Clone(new System.Drawing.Rectangle(0, 0, aux.Width, aux.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            this.pictureBox1.Image       = this.mBitmapOriginal;
            mSettings.Width              = mBitmapOriginal.Width;
            mSettings.Height             = mBitmapOriginal.Height;
            mSettings.AlphaGradientRange = (int)((float)mBitmapOriginal.Height * 0.5f);

            // Set texture colors
            this.mXNAPictureBox.Texture = new Texture2D(this.mDevice, mBitmapOriginal.Width, mBitmapOriginal.Height, 1, TextureUsage.None, SurfaceFormat.Color);
            int[] colors = this.GetBitmapColors(mBitmapOriginal, 0, 0, mBitmapOriginal.Width, mBitmapOriginal.Height);
            this.mXNAPictureBox.Texture.SetData <int>(colors);

            // Update settings to new bitmap properties
            mSettings.NewWidth  = mBitmapOriginal.Width;
            mSettings.NewHeight = mBitmapOriginal.Height;
            this.propertyGrid1.SelectedObject = mSettings;
        }
        private static void ProcessingThread(byte[] gifData, ref GifInfo frameInfo)
        {
            var gifImage   = Utilities.byteArrayToImage(gifData);
            var dimension  = new System.Drawing.Imaging.FrameDimension(gifImage.FrameDimensionsList[0]);
            int frameCount = gifImage.GetFrameCount(dimension);

            frameInfo.frameCount  = frameCount;
            frameInfo.dimension   = dimension;
            frameInfo.initialized = true;

            int index = 0;

            for (int i = 0; i < frameCount; i++)
            {
                gifImage.SelectActiveFrame(dimension, i);
                var frame = new System.Drawing.Bitmap(gifImage.Width, gifImage.Height);
                System.Drawing.Graphics.FromImage(frame).DrawImage(gifImage, System.Drawing.Point.Empty);

                FrameInfo currentFrame = new FrameInfo(frame);
                for (int x = 0; x < frame.Width; x++)
                {
                    for (int y = 0; y < frame.Height; y++)
                    {
                        System.Drawing.Color sourceColor = frame.GetPixel(x, y);
                        currentFrame.colors.Add(sourceColor);
                    }
                }

                currentFrame.delay = (float)BitConverter.ToInt32(gifImage.GetPropertyItem(20736).Value, index) / 100.0f;
                frameInfo.frames.Add(currentFrame);
                index += 4;
                Thread.Sleep(7);
            }
        }
Exemple #7
0
 public GifImage(string path)
 {
     gifImage = Image.FromFile(path);
     //initialize
     dimension = new System.Drawing.Imaging.FrameDimension(gifImage.FrameDimensionsList[0]);
     //gets the GUID
     //total frames in the animation
     frameCount = gifImage.GetFrameCount(dimension);
 }
Exemple #8
0
        //step grass animation
        private void StepAnimation()
        {
            grassAnimationStep += 0.07F;
            System.Drawing.Imaging.FrameDimension dim2;

            if (grassAnimationStep >= animatedGrass.GetFrameCount(new System.Drawing.Imaging.FrameDimension(animatedGrass.FrameDimensionsList[0])) - 1)
            {
                grassAnimationStep = 0;
            }
            dim2 = new System.Drawing.Imaging.FrameDimension(animatedGrass.FrameDimensionsList[0]);
            animatedGrass.SelectActiveFrame(dim2, Convert.ToInt32(grassAnimationStep));
        }
Exemple #9
0
        private static void ProcessingThread(byte[] gifData, GifInfo frameInfo)
        {
            var gifImage   = EmojiUtilities.byteArrayToImage(gifData);
            var dimension  = new System.Drawing.Imaging.FrameDimension(gifImage.FrameDimensionsList[0]);
            int frameCount = gifImage.GetFrameCount(dimension);

            frameInfo.frameCount  = frameCount;
            frameInfo.initialized = true;

            int index           = 0;
            int firstDelayValue = -1;

            for (int i = 0; i < frameCount; i++)
            {
                gifImage.SelectActiveFrame(dimension, i);
                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(gifImage.Width, gifImage.Height);
                System.Drawing.Graphics.FromImage(bitmap).DrawImage(gifImage, System.Drawing.Point.Empty);
                LockBitmap frame = new LockBitmap(bitmap);
                frame.LockBits();
                FrameInfo currentFrame = new FrameInfo(bitmap.Width, bitmap.Height);

                if (currentFrame.colors == null)
                {
                    currentFrame.colors = new Color32[frame.Height * frame.Width];
                }
                for (int x = 0; x < frame.Width; x++)
                {
                    for (int y = 0; y < frame.Height; y++)
                    {
                        System.Drawing.Color sourceColor = frame.GetPixel(x, y);
                        currentFrame.colors[(frame.Height - y - 1) * frame.Width + x] = new Color32(sourceColor.R, sourceColor.G, sourceColor.B, sourceColor.A);
                    }
                }

                int delayPropertyValue = BitConverter.ToInt32(gifImage.GetPropertyItem(20736).Value, index);
                if (firstDelayValue == -1)
                {
                    firstDelayValue = delayPropertyValue;
                }

                if (delayPropertyValue != firstDelayValue)
                {
                    frameInfo.isDelayConsistent = false;
                }

                currentFrame.delay = delayPropertyValue * 10;
                frameInfo.frames.Add(currentFrame);
                index += 4;

                Thread.Sleep(Globals.IsAtMainMenu ? 0 : 10);
            }
        }
Exemple #10
0
 static void SplitGIF(string fileName, string outputTemplate)
 {
     using (var image = System.Drawing.Image.FromFile(fileName))
     {
         var dimension  = new System.Drawing.Imaging.FrameDimension(image.FrameDimensionsList[0]);
         var frameCount = image.GetFrameCount(dimension);
         for (var frame = 0; frame < frameCount; ++frame)
         {
             image.SelectActiveFrame(dimension, frame);
             image.Save(string.Format(outputTemplate, frame + 1), System.Drawing.Imaging.ImageFormat.Png);
         }
     }
 }
 public static void SplitTiff(string fileName)
 {
     System.Drawing.Image imageFile = System.Drawing.Image.FromFile(fileName);
     System.Drawing.Imaging.FrameDimension frameDimensions = new System.Drawing.Imaging.FrameDimension(imageFile.FrameDimensionsList[0]);
     int numberOfImages = imageFile.GetFrameCount(frameDimensions);
     System.Drawing.Image[] img = new System.Drawing.Image[numberOfImages];
     for (int intFrame = 0; intFrame < numberOfImages; intFrame++)
     {
         imageFile.SelectActiveFrame(frameDimensions, intFrame);
         img[intFrame] = imageFile;
     }
     img[0].Save(@"C:\YpiiData\test55.tif");
 }
Exemple #12
0
 private bool IsAnimationGif(Image image)
 {
     try
     {
         var frameDimensions = new System.Drawing.Imaging.FrameDimension(image.FrameDimensionsList[0]);
         var frames          = image.GetFrameCount(frameDimensions);
         return(frames > 1);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #13
0
        public void LoadImageSequenceData(Stream stream, ImageSequence sequence)
        {
            lock (locker)
            {
                System.Drawing.Image image;
                try
                {
                    image = System.Drawing.Image.FromStream(stream);
                }
                catch
                {
                    return;
                }

                sequence.Frames.Clear();
                sequence.FrameTimesMs.Clear();

                var dimension = new System.Drawing.Imaging.FrameDimension(image.FrameDimensionsList[0]);
                // Number of frames
                int frameCount = image.GetFrameCount(dimension);

                if (frameCount > 1)
                {
                    var minFrameTimeMs = int.MaxValue;
                    for (var i = 0; i < frameCount; i++)
                    {
                        // Return an Image at a certain index
                        image.SelectActiveFrame(dimension, i);
                        ImageBuffer imageBuffer = new ImageBuffer();
                        if (ImageIOWindowsPlugin.ConvertBitmapToImage(imageBuffer, new Bitmap(image)))
                        {
                            var frameDelay = BitConverter.ToInt32(image.GetPropertyItem(20736).Value, i * 4) * 10;

                            sequence.AddImage(imageBuffer, frameDelay);
                            minFrameTimeMs = Math.Max(10, Math.Min(frameDelay, minFrameTimeMs));
                        }
                    }
                    var item = image.GetPropertyItem(0x5100);                     // FrameDelay in libgdiplus
                    // Time is in milliseconds
                    sequence.SecondsPerFrame = minFrameTimeMs / 1000.0;
                }
                else
                {
                    ImageBuffer imageBuffer = new ImageBuffer();
                    if (ImageIOWindowsPlugin.ConvertBitmapToImage(imageBuffer, new Bitmap(image)))
                    {
                        sequence.AddImage(imageBuffer);
                    }
                }
            }
        }
Exemple #14
0
        private static void ProcessingThread(byte[] gifData, GifInfo frameInfo)
        {
            var gifImage   = EmojiUtilities.byteArrayToImage(gifData);
            var dimension  = new System.Drawing.Imaging.FrameDimension(gifImage.FrameDimensionsList[0]);
            int frameCount = gifImage.GetFrameCount(dimension);

            frameInfo.frameCount  = frameCount;
            frameInfo.dimension   = dimension;
            frameInfo.initialized = true;

            int index = 0;

            for (int i = 0; i < frameCount; i++)
            {
                gifImage.SelectActiveFrame(dimension, i);
                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(gifImage.Width, gifImage.Height);
                System.Drawing.Graphics.FromImage(bitmap).DrawImage(gifImage, System.Drawing.Point.Empty);
                LockBitmap frame = new LockBitmap(bitmap);

                frame.LockBits();
                FrameInfo currentFrame = new FrameInfo(bitmap.Width, bitmap.Height);

                if (currentFrame.colors == null)
                {
                    currentFrame.colors = new Color32[frame.Height * frame.Width];
                }

                for (int x = 0; x < frame.Width; x++)
                {
                    for (int y = 0; y < frame.Height; y++)
                    {
                        System.Drawing.Color sourceColor = frame.GetPixel(x, y);
                        currentFrame.colors[(frame.Height - y - 1) * frame.Width + x] = new Color32(sourceColor.R, sourceColor.G, sourceColor.B, sourceColor.A);
                    }
                }

                int delayPropertyValue = BitConverter.ToInt32(gifImage.GetPropertyItem(20736).Value, index);
                // If the delay property is 0, assume that it's a 10fps emote
                if (delayPropertyValue == 0)
                {
                    delayPropertyValue = 10;
                }

                currentFrame.delay = (float)delayPropertyValue / 100.0f;
                frameInfo.frames.Add(currentFrame);
                index += 4;

                Thread.Sleep(0);
            }
        }
Exemple #15
0
        public static void SplitTiff(string fileName)
        {
            System.Drawing.Image imageFile = System.Drawing.Image.FromFile(fileName);
            System.Drawing.Imaging.FrameDimension frameDimensions = new System.Drawing.Imaging.FrameDimension(imageFile.FrameDimensionsList[0]);
            int numberOfImages = imageFile.GetFrameCount(frameDimensions);

            System.Drawing.Image[] img = new System.Drawing.Image[numberOfImages];
            for (int intFrame = 0; intFrame < numberOfImages; intFrame++)
            {
                imageFile.SelectActiveFrame(frameDimensions, intFrame);
                img[intFrame] = imageFile;
            }
            img[0].Save(@"C:\YpiiData\test55.tif");
        }
Exemple #16
0
        public static string ConvertToPdf(string strFilePath)
        {
            Document document = new Document(PageSize.A4, 50, 50, 50, 50);
            string newPdfFile = string.Empty;

            try
            {
                System.Drawing.Image objImage = System.Drawing.Image.FromFile(strFilePath);
                Guid objGuid = objImage.FrameDimensionsList[0];
                System.Drawing.Imaging.FrameDimension objDimension = new System.Drawing.Imaging.FrameDimension(objGuid);

                newPdfFile = System.IO.Path.GetTempPath() + @"\" + objGuid + ".pdf";
                PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(newPdfFile, FileMode.Create));

                System.Drawing.Bitmap bm = new System.Drawing.Bitmap(strFilePath);
                int total = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);

                document.Open();
                PdfContentByte cb = writer.DirectContent;

                for (int i = 0; i < total; i++)
                {
                    string pageName = System.IO.Path.GetTempPath() + @"\" + objGuid + "_" + i.ToString();
                    objImage.SelectActiveFrame(objDimension, i);
                    objImage.Save(pageName, System.Drawing.Imaging.ImageFormat.Tiff);

                    iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(pageName);
                    img.ScalePercent(62208f / img.Width, 83737.5f / img.Height);
                    img.SetAbsolutePosition(0, 0);
                    cb.AddImage(img);
                    document.NewPage();

                    File.Delete(pageName);
                }

            }
            catch (DocumentException de)
            {
                Console.Error.WriteLine(de.Message);
            }
            catch (IOException ioe)
            {
                Console.Error.WriteLine(ioe.Message);
            }

            document.Close();
            return newPdfFile;
        }
Exemple #17
0
        private void StartTimer_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1.Start();

            gif   = Properties.Resources.bck;
            fd    = new System.Drawing.Imaging.FrameDimension(gif.FrameDimensionsList[0]);
            count = gif.GetFrameCount(fd);
            System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
            timer.Interval = 200;
            timer.Tick    += Timer_Tick;
            timer.Start();

            StartTimer.Stop();
            StartTimer.Enabled = false;
        }
            public Emote(float offset_x, float offset_y, Image image)
            {
                OffsetX = offset_x;
                OffsetY = offset_y;
                Image   = image;

                dimension  = new System.Drawing.Imaging.FrameDimension(image.FrameDimensionsList[0]);
                max_frames = image.GetFrameCount(dimension);
                if (max_frames > 1)
                {
                    var fd_bytes = image.GetPropertyItem(FRAME_DELAY_ID);
                    frame_delay = fd_bytes != null?BitConverter.ToInt32(fd_bytes.Value, 0) : 0;
                }
                else
                {
                    frame_delay = 0;
                }
            }
Exemple #19
0
        private void SetGifBackground()
        {
            Image gif = Properties.Resources.乌云闪电;

            if (weather.Text == "小雨")
            {
                gif = Properties.Resources.乌云闪电;
            }
            else if (weather.Text == "多云")
            {
                gif = Properties.Resources.云;
            }
            else if (weather.Text == "晴转多云")
            {
                gif = Properties.Resources.阳光;
            }
            System.Drawing.Imaging.FrameDimension fd = new System.Drawing.Imaging.FrameDimension(gif.FrameDimensionsList[0]);
            int   count  = gif.GetFrameCount(fd); //获取帧数(gif图片可能包含多帧,其它格式图片一般仅一帧)
            Timer timer1 = new Timer();

            timer1.Interval = 100;
            int   i     = 0;
            Image bgImg = null;

            timer1.Tick += (s, e) =>
            {
                if (i >= count)
                {
                    i = 0;
                }
                gif.SelectActiveFrame(fd, i);
                System.IO.Stream stream = new System.IO.MemoryStream();
                gif.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                if (bgImg != null)
                {
                    bgImg.Dispose();
                }
                bgImg = Image.FromStream(stream);
                this.BackgroundImage = bgImg;
                i++;
            };
            timer1.Start();
            WeaBackTrans.BackColor = Color.FromArgb(0, 0, 0, 100);
        } // 窗体加载动图的方法
Exemple #20
0
        private static string[] SplitTiff(byte[] bytes, string splittedFilesDirectoryName, string prefixOfFileName)
        {
            using (var byteStream = new MemoryStream(bytes))
            {
                var image         = System.Drawing.Image.FromStream(byteStream);
                var fd            = new System.Drawing.Imaging.FrameDimension(image.FrameDimensionsList[0]);
                int numberOfPages = image.GetFrameCount(fd);
                var splittedFiles = new string[numberOfPages];
                Directory.CreateDirectory(splittedFilesDirectoryName);

                for (int pageNum = 0; pageNum < numberOfPages; pageNum++)
                {
                    image.SelectActiveFrame(fd, pageNum);
                    string filename = Path.Combine(splittedFilesDirectoryName, prefixOfFileName + pageNum.ToString("D10") + ".tif");
                    image.Save(filename, System.Drawing.Imaging.ImageFormat.Tiff);
                    splittedFiles[pageNum] = filename;
                }

                return(splittedFiles);
            }
        }
Exemple #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pPath"></param>
        /// <returns></returns>
        public String func_分解GIF(String pPath)
        {
            String s_資料夾名稱 = func_雜湊檔案(pPath);

            String pSavedPath = M.func_取得暫存路徑() + "GIF\\" + s_資料夾名稱;


            if (Directory.Exists(pSavedPath))
            {
                /* try {
                 *   foreach (var item in Directory.GetFiles(pSavedPath, "*.*")) {
                 *       File.Delete(item);
                 *   }
                 * } catch { }*/
            }
            else
            {
                Directory.CreateDirectory(pSavedPath);


                var gif = System.Drawing.Image.FromFile(pPath);
                var fd  = new System.Drawing.Imaging.FrameDimension(gif.FrameDimensionsList[0]);

                //獲取幀數(gif圖片可能包含多幀,其它格式圖片一般僅一幀)
                int count = gif.GetFrameCount(fd);
                //List<string> gifList = new List<string>();
                //以Jpeg格式保存各幀

                for (int i = 0; i < count; i++)
                {
                    gif.SelectActiveFrame(fd, i);
                    gif.Save(pSavedPath + "\\" + (i + 1) + ".png", System.Drawing.Imaging.ImageFormat.Png);
                    //gifList.Add(pSavedPath + "\\frame_" + i + ".png");
                }
            }

            return(pSavedPath);
        }
Exemple #22
0
        public void LoadFromGif(string path)
        {
            System.Drawing.Image image     = System.Drawing.Image.FromFile(path);
            System.Drawing.Size  imageSize = new System.Drawing.Size(image.Size.Width, image.Size.Height);
            System.Drawing.Imaging.FrameDimension frameSize = new System.Drawing.Imaging.FrameDimension(image.FrameDimensionsList[0]);

            int frames = image.GetFrameCount(frameSize);

            Images = new BitmapImage[frames];

            for (int i = 0; i < frames; i++)
            {
                System.Drawing.Bitmap   b = new System.Drawing.Bitmap(imageSize.Width, imageSize.Height);
                System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b);

                image.SelectActiveFrame(frameSize, i);
                g.DrawImage(image, 0, 0);

                Images[i] = Bitmap2BitmapImage(b);

                b.Dispose();
            }
        }
Exemple #23
0
        public System.Drawing.Image[] TiffPages()
        {
            System.Drawing.Image[] tiffPages = new System.Drawing.Image [0];

            try {
                // INITIALIZATION - SOURCE

                System.Drawing.Image tiffImage = System.Drawing.Bitmap.FromStream(ImageDecompressed);

                Int32 tiffPageCount = TiffPageCount(tiffImage);

                tiffPages = new System.Drawing.Image[tiffPageCount];


                // INITIALIZATION - FRAME DIMENSIONS

                System.Drawing.Imaging.FrameDimension pageDimension = new System.Drawing.Imaging.FrameDimension(tiffImage.FrameDimensionsList[0]);


                for (Int32 currentPageIndex = 0; currentPageIndex < tiffPageCount; currentPageIndex++)
                {
                    System.IO.MemoryStream tiffPage = new System.IO.MemoryStream();

                    tiffImage.SelectActiveFrame(pageDimension, currentPageIndex);

                    tiffImage.Save(tiffPage, System.Drawing.Imaging.ImageFormat.Tiff);

                    tiffPages[currentPageIndex] = System.Drawing.Image.FromStream(tiffPage);
                }
            }

            catch (Exception imageException) {
                System.Diagnostics.Debug.WriteLine("!---> Image Stream Exception [TiffPages]: " + imageException.Message);
            }

            return(tiffPages);
        }
Exemple #24
0
        private static void Main(string[] args)
        {
            if (args.Length > 0 && System.IO.File.Exists(args[0]))
            {
                // first to regconise if GIF98a & check the resolution of image
                // if still image then open it using Windows Photo Gallery instead
                //http://stackoverflow.com/questions/2848689/c-sharp-tell-static-gifs-apart-from-animated-ones
                System.Drawing.Image regconiseImageSize = System.Drawing.Image.FromFile(args[0]);

                System.Drawing.Imaging.FrameDimension FrameDimensions =
                    new System.Drawing.Imaging.FrameDimension(regconiseImageSize.FrameDimensionsList[0]);

                int frames = regconiseImageSize.GetFrameCount(FrameDimensions);

                if (frames > 1)
                {
                    int width  = regconiseImageSize.Size.Width;
                    int height = regconiseImageSize.Size.Height;
                    regconiseImageSize.Dispose();

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm(args[0], width, height));
                }
                else
                {
                    regconiseImageSize.Dispose();
                    System.Diagnostics.Process.Start("rundll32.exe", "\"" + System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\Windows Photo Viewer\\PhotoViewer.dll\", ImageView_Fullscreen " + args[0]);
                    Application.Exit();
                }
            }
            else
            {
                // Proposed user-friendly file association function
                Application.Exit();
            }
        }
        internal void LoadImageDataFromByte(Triggernometry.RealPlugin plug, Graphics g, byte[] data)
        {
            GifData gif = GetGifData(data);

            using (MemoryStream ms = new MemoryStream(data))
            {
                using (System.Drawing.Image i = System.Drawing.Image.FromStream(ms))
                {
                    System.Drawing.Bitmap b = (System.Drawing.Bitmap)i;
                    System.Drawing.Imaging.FrameDimension CurrentFd = new System.Drawing.Imaging.FrameDimension(i.FrameDimensionsList[0]);
                    NumberOfFrames = i.GetFrameCount(CurrentFd);
                    IsAnimated     = (NumberOfFrames > 1);
                    if (IsAnimated == true)
                    {
                        Frames      = new List <Image>();
                        FrameDelays = new List <int>();
                        System.Drawing.Imaging.PropertyItem delay = i.GetPropertyItem(0x5100);
                        Color tc;
                        bool  hastc = false;
                        if (gif.TransparencyIndex >= 0)
                        {
                            tc    = gif.Palette[gif.TransparencyIndex];
                            hastc = true;
                        }
                        else
                        {
                            tc = gif.Palette[0];
                        }
                        for (int h = 0; h < NumberOfFrames; h++)
                        {
                            int delayn = (delay.Value[h * 4] + (delay.Value[(h * 4) + 1] * 256)) * 10;
                            FrameDelays.Add(delayn);
                            i.SelectActiveFrame(CurrentFd, h);
                            System.Drawing.Image ifa = ((System.Drawing.Image)i.Clone());
                            byte[] idata             = ImageToByte(ifa);
                            if (hastc == true)
                            {
                                if (gif.TransparencyIndex != gif.BackgroundColor)
                                {
                                    // hack in case transparency color is different from bgcolor (some gifs have this shit)
                                    SetTransparencyIndex(idata, (byte)gif.BackgroundColor);
                                }
                                else
                                {
                                    for (int j = 0; j < gif.TransparencyIndex; j++)
                                    {
                                        if ((gif.Palette[j].R == tc.R) && (gif.Palette[j].R == tc.G) && (gif.Palette[j].R == tc.B))
                                        {
                                            // net itself might have selected an earlier color as new transparency color
                                            // hack to reset transparency index to match if so
                                            SetTransparencyIndex(idata, (byte)j);
                                            break;
                                        }
                                    }
                                }
                            }
                            Frames.Add(g.CreateImage(idata));
                        }
                        CurrentFrame = -1;
                        AdvanceFrame();
                    }
                    else
                    {
                        OriginalImage = g.CreateImage(data);
                    }
                }
            }
        }
Exemple #26
0
        public void btnSetting_Click(object sender, EventArgs e)
        {
            AvatarCanvas canvas = new AvatarCanvas();

            canvas.LoadZ();
            canvas.LoadActions();
            canvas.LoadEmotions();

            /*
             * cmbAction.Items.Clear();
             * foreach (var action in canvas.Actions)
             * {
             *  ComboItem cmbItem = new ComboItem(action.Name);
             *  switch (action.Level)
             *  {
             *      case 0:
             *          cmbItem.FontStyle = System.Drawing.FontStyle.Bold;
             *          cmbItem.ForeColor = Color.Indigo;
             *          break;
             *
             *      case 1:
             *          cmbItem.ForeColor = Color.Indigo;
             *          break;
             *  }
             *  cmbAction.Items.Add(cmbItem);
             * }*/

            canvas.ActionName       = "stand1";
            canvas.EmotionName      = "default";
            canvas.TamingActionName = "stand1";
            AddPart(canvas, "Character\\00002000.img");
            AddPart(canvas, "Character\\00012000.img");
            AddPart(canvas, "Character\\Face\\00020000.img");
            AddPart(canvas, "Character\\Hair\\00030000.img");
            AddPart(canvas, "Character\\Coat\\01040036.img");
            AddPart(canvas, "Character\\Pants\\01060026.img");
            AddPart(canvas, "Character\\Weapon\\01442000.img");
            //AddPart(canvas, "Character\\Weapon\\01382007.img");
            //AddPart(canvas, "Character\\Weapon\\01332000.img");
            //AddPart(canvas, "Character\\Weapon\\01342000.img");

            var faceFrames = canvas.GetFaceFrames(canvas.EmotionName);

            foreach (var action in canvas.Actions)
            {
                break;
                Gif gif          = new Gif();
                var actionFrames = canvas.GetActionFrames(action.Name);
                foreach (var frame in actionFrames)
                {
                    if (frame.Delay != 0)
                    {
                        var bone = canvas.CreateFrame(frame, faceFrames[0], null);
                        var bmp  = canvas.DrawFrame(bone, frame);

                        Point pos = bmp.OpOrigin;
                        pos.Offset(frame.Flip ? new Point(-frame.Move.X, frame.Move.Y) : frame.Move);
                        GifFrame f = new GifFrame(bmp.Bitmap, new Point(-pos.X, -pos.Y), Math.Abs(frame.Delay));
                        gif.Frames.Add(f);
                    }
                }


                var    gifFile  = gif.EncodeGif(Color.Black);
                string fileName = "D:\\ms\\" + action.Name.Replace('\\', '.');
                gifFile.Save(fileName + (gif.Frames.Count == 1 ? ".png" : ".gif"));
                gifFile.Dispose();
            }

            {
                Gif    gif      = CreateKeyDownAction(canvas);
                var    gifFile  = gif.EncodeGif(Color.Transparent, 0);
                string fileName = "D:\\d12";

                if (false)
                {
                    var fd = new System.Drawing.Imaging.FrameDimension(gifFile.FrameDimensionsList[0]);
                    //获取帧数(gif图片可能包含多帧,其它格式图片一般仅一帧)
                    int count = gifFile.GetFrameCount(fd);
                    for (int i = 0; i < count; i++)
                    {
                        gifFile.SelectActiveFrame(fd, i);
                        gifFile.Save(fileName + "_" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);
                    }
                }
                gifFile.Save(fileName + (gif.Frames.Count == 1 ? ".png" : ".gif"));
                gifFile.Dispose();
            }
        }
Exemple #27
0
 public System.Drawing.Image Mark(System.Drawing.Image img, MarkType markType, string text, System.Drawing.Image waterImg, int markx, int marky, bool bold, System.Drawing.Color textColor, float transparence, System.Drawing.FontFamily fontFamily, int fontSize, CompressSize compressSize)
 {
     Guid[] frameDimensionsList = img.FrameDimensionsList;
     System.Drawing.Image result;
     for (int i = 0; i < frameDimensionsList.Length; i++)
     {
         Guid guid = frameDimensionsList[i];
         System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(guid);
         if (img.GetFrameCount(dimension) > 1)
         {
             result = img;
             return(result);
         }
     }
     try
     {
         System.Drawing.Imaging.ImageCodecInfo    encoderInfo       = PictureWaterMark.GetEncoderInfo("image/jpeg");
         System.Drawing.Imaging.Encoder           quality           = System.Drawing.Imaging.Encoder.Quality;
         System.Drawing.Imaging.EncoderParameters encoderParameters = new System.Drawing.Imaging.EncoderParameters(1);
         System.Drawing.Imaging.EncoderParameter  encoderParameter  = new System.Drawing.Imaging.EncoderParameter(quality, 100L);
         encoderParameters.Param[0] = encoderParameter;
         if (markType == MarkType.Text)
         {
             System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
             bitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution);
             System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
             graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
             graphics.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
             graphics.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
             graphics.DrawImage(img, new System.Drawing.Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel);
             System.Drawing.Font  textFont = this.TextFont;
             System.Drawing.SizeF sizeF    = default(System.Drawing.SizeF);
             float num = this.TextFont.Size - 2f;
             if ((double)num < 0.0001)
             {
             }
             sizeF = graphics.MeasureString(this.Text, textFont);
             while ((ushort)sizeF.Width > (ushort)img.Width)
             {
                 num = this.TextFont.Size - 2f;
                 if ((double)num < 0.0001)
                 {
                     break;
                 }
                 this.TextFont = new System.Drawing.Font(this.TextFont.FontFamily, num, this.TextFont.Style);
                 sizeF         = graphics.MeasureString(this.Text, this.TextFont);
                 if ((ushort)sizeF.Width < (ushort)this.SourceImage.Width)
                 {
                     break;
                 }
             }
             int alpha = Convert.ToInt32(255f * transparence);
             System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(alpha, textColor));
             graphics.DrawString(text, textFont, brush, (float)markx, (float)marky);
             graphics.Dispose();
             img = this.ConvertBmpToNewImg(bitmap, encoderInfo, encoderParameters);
             bitmap.Dispose();
             result = img;
         }
         else
         {
             if (markType == MarkType.Image)
             {
                 float[][] array     = new float[5][];
                 float[][] arg_236_0 = array;
                 int       arg_236_1 = 0;
                 float[]   array2    = new float[5];
                 array2[0]            = 1f;
                 arg_236_0[arg_236_1] = array2;
                 float[][] arg_24D_0 = array;
                 int       arg_24D_1 = 1;
                 float[]   array3    = new float[5];
                 array3[1]            = 1f;
                 arg_24D_0[arg_24D_1] = array3;
                 float[][] arg_264_0 = array;
                 int       arg_264_1 = 2;
                 float[]   array4    = new float[5];
                 array4[2]            = 1f;
                 arg_264_0[arg_264_1] = array4;
                 float[][] arg_278_0 = array;
                 int       arg_278_1 = 3;
                 float[]   array5    = new float[5];
                 array5[3]            = transparence;
                 arg_278_0[arg_278_1] = array5;
                 array[4]             = new float[]
                 {
                     0f,
                     0f,
                     0f,
                     0f,
                     1f
                 };
                 float[][] newColorMatrix = array;
                 System.Drawing.Imaging.ColorMatrix     newColorMatrix2 = new System.Drawing.Imaging.ColorMatrix(newColorMatrix);
                 System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
                 imageAttributes.SetColorMatrix(newColorMatrix2, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Default);
                 System.Drawing.Bitmap bitmap2 = new System.Drawing.Bitmap(img.Width, img.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                 bitmap2.SetResolution(img.HorizontalResolution, img.VerticalResolution);
                 System.Drawing.Graphics graphics2 = System.Drawing.Graphics.FromImage(bitmap2);
                 graphics2.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                 graphics2.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                 graphics2.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                 graphics2.DrawImage(img, new System.Drawing.Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, System.Drawing.GraphicsUnit.Pixel);
                 if (waterImg.Width > img.Width || waterImg.Height > img.Height)
                 {
                     System.Drawing.Image.GetThumbnailImageAbort callback = null;
                     System.Drawing.Image image = null;
                     if (this.CompressSize == CompressSize.None)
                     {
                         image = this.WaterImage.GetThumbnailImage(this.SourceImage.Width, this.SourceImage.Height, callback, new IntPtr(0));
                     }
                     else
                     {
                         if (this.CompressSize == CompressSize.Compress4)
                         {
                             image = this.WaterImage.GetThumbnailImage(this.SourceImage.Width / 2, this.SourceImage.Height / 2, callback, new IntPtr(0));
                         }
                         else
                         {
                             if (this.CompressSize == CompressSize.Compress9)
                             {
                                 image = this.WaterImage.GetThumbnailImage(this.SourceImage.Width / 3, this.SourceImage.Height / 3, callback, new IntPtr(0));
                             }
                             else
                             {
                                 if (this.CompressSize == CompressSize.Compress16)
                                 {
                                     image = this.WaterImage.GetThumbnailImage(this.SourceImage.Width / 4, this.SourceImage.Height / 4, callback, new IntPtr(0));
                                 }
                             }
                         }
                     }
                     if (this.CompressSize == CompressSize.Compress25)
                     {
                         image = this.WaterImage.GetThumbnailImage(this.SourceImage.Width / 5, this.SourceImage.Height / 5, callback, new IntPtr(0));
                     }
                     if (this.CompressSize == CompressSize.Compress36)
                     {
                         image = this.WaterImage.GetThumbnailImage(this.SourceImage.Width / 6, this.SourceImage.Height / 6, callback, new IntPtr(0));
                     }
                     graphics2.DrawImage(image, new System.Drawing.Rectangle(markx, marky, image.Width, image.Height), 0, 0, image.Width, image.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes);
                     image.Dispose();
                     graphics2.Dispose();
                     img = this.ConvertBmpToNewImg(bitmap2, encoderInfo, encoderParameters);
                     bitmap2.Dispose();
                     result = img;
                 }
                 else
                 {
                     graphics2.DrawImage(waterImg, new System.Drawing.Rectangle(markx, marky, waterImg.Width, waterImg.Height), 0, 0, waterImg.Width, waterImg.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes);
                     graphics2.Dispose();
                     img = this.ConvertBmpToNewImg(bitmap2, encoderInfo, encoderParameters);
                     bitmap2.Dispose();
                     result = img;
                 }
             }
             else
             {
                 result = img;
             }
         }
     }
     catch
     {
         result = img;
     }
     return(result);
 }
 private FrameDimension(System.Drawing.Imaging.FrameDimension frameDimension)
 {
     WrappedFrameDimension = frameDimension;
 }
Exemple #29
0
        public GifInfo(string filePath)
        {
            bool isWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

            if (System.IO.File.Exists(filePath))
            {
                using (System.Drawing.Image image = System.Drawing.Image.FromFile(filePath))
                {
                    this.size = new System.Drawing.Size(image.Width, image.Height);

                    if (image.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Gif))
                    {
                        this.frames   = new System.Collections.Generic.List <System.Drawing.Image>();
                        this.fileInfo = new System.IO.FileInfo(filePath);

                        if (System.Drawing.ImageAnimator.CanAnimate(image))
                        {
                            // Get frames
                            System.Drawing.Imaging.FrameDimension dimension =
                                new System.Drawing.Imaging.FrameDimension(image.FrameDimensionsList[0]);

                            int frameCount = image.GetFrameCount(dimension);

                            int index    = 0;
                            int duration = 0;
                            for (int i = 0; i < frameCount; i++)
                            {
                                image.SelectActiveFrame(dimension, i);
                                System.Drawing.Image frame = image.Clone() as System.Drawing.Image;
                                frames.Add(frame);

                                // https://docs.microsoft.com/en-us/dotnet/api/system.drawing.imaging.propertyitem.id?view=dotnet-plat-ext-3.1
                                // 0x5100	PropertyTagFrameDelay
                                byte[] propertyArray = image.GetPropertyItem(20736).Value;

                                int delay = 0;

                                if (isWindows)
                                {
                                    delay = System.BitConverter.ToInt32(propertyArray, index) * 10;
                                }
                                else
                                {
                                    delay = System.BitConverter.ToInt32(propertyArray, 0) * 10;
                                }

                                duration += (delay < 100 ? 100 : delay);

                                index += 4;
                            } // Next i

                            this.animationDuration = System.TimeSpan.FromMilliseconds(duration);
                            this.animated          = true;
                            this.loop = System.BitConverter.ToInt16(image.GetPropertyItem(20737).Value, 0) != 1;
                        }
                        else
                        {
                            this.frames.Add(image.Clone() as System.Drawing.Image);
                        }
                    }
                    else
                    {
                        throw new System.FormatException("Not valid GIF image format");
                    }
                } // End Using image
            }     // End if (System.IO.File.Exists(filePath))
        }         // End Constructor
Exemple #30
0
        /// <summary>
        /// Creates an animated gif shape.  
        /// Do not add a very large number of these or performance may be degraded.
        /// </summary>
        /// <param name="imageName">
        /// The animated gif file (local or network) to load.
        /// </param>
        /// <param name="repeat">
        /// Continuously repeat the animation "True" or "False".
        /// </param>
        /// <returns>
        /// The animated gif shape name.
        /// </returns>
        public static Primitive AddAnimatedGif(Primitive imageName, Primitive repeat)
        {
            if (((string)imageName).StartsWith("http")) imageName = Network.DownloadFile(imageName);
            GraphicsWindow.Show();
            Type ShapesType = typeof(Shapes);
            Canvas _mainCanvas;
            string shapeName;

            try
            {
                MethodInfo method = GraphicsWindowType.GetMethod("VerifyAccess", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                method.Invoke(null, new object[] { });

                method = ShapesType.GetMethod("GenerateNewName", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
                shapeName = method.Invoke(null, new object[] { "Image" }).ToString();

                _mainCanvas = (Canvas)GraphicsWindowType.GetField("_mainCanvas", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);

                InvokeHelperWithReturn ret = new InvokeHelperWithReturn(delegate
                {
                    try
                    {
                        System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(imageName);
                        System.Drawing.Imaging.FrameDimension fd = new System.Drawing.Imaging.FrameDimension(bitmap.FrameDimensionsList[0]);
                        int frameCount = bitmap.GetFrameCount(fd);

                        if (frameCount > 1)
                        {
                            Animated anim = new Animated();
                            animated.Add(anim);
                            anim.name = shapeName;
                            anim.frames = new Frame[frameCount];
                            anim.repeat = repeat;

                            //0x5100 is the property id of the GIF frame's durations
                            //this property does not exist when frameCount <= 1
                            byte[] times = bitmap.GetPropertyItem(0x5100).Value;

                            for (int i = 0; i < frameCount; i++)
                            {
                                //selects GIF frame based on FrameDimension and frameIndex
                                bitmap.SelectActiveFrame(fd, i);

                                //length in milliseconds of display duration
                                int length = BitConverter.ToInt32(times, 4 * i) * 10;

                                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                                new System.Drawing.Bitmap(bitmap).Save(stream, System.Drawing.Imaging.ImageFormat.Png);

                                BitmapImage bi = new BitmapImage();
                                bi.BeginInit();
                                bi.StreamSource = stream;
                                bi.EndInit();

                                anim.frames[i] = new Frame(length, bi);
                            }

                            Image shape = new Image();
                            shape.Source = anim.frames[0].bi;
                            shape.Stretch = Stretch.Fill;
                            shape.Name = shapeName;
                            shape.Width = shape.Source.Width;
                            shape.Height = shape.Source.Height;
                            anim.shape = shape;

                            if (null == animationTimer)
                            {
                                animationTimer = new System.Windows.Forms.Timer();
                                animationTimer.Enabled = animationInterval > 0;
                                if (animationInterval > 0) animationTimer.Interval = animationInterval;
                                animationTimer.Tick += new System.EventHandler(animation_Tick);
                            }

                            _objectsMap[shapeName] = shape;
                            _mainCanvas.Children.Add(shape);
                            return shapeName;
                        }
                        return "";
                    }
                    catch (Exception ex)
                    {
                        Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                        return "";
                    }
                });
                return FastThread.InvokeWithReturn(ret).ToString();
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                return "";
            }
        }
Exemple #31
0
        void OnGUI()
        {
            string sourcePath = Application.dataPath + IntputFolder;

            GUILayout.Space(15);

            GUILayout.Label("Settings", EditorStyles.boldLabel);

            GUILayout.Space(15);

            #region OutputFolder Selection

            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Input GIF Path");
            GUIStyle outPtBtn = new GUIStyle(GUI.skin.button);
            outPtBtn.alignment = TextAnchor.MiddleLeft;
            if (GUILayout.Button(IntputFolder.Length == 0 ? "Click To Select Path" : IntputFolder, outPtBtn))
            {
                string returnPath = EditorUtility.OpenFolderPanel("Select Input Directory", IntputFolder.Length == 0 ? Application.dataPath : Application.dataPath, "");
                Debug.Log("Return pATH : " + returnPath);
                if (returnPath.Length > 0)
                {
                    if (returnPath.Contains(Application.dataPath))
                    {
                        returnPath = returnPath.Substring(Application.dataPath.Length);
                        returnPath = "Assets" + returnPath;
                    }
                    IntputFolder = returnPath;
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Output Folder Path");
            GUIStyle alignLeft = new GUIStyle(GUI.skin.button);
            alignLeft.alignment = TextAnchor.MiddleLeft;
            if (GUILayout.Button(OutputFolder.Length == 0 ? "Click To Select Path" : OutputFolder, alignLeft))
            {
                string returnPath = EditorUtility.OpenFolderPanel("Select Output Folder", OutputFolder.Length == 0 ? Application.dataPath : Application.dataPath, "");

                if (returnPath.Length > 0)
                {
                    if (returnPath.Contains(Application.dataPath))
                    {
                        returnPath = returnPath.Substring(Application.dataPath.Length);
                        returnPath = "Assets" + returnPath;
                    }
                    OutputFolder = returnPath;
                }

                //Set Compress texture search folder
                var allStr = OutputFolder.Split('/');
                OuputTextureSearchFolder = allStr[allStr.Length - 1];
            }
            GUILayout.EndHorizontal();



            #endregion

            SplitExtension = EditorGUILayout.TextField("SplitExtension", SplitExtension);

            CompressTexture = EditorGUILayout.Toggle("CompressTexture", CompressTexture);
            if (CompressTexture == true)
            {
                OverrideTexture    = EditorGUILayout.Toggle("Override for Platfrom", OverrideTexture);
                platformSelect     = EditorGUILayout.Popup("Platform", platformSelect, m_platform);
                Platform           = m_platform[platformSelect];
                spriteImportMode   = (SpriteImportMode)EditorGUILayout.EnumPopup("Sprite Mode", spriteImportMode);
                selectFormatEnum   = (TextureImporterFormat)EditorGUILayout.EnumPopup("Compression mode", selectFormatEnum);
                CompressionQuality = EditorGUILayout.IntSlider("CompressionQuality", CompressionQuality, 0, 100);
                TextureSize        = EditorGUILayout.IntPopup("Texture Size", TextureSize, m_textureSize, i_textureSize);
                MipmapEnabled      = EditorGUILayout.Toggle("MipmapEnabled", MipmapEnabled);
            }
            GUILayout.FlexibleSpace();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Cancel"))
            {
                Close();
            }
            else if (GUILayout.Button("Convert"))
            {
#if UNITY_EDITOR_WIN
                //path
                string fullPath = Application.dataPath + IntputFolder.Substring("Assets".Length);

                if (Directory.Exists(fullPath))
                {
                    DirectoryInfo direction = new DirectoryInfo(fullPath);
                    FileInfo[]    files     = direction.GetFiles("*", SearchOption.AllDirectories);

                    Debug.Log("InputFolder :" + IntputFolder + " Convert Count : " + files.Length / 2); //cause meta file
                    Debug.Log("OutpuFolder :" + OutputFolder);

                    for (int i = 0; i < files.Length; i++)
                    {
                        if (files[i].Name.EndsWith(".gif"))
                        {
                            sourcePath = fullPath + "/" + files[i].Name;


                            var outputFullFolderPath = Application.dataPath + OutputFolder.Substring("Assets".Length) + "/" + files[i].Name.Substring(0, files[i].Name.Length - 4);

                            if (!Directory.Exists(outputFullFolderPath))
                            {
                                AssetDatabase.CreateFolder(OutputFolder, files[i].Name.Substring(0, files[i].Name.Length - 4));
                            }

                            using (Image gifImg = Image.FromFile(sourcePath))
                            {
                                System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(gifImg.FrameDimensionsList.First());


                                for (int k = 0; k < gifImg.GetFrameCount(dimension); k++)
                                {
                                    int finalWidth  = gifImg.Width;
                                    int finalHeight = gifImg.Height;

                                    using (Bitmap finalSprite = new Bitmap(finalWidth, finalHeight))
                                    {
                                        using (System.Drawing.Graphics canvas = System.Drawing.Graphics.FromImage(finalSprite))
                                        {
                                            canvas.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                                            canvas.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                                            gifImg.SelectActiveFrame(dimension, k);
                                            using (Bitmap frame = new Bitmap(gifImg, finalWidth, finalHeight))
                                            {
                                                canvas.DrawImage(frame, 0, 0);
                                            }

                                            canvas.Save();

                                            var    tmpPath    = outputFullFolderPath + "/" + files[i].Name;
                                            string targetPath = tmpPath.Substring(0, tmpPath.Length - 4) + SplitExtension + k + ".png";


                                            finalSprite.Save(targetPath, System.Drawing.Imaging.ImageFormat.Png);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    AssetDatabase.Refresh();
                }
#endif
                Close();
            }
            GUILayout.EndHorizontal();
        }
Exemple #32
0
 public int SelectActiveFrame(System.Drawing.Imaging.FrameDimension dimension, int frameIndex)
 {
 }
Exemple #33
0
 public int GetFrameCount(System.Drawing.Imaging.FrameDimension dimension)
 {
 }
Exemple #34
0
        public void LoadFrames()
        {
            System.Drawing.Imaging.FrameDimension frameDimension = new System.Drawing.Imaging.FrameDimension(Image.FrameDimensionsList[0]);
            Data.FramesCount = Image.GetFrameCount(frameDimension);

            for (int i = 0; i < Image.GetFrameCount(frameDimension); i++)
            {
                Image.SelectActiveFrame(frameDimension, i);
                Quantizer = new ImageManipulation.OctreeQuantizer(255, 8);

                System.Drawing.Bitmap quantized = Quantizer.Quantize(Image);
                MemoryStream stream = new MemoryStream();
                quantized.Save(stream, System.Drawing.Imaging.ImageFormat.Gif);
                Data.Frames.Add(new Texture(stream));

                stream.Dispose();

                Data.Frames[i].Smooth = true;
            }
        }
Exemple #35
0
        private void crearPdf_2(string rutaFinal)
        {
            try
            {
                lbl_pdfconvertir.Text = "Convirtiendo a PDF/A...";
                lbl_pdfconvertir.Refresh();
                string ruta_archivo = convertidor_path;
                System.Drawing.Image actualBitmap_ = System.Drawing.Image.FromFile(ruta_archivo);
                Guid objGuid = actualBitmap_.FrameDimensionsList[0];
                System.Drawing.Imaging.FrameDimension objDimension = new System.Drawing.Imaging.FrameDimension(objGuid);
                int total_page = actualBitmap_.GetFrameCount(objDimension);
                actualBitmap_.SelectActiveFrame(objDimension, 0);



                garbage_collector();
                var width0  = actualBitmap_.Width;
                var height0 = actualBitmap_.Height;
                iTextSharp.text.Rectangle cero = new iTextSharp.text.Rectangle(width0, height0);

                doc_pdf = new Document(cero, 0, 0, 0, 0);

                doc_pdf.SetMargins(0, 0, 0, 0);
                PdfWriter writer = PdfWriter.GetInstance(doc_pdf, new FileStream(rutaFinal, FileMode.Create));
                writer.PDFXConformance = PdfWriter.PDFA1B;
                doc_pdf.Open();

                PdfDictionary outi = new PdfDictionary(PdfName.OUTPUTINTENT);
                outi.Put(PdfName.OUTPUTCONDITIONIDENTIFIER, new PdfString("sRGB IEC61966-2.1"));
                outi.Put(PdfName.INFO, new PdfString("sRGB IEC61966-2.1"));
                outi.Put(PdfName.S, PdfName.GTS_PDFA1);

                //Perfiles icc
                var path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
                path = path.Replace("file:\\", "");
                ICC_Profile icc = ICC_Profile.GetInstance(path + @"\sRGB_v4.icc");
                PdfICCBased ib  = new PdfICCBased(icc);
                ib.Remove(PdfName.ALTERNATE);
                outi.Put(PdfName.DESTOUTPUTPROFILE, writer.AddToBody(ib).IndirectReference);

                writer.ExtraCatalog.Put(PdfName.OUTPUTINTENTS, new PdfArray(outi));
                BaseFont             bf = BaseFont.CreateFont(path + @"\arial.ttf", BaseFont.WINANSI, true);
                iTextSharp.text.Font f  = new iTextSharp.text.Font(bf, 12);

                float subtrahend0 = doc_pdf.PageSize.Height - 10;

                iTextSharp.text.Image pool0;
                pool0 = iTextSharp.text.Image.GetInstance(actualBitmap_, System.Drawing.Imaging.ImageFormat.Gif);

                pool0.Alignment = 3;
                pool0.ScaleToFit(doc_pdf.PageSize.Width - (doc_pdf.RightMargin * 2), subtrahend0);
                doc_pdf.Add(pool0);
                garbage_collector();
                //Crear las paginas
                for (int i = 1; i < total_page; ++i)
                {
                    actualBitmap_.SelectActiveFrame(objDimension, i);
                    float Width  = actualBitmap_.Width;
                    float Height = actualBitmap_.Height;
                    Task  task1  = Task.Factory.StartNew(() => pdf_paralelo_page(actualBitmap_));
                    Task  task2  = Task.Factory.StartNew(() => pdf_paralelo_doc(Width, Height));
                    Task.WaitAll(task1, task2);
                    doc_pdf.Add(page_prop_pdf);
                    decimal porcentaje = ((decimal)i / (decimal)total_page);
                    progressBar1.Value = (int)(porcentaje * 100);
                    progressBar1.Refresh();
                    garbage_collector();
                }
                progressBar1.Value = 100;
                writer.CreateXmpMetadata();
                doc_pdf.Close();
                actualBitmap_.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Falla de sistema en la conversión a PDF/A", title);
                if (ex.ToString().Contains("utilizado en otro proceso"))
                {
                    MessageBox.Show("El PDF esta siendo utilizado en otro proceso", title);
                }
                MessageBox.Show(ex.ToString(), title);
                garbage_collector();
            }
            garbage_collector();
        }