Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

OverFlowException in Graphics.DrawImage using InterpolationMode HighQualityBicubic

$
0
0

Dear Reader,

I have an service that imports image files into a DMS system and while doing that it checks if the images are large (>A4). If so it produces A4 sized images keeping the aspect ratio. Now I got a few images that can not be scaled even on a 64Bit machine with lots of RAM.

I could nail it down to the used scaling algorithm: if HighQualityBicubic or HighQualityBilinear are used an OverflowException is thrown. If I use a worse alogithm like Bicubic it works.

Since the images are sometimes very large (>500MPixel, 400DPI) I used to use HighQualityBicubic all the time. Now i got four images that seem to be around the same size but are failing with an Exception on DrawImage. One of the images has 40869x13188 Pixels and should get shrinked to 4676x1508.

This is basically the code (hardcoded values are calculated in real program):

                using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(@"somepath\somename.tif")))
                {
                    using (System.Drawing.Image image = System.Drawing.Image.FromStream(ms))
                    {
                        System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(4676, 1508);
                        bmp.SetResolution(400, 400);

                        using (Graphics g = Graphics.FromImage(bmp))
                        {
                            g.InterpolationMode = InterpolationMode.HighQualityBicubic; // GetQualitySetting(scaleFactor);
                            g.SmoothingMode = SmoothingMode.HighQuality;
                            g.CompositingQuality = CompositingQuality.HighQuality;
                            g.PixelOffsetMode = PixelOffsetMode.HighQuality;

                            g.DrawImage(image, 0, 0, 4676, 1508);
                            g.Flush();
                        }
                    }
                }

My Question: are there limits for HighQualityBicubic scaling? Any other restrictions like width/height has to be n^4 or something like that.

I am grateful for any hint to an solution or a workaround.

Edit:
[System.OverflowException] = {"Überlauffehler."}
Stacktrace
   bei System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   bei System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
   bei ConsoleApplication2.Program.Main(String[] args) in d:\SRC.NET\TestApps\ConsoleApplication2\ConsoleApplication2\Program.cs:Zeile 32.


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>