Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. combining 2 codes

combining 2 codes

Scheduled Pinned Locked Moved C#
graphicscsharp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    djsproject
    wrote on last edited by
    #1

    hello everybody i have one csharp .net code that selects multiple images.

    string[] extensions = new string[] {"jpg", "gif", "bmp", /*...*/};
    foreach (string extension in extensions)
    {
    FileInfo[] FileJpg = FileDirectory.GetFiles(string.Format("*.{0}", extension));
    foreach (FileInfo File in FileJpg)
    {
    ImageList.Add(File.Name, File.FullName);
    checkedListBox1.Items.Add(File.Name);
    }
    }

    and a second code that performs rotation on one image.

    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();
        }
    
    0 1 Reply Last reply
    0
    • D djsproject

      hello everybody i have one csharp .net code that selects multiple images.

      string[] extensions = new string[] {"jpg", "gif", "bmp", /*...*/};
      foreach (string extension in extensions)
      {
      FileInfo[] FileJpg = FileDirectory.GetFiles(string.Format("*.{0}", extension));
      foreach (FileInfo File in FileJpg)
      {
      ImageList.Add(File.Name, File.FullName);
      checkedListBox1.Items.Add(File.Name);
      }
      }

      and a second code that performs rotation on one image.

      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();
          }
      
      0 Offline
      0 Offline
      0x3c0
      wrote on last edited by
      #2

      First of all, you don't need such complex code for image rotation. There's a code snippet here[^] which will do the job just as well. Secondly, your problem is that you need to progress from filepath to image. Image.FromFile will fill your gap here, making the pseudocode something like this:

      for each extension in extensions
      {
      for each file found with extension
      {
      Image img = Image.FromFile(file);

          img = rotateImage(img);
          //continue work here
      }
      

      }

      OSDev :)

      D 1 Reply Last reply
      0
      • 0 0x3c0

        First of all, you don't need such complex code for image rotation. There's a code snippet here[^] which will do the job just as well. Secondly, your problem is that you need to progress from filepath to image. Image.FromFile will fill your gap here, making the pseudocode something like this:

        for each extension in extensions
        {
        for each file found with extension
        {
        Image img = Image.FromFile(file);

            img = rotateImage(img);
            //continue work here
        }
        

        }

        OSDev :)

        D Offline
        D Offline
        djsproject
        wrote on last edited by
        #3

        can someone elaborate more on this.............

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups