Solved

Control to bitmap

Posted on 2009-04-02
2
682 Views
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.ScaleTransform(1F,(float)factor);
                       
                        g.SmoothingMode = SmoothingMode.HighQuality;
                        g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                        g.CompositingQuality = CompositingQuality.HighQuality;
                        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
 
 bmp.Save(path + "myBitmap.Bmp", ImageFormat.Bmp);
                        g.Dispose();

Open in new window

0
Comment
Question by:p_davis
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 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));
            g.Dispose();
            scaledBMP.Save(path + "myBitmap.Bmp", ImageFormat.Bmp);

Open in new window

0
 
LVL 22

Author Comment

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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