Пример #1
0
        private static void ProcessFile(string inputPath, string outputPath, int maxWidth, int maxHeight, bool forceOverride)
        {
            Bitmap fileImg    = (Bitmap)Image.FromFile(inputPath);
            Bitmap destImg    = ImageScaler.Resize(fileImg, maxWidth, maxHeight);
            string folderPath = Path.GetDirectoryName(Path.GetFullPath(outputPath));

            if (!Directory.Exists(folderPath))
            {
                Console.WriteLine(string.Format("Create direcotry: {0}", folderPath));
                Directory.CreateDirectory(folderPath);
            }
            Console.WriteLine(string.Format("File processed: {0}", outputPath));
            if (File.Exists(outputPath))
            {
                if (forceOverride)
                {
                    Console.WriteLine("File override: " + outputPath);
                    destImg.Save(outputPath);
                }
                else
                {
                    Console.WriteLine("File exist. Skip file: " + outputPath);
                }
            }
            else
            {
                destImg.Save(outputPath);
            }
        }
Пример #2
0
        public static Texture FlushTextures()
        {
            var count = Textures.Count;

            TexturesPerLine = 1 << (int)Math.Ceiling(Math.Log(Math.Ceiling(Math.Sqrt(count))) / Math.Log(2));
            var wid = TexturesPerLine * pixelPerTexture;

            using (Texture texture = Texture.New2D(Context.GraphicsDevice, wid, wid, PixelFormat.R8G8B8A8_UNorm),
                   result = Texture.New2D(Context.GraphicsDevice, pixelPerTexture, pixelPerTexture,
                                          PixelFormat.R8G8B8A8_UNorm, TextureFlags.RenderTarget | TextureFlags.ShaderResource))
            {
                using (var scaler = new ImageScaler(SamplingPattern.Linear))
                {
                    scaler.SetOutput(result);
                    for (var i = 0; i < count; ++i)
                    {
                        var tile = Textures[i];
                        scaler.SetInput(tile);
                        scaler.Draw(Context.RdwContext);
                        var x  = i % TexturesPerLine;
                        var y  = i / TexturesPerLine;
                        var rx = x * pixelPerTexture;
                        var ry = y * pixelPerTexture;
                        Context.RdwContext.CommandList.CopyRegion(
                            result, result.GetSubResourceIndex(0, 0), null,
                            texture, texture.GetSubResourceIndex(0, 0), rx, ry);
                    }

                    return(MakeMipmap(texture, (int)Math.Floor(Math.Log(pixelPerTexture) / Math.Log(2)), scaler));
                }
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            var image = ImageManager.GetSampleImage();

            var imageScaler = new ImageScaler();
            var scaledImage = imageScaler.ScaleTo(image, 10, InterpolationMethod.NearestNeighbour);

            ImageManager.SaveImage(scaledImage, Assembly.GetExecutingAssembly());
        }
Пример #4
0
        /// <summary>
        /// Create a new instance of the class.
        /// </summary>
        /// <param name="context">the context</param>
        public RadiancePrefilteringGGXNoCompute(RenderContext context)
            : base(context, "RadiancePrefilteringGGX")
        {
            shader = new ImageEffectShader("RadiancePrefilteringGGXNoComputeEffect");
            DoNotFilterHighestLevel = true;
            samplingsCount          = 1024;

            scaler = new ImageScaler(SamplingPattern.Expanded);
            scaler.Initialize(context);
        }
Пример #5
0
        public async Task <IActionResult> UserAvatar(string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return(BadRequest());
            }
            var user = await userManager.FindByIdAsync(userId);

            return(user?.Avatar == null || user.Avatar.Length == 0
                ? File(ImageScaler.ScaleImage(Resource.DefaultAvatar, 128, 128), "image/png")
                : File(ImageScaler.ScaleImage(user.Avatar, 128, 128), "image/png"));
        }
        protected override AttachmentPanelDecoratorBase_NonGeneric CreateAttachmentDecorator(string filePath)
        {
            byte[] fileData   = File.ReadAllBytes(filePath);
            var    photoModel = new PhotoAttachmentModel
            {
                добавить сохранение фул блоба и сжатие превью
                   PreviewDataBlob  = ImageScaler.ScaleToPreview(fileData),
                   TypeOfAttachment = AttachmentType.Photo,
                   RootSubjectType  = subject?.TypeOfSubject ?? SubjectType.None,
                   RootSubjectId    = subject == null ? "" : RootSubjectIdentifier.Identify(subject)
            };

            return(new PhotoPanelDecorator(PhotoAttachmentViewModel.CreateEditable(photoModel)));
        }
        private static void checkResizeImage(string imageFilePath, int width, int height)
        {
            // 2013-05-20, Uwe Keim:
            // Das Bild so in der Größe anpassen, wie es im HTML auch tatsächlich angegeben wurde.

            if (width > 0 && height > 0 && !String.IsNullOrEmpty(imageFilePath) && File.Exists(imageFilePath))
            {
                using (var img = ImageHelper.LoadImage(imageFilePath))
                {
                    if (img.Width != width || img.Height != height)
                    {
                        using (var img2 = ImageScaler.ScaleImage(img, width, height))
                        {
                            ImageHelper.SaveImage(img2, imageFilePath);
                        }
                    }
                }
            }
        }
