-3

My task is to resize multiple images. I tried this code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace Boyutlandir
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string dosyaYolu = string.Empty;
        Bitmap bmp = null;
        OpenFileDialog openFileDialogDosyaAc = new OpenFileDialog();

        private void button1_Click(object sender, EventArgs e)
        {

            openFileDialogDosyaAc.Multiselect = true;
            if (openFileDialogDosyaAc.ShowDialog() == DialogResult.OK)
            {
                dosyaYolu = openFileDialogDosyaAc.FileName;

                bmp = new Bitmap(openFileDialogDosyaAc.FileNames.ToString());

                pictureBox1.Image = bmp;

                pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Bitmap bmpKucuk = new Bitmap(pictureBox1.Image,Convert.ToInt32(textBox1.Text),Convert.ToInt32(textBox2.Text));
            pictureBox1.Image = bmpKucuk;
            pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;

        }

        private void button3_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "jpeg dosyası(*.jpg)|*.jpg|Bitmap(*.bmp)|*.bmp";
            DialogResult sonuc = sfd.ShowDialog();
            if (sonuc == DialogResult.OK)
            {
                pictureBox1.Image.Save(sfd.FileName);

            }
        }
    }
}
rajeemcariazo
  • 2,476
  • 5
  • 36
  • 62
UgurGul
  • 45
  • 7

1 Answers1

1

Ok, so you are using winforms and want to open multiple files? or a directory? and want to resize them. but there is nothing resized? or do I need more coffee? use http://nuget.org/packages/ImageResizer/ and I don't see a loop to loop over the files you want to resize.

Read more about the imageresizer component here: http://imageresizing.net/docs/managed

in your button1 click event, do something like this:

private void button1_Click(object sender, EventArgs e)
{
    DialogResult dr = this.openFileDialogDosyaAc.ShowDialog();
    if (dr == System.Windows.Forms.DialogResult.OK)
    {
        // Read the files
        foreach (String file in openFileDialogDosyaAc.FileNames) 
        {
            //resize and save
        }
    }
}
JP Hellemons
  • 5,977
  • 11
  • 63
  • 128