combining 2 codes
-
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(); }
-
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(); }
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 :)
-
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 :)
can someone elaborate more on this.............