Пример #8
0
        private static Image <Rgba32> ZoomImage(Image <Rgba32> image, float zoom, int xMin, int xMax, int yMin, int yMax)
        {
            var newImg = new Image <Rgba32>(xMax - xMin, yMax - yMin);

            for (var y = yMin; y < yMax; ++y)
            {
                for (var x = xMin; x < xMax; ++x)
                {
                    var newY = y - yMin;
                    var newX = x - xMin;

                    newImg[newX, newY] = image[x, y];
                }
            }

            var imageScaler = new ImageScaler();

            return(imageScaler.ScaleTo(newImg, zoom, InterpolationMethod.Billinear));
        }
Пример #9
0
        private void UploadPhotoToAzure(Stream file, Photo photo, int width, int height)
        {
            // create a resized image
            using (Image resized = ImageScaler.Crop(
                       Image.FromStream(file),
                       width, height, ImageScaler.AnchorPosition.Center))
            {
                using (MemoryStream upload = new MemoryStream())
                {
                    // encode and save that image to a memory stream
                    ImageCodecInfo[] info = ImageCodecInfo.GetImageEncoders();
                    var encoderParams     = new EncoderParameters(1);
                    encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
                    resized.Save(upload, info[1], encoderParams);

                    // reset the image
                    upload.Position = 0;
                }
            }
        }
Пример #10
0
        private static Texture MakeMipmap(Texture input, int levels, ImageScaler scaler)
        {
            var ret  = Texture.New2D(Context.GraphicsDevice, input.Width, input.Height, levels + 1, input.Format);
            var fact = 1;

            scaler.SetInput(input);
            for (var i = 0; i <= levels; ++i)
            {
                using (var target = Texture.New2D(Context.GraphicsDevice, input.Width / fact, input.Height / fact,
                                                  input.Format, TextureFlags.RenderTarget | TextureFlags.ShaderResource))
                {
                    scaler.SetOutput(target);
                    scaler.Draw(Context.RdwContext);
                    Context.RdwContext.CommandList.CopyRegion(
                        target, target.GetSubResourceIndex(0, 0), null,
                        ret, ret.GetSubResourceIndex(0, i), 0, 0);
                }

                fact *= 2;
            }

            return(ret);
        }
Пример #11
0
        Image addImage(int width, int height)
        {
            if (Image == null)
            {
                return(null);
            }
            Image img;

            try
            {
                img = ImageScaler.ScaleImage(width, height, Image);
            }
            catch (OutOfMemoryException)
            {
                return(null);
            }
            if (img == null)
            {
                return(null);
            }

            if (img == Image)
            {
                return(null);
            }

            ImageDesc desc = new ImageDesc();

            desc.Width  = width;
            desc.Height = height;
            desc.Image  = img;
            mImages.Add(desc);
            mImage.Dispose();
            mImage = null;
            return(img);
        }
Пример #12
0
        private void scaleImage()
        {
            try
            {
                this.statusStrip1.Visible = this.WindowState != FormWindowState.Maximized;

                if (pictureBox1.Width > 0)
                {
                    Dimension frame = new Dimension(pictureBox1.Width, pictureBox1.Height);

                    int desiredWidth = ImageScaler.getDesiredWidth(item.Dimensions, frame);

                    ImageScaler scaler = new ImageScaler(desiredWidth);

                    MemoryStream streamIn = new MemoryStream(item.Image);

                    MemoryStream streamOut = new MemoryStream();

                    scaler.scaleImage(streamIn, streamOut, ImageFormat.Bmp);

                    Image bitmap = Image.FromStream(streamOut);

                    pictureBox1.Image = bitmap;
                }
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e.Message);
            }
        }
Пример #13
0
 public void PrintFullBadge()
 {
     Image  logo       = Image.FromFile("Images\\Logo.jpg");
     Bitmap scaledLogo = ImageScaler.ResizeImage(logo, 60, 60);
     //BadgePrinterHelper.PrintBadge(1, "Comercializadora Las Margaritas", "PRODUCTOR DISTINGUIDO", "Avenida Patria 10. Ameca, Jalisco", "Manuel A. Quintero Sánchez", scaledLogo, 5, 9, true, true);
 }
 public void SetUp()
 {
     _imageScaler = DependencyResolver.Resolve <ImageScaler>();
 }