[Webinar] Streamline your web hosting managementRegister Today


Control to bitmap

Posted on 2009-04-02
Medium Priority
Last Modified: 2013-12-17
i have a control that i am drawing to a bitmap. The problem that i am having is scaling the bitmap to a certain size. No matter what i have tried, after the control is drawn to the bitmap i cannot scale it down. When i view the bitmap in paint or window picture/fax viewer it isn't scaled, it is the original control drawn to bitmap size.

the factor variable is about .75 and is calculated in another method.

i have also tried the Graphics.DrawImage with the destination rectangle equally what it would be if the .75 scaling was applied in the scaletransform.  the drawimage does scale it down but it draws over the original control.drawtobitmap so i have both and the bitmap is still the same height.
Control s = (Control)control;
Bitmap bmp = new Bitmap((Image)new Bitmap(1, 1), control.Size);
s.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
Graphics g = Graphics.FromImage(bmp);
                        g.SmoothingMode = SmoothingMode.HighQuality;
                        g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                        g.CompositingQuality = CompositingQuality.HighQuality;
                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
 bmp.Save(path + "myBitmap.Bmp", ImageFormat.Bmp);

Open in new window

Question by:p_davis
LVL 86

Accepted Solution

Mike Tomlinson earned 2000 total points
ID: 24050994
Try this please:
            Control s = (Control)control;
            Bitmap unscaledBMP = new Bitmap(control.Size.Width, control.Size.Height);
            s.DrawToBitmap(unscaledBMP, new Rectangle(0, 0, unscaledBMP.Width, unscaledBMP.Height));
            Bitmap scaledBMP = new Bitmap((int)((double)unscaledBMP.Width * factor), (int)((double)unscaledBMP.Height * factor));
            Graphics g = Graphics.FromImage(scaledBMP);
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.DrawImage(unscaledBMP, new Rectangle(0, 0, scaledBMP.Width, scaledBMP.Height));
            scaledBMP.Save(path + "myBitmap.Bmp", ImageFormat.Bmp);

Open in new window

LVL 22

Author Comment

ID: 24051168
awesome, that is something i can work with -- thanks  Idle Mind

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses
Course of the Month7 days, 20 hours left to enroll

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question