Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear friends,
I am using windows Application using C#, i have one doubt let i explain,

Explain :
I have one panel and one button control in windows application, When i click the Button I added the image of run time (Without using picture box control) of the panel, I need to select that image runtime when i click the mouse of that image, and that same time it able to re size (like Transform) that image eight right,left,top,bottom, side-left, side-right.

Please give me the Ideas how i do that. I try that last 20 days, still i didn't achieve.
Posted
Comments
OriginalGriff 25-Jun-12 7:57am    
What did you try?
If you are using the Panel Paint event it's pretty simple - the Graphics.DrawImage method has many, many overloads for doing just that...
vasanthkumarmk 26-Jun-12 8:03am    
if (openFileDlgImg.ShowDialog(this) == DialogResult.OK)
{
try
{
m_objMLCharGen.AddNewItem(openFileDlgImg.FileName, 36, 29, 0, 0, ref strItemID); //Using My SDK to add the image
}
catch (Exception) { }

// UpdateList();
}

Dear Friends,
My project we are using one SDK, using that SDK i added the image, But i am very sure it won't add the picturebox format. i need that will re size while runtime.
Sandeep Mewara 25-Jun-12 9:01am    
Ok, so do share with us what you did in last 20 days.
Sergey Alexandrovich Kryukov 25-Jun-12 17:52pm    
... :-) !!!
Vani Kulkarni 26-Jun-12 2:06am    
Exactly!

1 solution

an Example to resize a picture;

C#
public  static Image resizeImage(Image imgToResize, Size size)
        {
            int sourceWidth = imgToResize.Width;
            int sourceHeight = imgToResize.Height;

            float nPercent = 0;
            float nPercentW = 0;
            float nPercentH = 0;

            nPercentW = ((float)size.Width / (float)sourceWidth);
            nPercentH = ((float)size.Height / (float)sourceHeight);

            if (nPercentH < nPercentW)
                nPercent = nPercentH;
            else
                nPercent = nPercentW;

            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);

            Bitmap b = new Bitmap(destWidth, destHeight);
            Graphics g = Graphics.FromImage((Image)b);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
            g.Dispose();

            return (Image)b;
        }
 
Share this answer
 
Comments
vasanthkumarmk 27-Jun-12 7:28am    
I want to move while runtime using mouse.......
Herman<T>.Instance 27-Jun-12 8:42am    
use the mouse click event for that. In that event you can you the above method
vasanthkumarmk 27-Jun-12 8:52am    
how i will takes the width & height size using mouse over
Herman<T>.Instance 27-Jun-12 9:53am    
shouldn't that be in the properties of the image object!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900