Click here to Skip to main content
15,914,488 members
Home / Discussions / C#
   

C#

 
GeneralRe: find week num of first week in year Pin
Maddie from Dartford7-Jan-10 6:03
Maddie from Dartford7-Jan-10 6:03 
JokeRe: find week num of first week in year Pin
dojohansen8-Jan-10 1:27
dojohansen8-Jan-10 1:27 
GeneralRe: find week num of first week in year Pin
Richard MacCutchan8-Jan-10 4:29
mveRichard MacCutchan8-Jan-10 4:29 
QuestionDataGridView, DataSource and RowCount related query Pin
dan!sh 7-Jan-10 4:09
professional dan!sh 7-Jan-10 4:09 
AnswerRe: DataGridView, DataSource and RowCount related query Pin
Ben Fair7-Jan-10 4:52
Ben Fair7-Jan-10 4:52 
GeneralRe: DataGridView, DataSource and RowCount related query Pin
dan!sh 7-Jan-10 4:56
professional dan!sh 7-Jan-10 4:56 
QuestionCreate object explorer,query analyser and registered services windows Pin
tasumisra7-Jan-10 3:43
tasumisra7-Jan-10 3:43 
QuestionC# DataTable Pin
jojoba20107-Jan-10 3:18
jojoba20107-Jan-10 3:18 
AnswerRe: C# DataTable Pin
mrcooll7-Jan-10 4:50
mrcooll7-Jan-10 4:50 
AnswerRe: C# DataTable Pin
loyal ginger7-Jan-10 4:52
loyal ginger7-Jan-10 4:52 
GeneralRe: C# DataTable Pin
OriginalGriff7-Jan-10 5:23
mveOriginalGriff7-Jan-10 5:23 
AnswerRe: C# DataTable Pin
OriginalGriff7-Jan-10 5:19
mveOriginalGriff7-Jan-10 5:19 
QuestionCsharp .Net doubt [modified] Pin
djsproject7-Jan-10 2:59
djsproject7-Jan-10 2:59 
AnswerRe: Csharp .Net doubt Pin
Ben Fair7-Jan-10 3:03
Ben Fair7-Jan-10 3:03 
GeneralRe: Csharp .Net doubt Pin
djsproject7-Jan-10 3:08
djsproject7-Jan-10 3:08 
GeneralRe: Csharp .Net doubt Pin
#realJSOP7-Jan-10 3:17
professional#realJSOP7-Jan-10 3:17 
GeneralRe: Csharp .Net doubt Pin
dojohansen7-Jan-10 3:08
dojohansen7-Jan-10 3:08 
AnswerRe: Csharp .Net doubt Pin
dojohansen7-Jan-10 3:12
dojohansen7-Jan-10 3:12 
GeneralRe: Csharp .Net doubt Pin
djsproject7-Jan-10 3:18
djsproject7-Jan-10 3:18 
GeneralRe: Csharp .Net doubt Pin
dojohansen7-Jan-10 3:39
dojohansen7-Jan-10 3:39 
General[Message Deleted] Pin
djsproject7-Jan-10 3:26
djsproject7-Jan-10 3:26 
GeneralRe: Csharp .Net doubt Pin
djsproject7-Jan-10 3:37
djsproject7-Jan-10 3:37 
AnswerRe: Csharp .Net doubt Pin
Luc Pattyn7-Jan-10 3:39
sitebuilderLuc Pattyn7-Jan-10 3:39 
AnswerRe: Csharp .Net doubt Pin
Lutosław7-Jan-10 12:28
Lutosław7-Jan-10 12:28 
GeneralRe: Csharp .Net doubt Pin
djsproject12-Jan-10 17:28
djsproject12-Jan-10 17:28 
hey i want this code of rotating image with all the images that i have selected can somebody tell me how to get it done?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;

namespace ImageRotation
{
    public partial class Form1 : Form
    {
        private Image loadedImage;

        public Form1()
        {
            InitializeComponent();
        }

