Ejemplo n.º 1
0
        public List <Bitmap> ConvertPagedPdfToBitmaps(System.IO.Stream pdfStream)
        {
            string ghostscriptLibraryPath = "C:\\Program Files (x86)\\gs\\gs9.50\\bin\\";

            MagickNET.SetGhostscriptDirectory(ghostscriptLibraryPath);
            MagickNET.SetNativeLibraryDirectory(ghostscriptLibraryPath);
            MagickReadSettings settings = new MagickReadSettings()
            {
                Density = new Density(300, 300)
            };

            var bitmapImages = new List <System.Drawing.Bitmap>();

            using (MagickImageCollection images = new MagickImageCollection())
            {
                // Add all the pages of the pdf file to the collection
                images.Read(pdfStream, settings);                 //MagickImageCollection_ReadStream

                foreach (MagickImage image in images)
                {
                    bitmapImages.Add(image.ToBitmap());
                }
            }
            return(bitmapImages);
        }
Ejemplo n.º 2
0
        // ReSharper disable once UnusedMember.Global
        public static async Task <IActionResult> Function(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "RetrieveImage/{*image}")]
            HttpRequestMessage req,
            [Blob("{image}", FileAccess.Read, Connection = "ImageStorageAccount")]
            Stream s,
            ILogger log)
        {
            // var ms = new MemoryStream();
            // await s.CopyToAsync(ms);
            // ms.Seek(0, SeekOrigin.Begin);

            var magickNetNativeLibraryDirectory = Environment.GetEnvironmentVariable("MAGICK_NET_NATIVE", EnvironmentVariableTarget.Process);

            MagickNET.SetNativeLibraryDirectory(magickNetNativeLibraryDirectory);
            var defines = new JpegWriteDefines
            {
                Extent = 4 * 1024
            };

            var ms = new MemoryStream();

            using (var image = new MagickImage(s))
            {
                image.Settings.SetDefines(defines);
                image.Write(ms);
            }

            ms.Seek(0, SeekOrigin.Begin);

            return(new FileStreamResult(ms, "image/jpg"));
        }
Ejemplo n.º 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseStatusCodePages("text/plain", "{0}");
            }

            app.UseStaticFiles();

            app.UseRouting();

            app.UseResponseCaching();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            Directory.CreateDirectory(ImageGallery.Configuration.Get.TempDir);
            MagickNET.SetTempDirectory(ImageGallery.Configuration.Get.TempDir);
            MagickNET.SetNativeLibraryDirectory(ImageGallery.Configuration.Get.TempDir);
            FFmpeg.SetExecutablesPath(Path.Combine(env.ContentRootPath, "ffmpeg"));
        }