Solved

Control to bitmap

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

706 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

16 Experts available now in Live!

Get 1:1 Help Now