示例#1
0
文件: Form1.cs 项目: FMI-VT/API
        private void button3_Click(object sender, EventArgs e)
        {
            int w = Convert.ToInt32(txtwidth.Text);
            int h = Convert.ToInt32(txtheight.Text);

            ImageProcess.Resizer.Resize resize = new ImageProcess.Resizer.Resize(label1.Text, label5.Text, comboBox1.Text, w, h);

            resize.Execute();
            MessageBox.Show("Image saved!");
        }
示例#2
0
        static void Main(string[] args)
        {
            //    ImageProcess.Converter.Convert convert = new ImageProcess.Converter.Convert(@"D:\test\test.gif", @"Dsdasd\test\test", "png");
            //    convert.Execute();


            //skew and keepaspect have to have different dest path (can not be same as src path);
            ImageProcess.Resizer.Resize resize = new ImageProcess.Resizer.Resize(@"D:\test\k.gif", @"D:\test\k.gif", "skew", 600, 400);
            resize.Execute();
            Console.ReadKey(true);
        }
示例#3
0
        public IHttpActionResult Post(ResizeBindModel model)
        {
            try
            {
                if (model == null)
                {
                    return(BadRequest("Model can not be null. Please fill up the model data."));
                }

                if (model.height < 1)
                {
                    return(BadRequest("Height is invalid. It must be bigger than 0."));
                }

                if (model.width < 1)
                {
                    return(BadRequest("Width is invalid. It must be bigger than 0."));
                }

                ImageProcess.Resizer.Resize resize = new ImageProcess.Resizer.Resize(model.srcPath, model.destPath, model.type, model.width, model.height, model.x, model.y);
                resize.Execute();
                return(Created(model.destPath, model));
            }

            catch (MyFileNotFoundException)
            {
                return(BadRequest("File with path  " + model.srcPath + " not found."));
            }
            catch (SourceAndDestPathException)
            {
                return(BadRequest("Source or Destination path is an empty string, null or contains invalid characters."));
            }
            catch (UnsupportedDestPathException)
            {
                return(BadRequest("Destination path " + model.destPath + " is in an invalid format."));
            }
            catch (MyOutOfMemoryException)
            {
                if (model.type.ToLower() == "keepaspect")
                {
                    return(BadRequest("There is not enough memory to continue the execution of a program. Please keep image's aspect! Try with diffrent width and/or height."));
                }
                return(BadRequest("There is not enough memory to continue the execution of a program. Height " + model.height + " or width " + model.width + " is invalid. Please try smaller size."));
            }
            catch (MySystemException)
            {
                return(BadRequest("There is a problem with source path or destionation path. Please save resized image with new name that is diffrent from source image's name!"));
            }
        }
示例#4
0
文件: Program.cs 项目: FMI-VT/API
        static void Main(string[] args)
        {
            var srcpath  = "";
            var destpath = "";
            var type     = "";
            int height   = Convert.ToInt32(true);
            int width    = Convert.ToInt32(true);


            Console.WriteLine("Welcome");
            Console.WriteLine("[C]onvert or [R]esize");
            string choice = Console.ReadLine();

            switch (choice.ToUpper())
            {
            case "C":
            {
                Console.WriteLine("Add source image:");
                srcpath = Console.ReadLine();
                Console.WriteLine("Where to save image:");
                destpath = Console.ReadLine();
                Console.WriteLine("Add image type(jpg / gif / png)?");
                type = Console.ReadLine();

                ImageProcess.Converter.Convert convert = new ImageProcess.Converter.Convert(srcpath, destpath, type);
                convert.Execute();
                Console.WriteLine("Done!");
                break;
            }

            case "R":
            {
                Console.WriteLine("Add source image:");
                srcpath = Console.ReadLine();
                Console.WriteLine("Where to save image:");
                destpath = Console.ReadLine();
                Console.WriteLine("Add image height:");
                height = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Add image width:");
                width = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Add resizing type(crop / keepaspect / skew )?");
                type = Console.ReadLine();

                ImageProcess.Resizer.Resize resize = new ImageProcess.Resizer.Resize(srcpath, destpath, type, width, height);
                resize.Execute();
                Console.WriteLine("Done!");
                break;
            }
            }



            // ImageProcess.Resizer.Resize resize = new ImageProcess.Resizer.Resize(srcpath,destpath, type, width, height);
            // resize.Execute();
            // Console.WriteLine("Done!");

            /*
             * ImageProcess.Converter.Convert convert = new ImageProcess.Converter.Convert(@"E:\fox.jpg", @"E:\foxCon.gif", "gif");
             * convert.Execute();
             * Console.WriteLine("Done!");
             *
             * //1.59
             *
             * ImageProcess.Resizer.Resize resize = new ImageProcess.Resizer.Resize(@"E:\fox.jpg", @"E:\fox1.jpg", "keepaspect",350,220 );
             * resize.Execute();
             * Console.WriteLine("Done!");
             *
             *
             * ImageProcess.Resizer.Resize resize = new ImageProcess.Resizer.Resize(@"E:\fox.jpg", @"E:\fox1.jpg", "skew", 480, 220);
             * resize.Execute();
             * Console.WriteLine("Done!");
             */
        }