        private Image RotateImage(Image inputImg, double degreeAngle)
        {
            //Corners of the image
            PointF[] rotationPoints = { new PointF(0, 0),
                                        new PointF(inputImg.Width, 0),
                                        new PointF(0, inputImg.Height),
                                        new PointF(inputImg.Width, inputImg.Height)};

            //Rotate the corners
            PointMath.RotatePoints(rotationPoints, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f), degreeAngle);

            //Get the new bounds given from the rotation of the corners
            //(avoid clipping of the image)
            Rectangle bounds = PointMath.GetBounds(rotationPoints);

            //An empy bitmap to draw the rotated image
            Bitmap rotatedBitmap = new Bitmap(bounds.Width, bounds.Height);

            using (Graphics g = Graphics.FromImage(rotatedBitmap))
            {
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                //Transformation matrix
                Matrix m = new Matrix();
                m.RotateAt((float)degreeAngle, new PointF(inputImg.Width / 2.0f, inputImg.Height / 2.0f));
                m.Translate(-bounds.Left, -bounds.Top, MatrixOrder.Append); //shift to compensate for the rotation

                g.Transform = m;
                g.DrawImage(inputImg, 0, 0);
            }
            return (Image)rotatedBitmap;
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            if (loadedImage != null)
                pictureBox1.Image = RotateImage(loadedImage, (double)tRotation.Value);
            pictureBox1.Refresh();
        }

        private void btnLoad_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    loadedImage = Image.FromFile(openFileDialog1.FileName);
                    pictureBox1.Image = loadedImage;

                    //Reset rotation value
                    tRotation.Value = 0;
                }
                catch (Exception)
                {
                    MessageBox.Show("Image invalid.");
                }
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("http://www.vcskicks.com/");
        }
    }

    public static class PointMath
    {
        private static double DegreeToRadian(double angle)
        {
            return Math.PI * angle / 180.0;
        }

        public static PointF RotatePoint(PointF pnt, double degreeAngle)
        {
            return RotatePoint(pnt, new PointF(0, 0), degreeAngle);
        }

        public static PointF RotatePoint(PointF pnt, PointF origin, double degreeAngle)
        {
            double radAngle = DegreeToRadian(degreeAngle);

            PointF newPoint = new PointF();

            double deltaX = pnt.X - origin.X;
            double deltaY = pnt.Y - origin.Y;

            newPoint.X = (float)(origin.X + (Math.Cos(radAngle) * deltaX - Math.Sin(radAngle) * deltaY));
            newPoint.Y = (float)(origin.Y + (Math.Sin(radAngle) * deltaX + Math.Cos(radAngle) * deltaY));

            return newPoint;
        }

        public static void RotatePoints(PointF[] pnts, double degreeAngle)
        {
            for (int i = 0; i < pnts.Length; i++)
            {
                pnts[i] = RotatePoint(pnts[i], degreeAngle);
            }
        }

        public static void RotatePoints(PointF[] pnts, PointF origin, double degreeAngle)
        {
            for (int i = 0; i < pnts.Length; i++)
            {
                pnts[i] = RotatePoint(pnts[i], origin, degreeAngle);
            }
        }

        public static Rectangle GetBounds(PointF[] pnts)
        {
            RectangleF boundsF = GetBoundsF(pnts);
            return new Rectangle((int)Math.Round(boundsF.Left),
                                 (int)Math.Round(boundsF.Top),
                                 (int)Math.Round(boundsF.Width),
                                 (int)Math.Round(boundsF.Height));
        }

        public static RectangleF GetBoundsF(PointF[] pnts)
        {
            float left = pnts[0].X;
            float right = pnts[0].X;
            float top = pnts[0].Y;
            float bottom = pnts[0].Y;

            for (int i = 1; i < pnts.Length; i++)
            {
                if (pnts[i].X < left)
                    left = pnts[i].X;
                else if (pnts[i].X > right)
                    right = pnts[i].X;

                if (pnts[i].Y < top)
                    top = pnts[i].Y;
                else if (pnts[i].Y > bottom)
                    bottom = pnts[i].Y;
            }

            return new RectangleF(left,
                                  top,
                                 (float)Math.Abs(right - left),
                                 (float)Math.Abs(bottom - top));
        }
    }
}

this code works for only one image.I want it to run for multiple images.In other words i want it to integrate with the above code.can somebody help..............

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.