Пример #1
0
        private void GetFrames(DMIState state, FreeImageBitmap img)
        {
            for (int i = 0; i < state.Frames; i++)
            {
                int[] dirs  = { Directions.SOUTH, Directions.NORTH, Directions.EAST, Directions.WEST, Directions.SOUTHEAST, Directions.SOUTHWEST, Directions.NORTHEAST, Directions.NORTHWEST };
                var   frame = new DMIFrame(state.GetDelay(i));
                for (int j = 0; j < state.Dir; j++)
                {
                    int dir = dirs[j];

                    if (_pixelX >= img.Width)
                    {
                        _pixelX  = 0;
                        _pixelY += StateHeight;
                    }
                    Bitmap frameBitmap;
#if (ASEPRITE_LOAD)
                    //                       string getString = "./in/FromAse/NabFinalParts/r_nabber" + state.colourStr + " (" + state.Name + ") " + Directions.DirToAse(dir) + ".png";
                    string          getString = "./in/FromAse/NabFinalParts/r_nabber" + state.colourStr + " (" + state.Name + ") " + Directions.DirToAse(dir) + ".png";
                    FreeImageBitmap inImage   = new FreeImageBitmap(getString);
                    frameBitmap = inImage.ToBitmap();
#else
                    frameBitmap = img.Copy(new Rectangle(_pixelX, _pixelY, StateWidth, StateHeight)).ToBitmap();
#endif
                    frame.Add(new DMIImageData(frameBitmap, dir));
                    _pixelX += StateWidth;
                }
                state.Add(frame);
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            // string path = (@"E:\C\work\2019-07-00\贴图流程化测试\eeee.tga");
            string path = args[0];

            FreeImageBitmap ne      = new FreeImageBitmap(path, FREE_IMAGE_FORMAT.FIF_TARGA);
            Size            b       = ne.Size;
            int             image_h = b.Height;
            int             image_w = b.Width;
            /// 这里抛出移除是因为会当做方块来循环, 应该是小


            // FreeImageBitmap new_tem = new FreeImageBitmap(image_w, image_h);
            Bitmap new_tem = new Bitmap(image_w, image_h);

            Color tt = ne.GetPixel(0, 0); /// 优先获得高度 在高度上去处理 宽度

            Console.WriteLine(image_w);


            Bitmap ne_type = (Bitmap)ne.ToBitmap();

            ne.Dispose();

            for (int i = 0; i < image_h; i++)
            {
                for (int j = 0; j < image_w; j++)
                {
                    //Color t = ne.GetPixel(i, j); /// 优先获得高度 在高度上去处理 宽度
                    Color t = ne_type.GetPixel(j, i);

                    Program pro       = new Program();
                    Color   srgbcolor = pro.linetosrgb(t);
                    new_tem.SetPixel(j, i, srgbcolor);
                }
            }

            ///对图形处理完成
            ///
            FreeImageBitmap yy = new FreeImageBitmap(new_tem);

            yy.Save(path);
        }
Пример #3
0
        public static void FreeImageSaveExrBitmap(string fileName, int width, int height, RgbSpectrum[] data, string[] watermark = null)
        {
            using (var bmp = new FreeImageBitmap(width, height, FREE_IMAGE_TYPE.FIT_RGBF))
            {
                for (int i = 0; i < bmp.Height; i++)
                {
                    Scanline<FIRGBF> s = bmp.GetScanline<FIRGBF>(i);
                    for (int j = 0; j < bmp.Width; j++)
                    {
                        try
                        {
                            var spectra = data[j + i * bmp.Width];
                            s[j] = new FIRGBF()
                            {
                                blue = spectra.c3,
                                green = spectra.c2,
                                red = spectra.c1
                            };
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
                if (watermark != null)
                {
                    ApplyWaterMark(10, 400, bmp.ToBitmap(), watermark);
                }

                bmp.Save(fileName, FREE_IMAGE_FORMAT.FIF_EXR, FREE_IMAGE_SAVE_FLAGS.EXR_NONE);
                bmp.TmoReinhard05(1, 0.4);
                bmp.Save(fileName, FREE_IMAGE_FORMAT.FIF_PNG);
            }
        }
Пример #4
0
        /// <summary>
        /// 根据传入图片判读图片格式是什么格式  格式只是识别 rgb argb
        //// 返回 0 文件路径不对 或者格式不对
        //// 返回 24 32 说明通道企管科
        /// </summary>
        /// <returns></returns>
        public int is3224()
        {
            if (!File.Exists(this.imagepath))
            {
                ///路径不对也是按户籍0
                return(0);
            }

            FreeImageBitmap fb = new FreeImageBitmap(this.imagepath);

            Bitmap bim = fb.ToBitmap();

            fb.Dispose();
            ///这里只是处理美术用的2中格式 rgb argb  其他返回0
            ///
            PixelFormat imformat = bim.PixelFormat;

            if (imformat == PixelFormat.Format24bppRgb)
            {
                bim.Dispose();
                return(24);
            }
            else if (imformat == PixelFormat.Format32bppArgb)
            {
                //// 这里还要判断是不是真的32位, 对于有一个a通道但是全是纯白的,这种情况就是假的a通道, 会当作24处理
                /// 最后返回的还是 24
                ///
                int wdith  = bim.Width;
                int height = bim.Height;
                for (int i = 0; i < height; i++)
                {
                    for (int fo = 0; fo < wdith; fo++)
                    {
                        /// 防止加入变大 从0开始
                        if (fo > wdith - 1)
                        {
                            fo = wdith - 1;
                        }
                        ;
                        if (i > height - 1)
                        {
                            i = height - 1;
                        }
                        ;

                        Color cl = bim.GetPixel(fo, i);
                        if (cl.A != this.bai)
                        {
                            /// 本来这里就是告诉你这里使用的是32位图,有一个不是255 就告诉你 就是32 不用在处理的
                            /// 直接返回你就是32位
                            return(32);
                        }


                        fo += this.ina;
                    }
                    i += this.ina;
                }

                /// 处理完成之后每10 像素采样完成 都是白色 直接返回 24
                return(24);
            }
            else
            {
                bim.Dispose();

                //// 对于其他格式一律不处理  返回0 表示该图有问题
                return(0);
            }
        }
Пример #5
0
        /**
         */
        private void updateImages(int index)
        {
            float[] array;
            float   maxValue, minValue, value;
            int     value16bpp;
            Bitmap  bitmap;
            Color   color;
            Image   old_bitmap;

            if (base_dimensions != null)
            {
                int width  = base_dimensions[0];
                int height = base_dimensions[1];

                array = new float[width * height];
                Array.Copy(base_data, width * height * index, array, 0, width * height);

                FreeImageBitmap image_bitmap = new FreeImageBitmap(new Bitmap(width, height), width, height);
                maxValue = Enumerable.Range(0, array.Length).Max(m => array[m]);
                minValue = Enumerable.Range(0, array.Length).Min(m => array[m]);
                for (int j = 0; j < height; ++j)
                {
                    Scanline <int> scanline = image_bitmap.GetScanline <int>(j);

                    for (int k = 0; k < width; ++k)
                    {
                        value      = array[width * j + k];
                        value16bpp = (int)(255.0f / (maxValue - minValue) * (value - minValue));
                        color      = Color.FromArgb(value16bpp, value16bpp, value16bpp);
                        scanline.SetValue(color.ToArgb(), k);
                    }
                }

                image_bitmap.RotateFlip(base_orientation);
                bitmap = image_bitmap.ToBitmap();
                image_bitmap.Dispose();

                old_bitmap       = image_base.Image;
                image_base.Image = bitmap;
                if (old_bitmap != null)
                {
                    old_bitmap.Dispose();
                }
            }



            if (sliver_dimensions != null)
            {
                int width  = sliver_dimensions[0];
                int height = sliver_dimensions[1];

                array = new float[width * height];
                Array.Copy(sliver_data, width * height * index, array, 0, width * height);
                FreeImageBitmap image_bitmap = new FreeImageBitmap(new Bitmap(width, height), width, height);
                maxValue = Enumerable.Range(0, array.Length).Max(m => array[m]);
                minValue = Enumerable.Range(0, array.Length).Min(m => array[m]);
                for (int j = 0; j < height; ++j)
                {
                    Scanline <int> scanline = image_bitmap.GetScanline <int>(j);

                    for (int k = 0; k < width; ++k)
                    {
                        value      = array[width * j + k];
                        value16bpp = (int)(255.0f / (maxValue - minValue) * (value - minValue));
                        color      = Color.FromArgb(value16bpp, value16bpp, value16bpp);
                        scanline.SetValue(color.ToArgb(), k);
                    }
                }

                image_bitmap.RotateFlip(sliver_orientation);
                bitmap = image_bitmap.ToBitmap();
                image_bitmap.Dispose();

                old_bitmap         = image_sliver.Image;
                image_sliver.Image = bitmap;
                if (old_bitmap != null)
                {
                    old_bitmap.Dispose();
                }
            }
        }