Exemplo n.º 1
0
        //
        // GET: /Benchmark/
        public ActionResult Index()
        {
            var message = "\nReduced images sizes:\n\n";
            var lastByteSize = 0L;
            var demoModel = new DemoModel();
            var imageGenerator = new ImageGenerator();
            var bitmap = imageGenerator.GenerateDemoImage(Server.MapPath("~/Images/"), demoModel.IconName, demoModel.ForecastText);

            //un-reduced size
            using (var ms = new MemoryStream())
            {
                bitmap.Save(ms, ImageFormat.Png);
                message += string.Format("Unreduced size was {0} bytes.\n\n", ms.Length);
            }

            //calculate the size of each reducers output png image
            foreach (var reducer in demoModel.PngColorReducers)
            {
                IPngColorReducer colorReducer = PngColorReducerFactory.GetReducer(reducer);

                var pngStream = colorReducer.ReduceColorDepth(bitmap);
                lastByteSize = pngStream.Length;

                message += string.Format("{0} size was {1} bytes.\n\n", reducer, lastByteSize);
            }

            bitmap.Dispose();
            ViewData["Message"] = message;
            return View();
        }
Exemplo n.º 2
0
 public FileResult Show(ImageModel imageModel)
 {
     var imageGenerator = new ImageGenerator();
     MemoryStream pngStream;
     using (var bitmap = imageGenerator.GenerateDemoImage(Server.MapPath("~/Images/"), imageModel.Icon, imageModel.Text))
     {
         IPngColorReducer colorReducer = PngColorReducerFactory.GetReducer((PngColorReducers)imageModel.Id);
         pngStream = colorReducer.ReduceColorDepth(bitmap);
     }
     return new FileStreamResult(pngStream, "image/png");
 }