Solved

Control to bitmap

Posted on 2009-04-02
2
679 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

912 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now