示例#1
0
        public void CreateImagesForOtherColor(int campaignId, string prodIdAndColor, CampaignProductRecord p,
                                              DesignInfo data, string frontPath, string backPath, string color)
        {
            var destForder = Path.Combine(Server.MapPath("/Media/campaigns/"), campaignId.ToString(), prodIdAndColor);

            if (!Directory.Exists(destForder))
            {
                Directory.CreateDirectory(destForder);
            }

            if (!Directory.Exists(destForder + "/normal"))
            {
                Directory.CreateDirectory(destForder + "/normal");
            }
            if (!Directory.Exists(destForder + "/big"))
            {
                Directory.CreateDirectory(destForder + "/big");
            }

            var frontTemplate = new Bitmap(frontPath);
            var backTemplate  = new Bitmap(backPath);

            var rgba = ColorTranslator.FromHtml(color);

            var front = BuildProductImage(frontTemplate, _imageHelper.Base64ToBitmap(data.Front), rgba,
                                          p.ProductRecord.ProductImageRecord.Width, p.ProductRecord.ProductImageRecord.Height,
                                          p.ProductRecord.ProductImageRecord.PrintableFrontTop,
                                          p.ProductRecord.ProductImageRecord.PrintableFrontLeft,
                                          p.ProductRecord.ProductImageRecord.PrintableFrontWidth,
                                          p.ProductRecord.ProductImageRecord.PrintableFrontHeight);

            front.Save(Path.Combine(destForder, "normal", "front.png"));

            var back = BuildProductImage(backTemplate, _imageHelper.Base64ToBitmap(data.Back), rgba,
                                         p.ProductRecord.ProductImageRecord.Width, p.ProductRecord.ProductImageRecord.Height,
                                         p.ProductRecord.ProductImageRecord.PrintableBackTop,
                                         p.ProductRecord.ProductImageRecord.PrintableBackLeft,
                                         p.ProductRecord.ProductImageRecord.PrintableBackWidth,
                                         p.ProductRecord.ProductImageRecord.PrintableBackHeight);

            back.Save(Path.Combine(destForder, "normal", "back.png"));

            _imageHelper.ResizeImage(front, p.ProductRecord.ProductImageRecord.Width * 2, p.ProductRecord.ProductImageRecord.Height * 2).Save(Path.Combine(destForder, "big", "front.png"));
            _imageHelper.ResizeImage(back, p.ProductRecord.ProductImageRecord.Width * 2, p.ProductRecord.ProductImageRecord.Height * 2).Save(Path.Combine(destForder, "big", "back.png"));

            frontTemplate.Dispose();
            backTemplate.Dispose();
            front.Dispose();
            back.Dispose();
        }
示例#2
0
        private ProductImageSavingResult SaveProductFrontImage(HttpPostedFileBase imageFile, ProductRecord product)
        {
            if (imageFile == null)
            {
                return(null);
            }

            if (!IsImagePng(imageFile))
            {
                _orchardServices.Notifier.Error(
                    T("Front Image file should be *.png.",
                      ProductImageWidth,
                      ProductImageHeight));

                return(null);
            }

            using (var image = Image.FromStream(imageFile.InputStream, true, true))
            {
                if (image.Width != ProductImageWidth || image.Height != ProductImageHeight)
                {
                    _orchardServices.Notifier.Error(
                        T("Front Image should be {0}x{1}.",
                          ProductImageWidth,
                          ProductImageHeight));

                    return(null);
                }

                var imageFileName     = string.Format(ProductImageFrontFileNameTemplate, product.Id);
                var imagePhysicalPath = Path.Combine(Server.MapPath(ProductImagesRelativePath), imageFileName);

                image.Save(imagePhysicalPath, ImageFormat.Png);

                var smallImageBitmap = _imageHelper.ResizeImage(
                    image,
                    ProductImageFrontSmallWidth,
                    ProductImageFrontSmallHeight);

                var smallImageFileName     = string.Format(ProductImageFrontSmallFileNameTemplate, product.Id);
                var smallImagePhysicalPath = Path.Combine(Server.MapPath(ProductImagesRelativePath), smallImageFileName);

                smallImageBitmap.Save(smallImagePhysicalPath, ImageFormat.Png);

                return(new ProductImageSavingResult
                {
                    Width = image.Width,
                    Height = image.Height
                });
            }
        }