国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

c# 通過現(xiàn)在文件夾,獲取下面所有的照片,并對(duì)其進(jìn)行統(tǒng)一尺寸裁剪

這篇具有很好參考價(jià)值的文章主要介紹了c# 通過現(xiàn)在文件夾,獲取下面所有的照片,并對(duì)其進(jìn)行統(tǒng)一尺寸裁剪。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

c# 通過現(xiàn)在文件夾,獲取下面所有的照片,并對(duì)其進(jìn)行統(tǒng)一尺寸裁剪
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reflection.Emit;

namespace _11_裁剪照片
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void button1_Click(object sender, EventArgs e)
    {
        ArrayList list = new ArrayList();
        string path = textBox1.Text;
        string path_bc = textBox2.Text;
        DirectoryInfo folder = new DirectoryInfo(path);
        FileSystemInfo fileinfo1 = folder as FileSystemInfo;
        list = selecte_jpg(fileinfo1);
        progressBar1.Maximum = list.Count;
        progressBar1.Minimum = 0;
        int i = 0;
        foreach (string path_jpg in list)
        {
            string pathname = path_bc +'\\' + System.IO.Path.GetFileName(path_jpg);
            cj_jpg(path_jpg, pathname);
            setPos(i);
            i++;
        }
        setPos(i);

    }

    private void cj_jpg(string path_y, string path_bc) 
    {
        Image originImage = Image.FromFile(path_y);
        //創(chuàng)建矩形對(duì)象表示原圖上裁剪的矩形區(qū)域,這里相當(dāng)于劃定原圖上坐標(biāo)為(10, 10)處,50x50大小的矩形區(qū)域?yàn)椴眉魠^(qū)域
        Rectangle cropRegion = new Rectangle(0, 0, 900, 768);
        //創(chuàng)建空白畫布,大小為裁剪區(qū)域大小
        Bitmap result = new Bitmap(cropRegion.Width, cropRegion.Height);
        //創(chuàng)建Graphics對(duì)象,并指定要在result(目標(biāo)圖片畫布)上繪制圖像
        Graphics graphics = Graphics.FromImage(result);
        //使用Graphics對(duì)象把原圖指定區(qū)域圖像裁剪下來并填充進(jìn)剛剛創(chuàng)建的空白畫布
        graphics.DrawImage(originImage, new Rectangle(0, 0, cropRegion.Width, cropRegion.Height), cropRegion, GraphicsUnit.Pixel);
        //這個(gè)時(shí)候裁剪區(qū)域圖片就被填充進(jìn)result對(duì)象中去了,可以對(duì)其進(jìn)行保存
        result.Save(path_bc, ImageFormat.Png);
    }

    private static ArrayList selecte_jpg(FileSystemInfo info)
    {

        DirectoryInfo dir = info as DirectoryInfo;
        ArrayList listPics = new ArrayList();
        FileSystemInfo[] files = dir.GetFileSystemInfos();
        for (int i = 0; i < files.Length; i++)
        {
            FileInfo file = files[i] as FileInfo;
            //是文件
            if (file != null)
            {
                string extension = Path.GetExtension(file.Name);
                if (extension.ToUpper() == ".PNG")
                    listPics.Add(file.FullName);
            }
            else//對(duì)于子目錄,進(jìn)行遞歸調(diào)用
                selecte_jpg(files[i]);
        }
        return listPics;
    }

    private void button2_Click(object sender, EventArgs e)
    {
        FolderBrowserDialog dialog = new FolderBrowserDialog();
        dialog.Description = "請(qǐng)選擇文件路徑";

        if (dialog.ShowDialog() == DialogResult.OK)
        {
            string savePath = dialog.SelectedPath;
            textBox1.Text = savePath;
        }
    }

    private void button3_Click(object sender, EventArgs e)
    {
        string Path = "";
        FolderBrowserDialog folder = new FolderBrowserDialog();
        folder.Description = "選擇文件所在文件夾目錄";  //提示的文字
        if (folder.ShowDialog() == DialogResult.OK)
        {
            Path = folder.SelectedPath;
            textBox2.Text = Path;
        }
    }

    private void progressBar1_Click(object sender, EventArgs e)
    {

    }
    private void setPos(int value) //設(shè)置進(jìn)度條當(dāng)前進(jìn)度值
    {
        if (value < progressBar1.Maximum + 1) //如果值有效
        {
            progressBar1.Value = value; //設(shè)置進(jìn)度值
        }
        Application.DoEvents();//重點(diǎn),必須加上,否則父子窗體都假死
    }
}

}文章來源地址http://www.zghlxwxcb.cn/news/detail-425908.html

到了這里,關(guān)于c# 通過現(xiàn)在文件夾,獲取下面所有的照片,并對(duì)其進(jìn)行統(tǒng)一尺寸裁剪的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包