using Microsoft.Win32;
using System;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Media.Imaging; namespace Clip
{
class Clip
{
[STAThread]
static void Main(string[] args)
{
var openFileDialog = new OpenFileDialog()
{
Filter = "所有图片文件|*.bmp;*.dib;*.jpg;*.jpeg;*.jpe;*.jfif;*.png|位图文件|*.bmp;*.dib|JPEG|*.jpg;*.jpeg;*.jpe;*.jfif|PNG|*.png"
};
while (openFileDialog.ShowDialog() != true) ;
var bitmapImage = new BitmapImage(new Uri(openFileDialog.FileName));
Console.WriteLine("Left Margin: ");
Console.WriteLine("Top Margin: ");
Console.WriteLine("Right Margin: ");
Console.WriteLine("Bottom Margin: ");
Console.CursorTop = ;
Console.CursorLeft = ;
int leftMargin = int.Parse(Console.ReadLine());
Console.CursorLeft = ;
int topMargin = int.Parse(Console.ReadLine());
Console.CursorLeft = ;
int rightMargin = int.Parse(Console.ReadLine());
Console.CursorLeft = ;
int bottomMargin = int.Parse(Console.ReadLine());
int width = bitmapImage.PixelWidth - leftMargin - rightMargin;
int height = bitmapImage.PixelHeight - topMargin - bottomMargin;
var writeableBitmap = new WriteableBitmap(width, height, bitmapImage.DpiX, bitmapImage.DpiY, bitmapImage.Format, bitmapImage.Palette);
IntPtr backBuffer = writeableBitmap.BackBuffer;
bitmapImage.CopyPixels(new Int32Rect(leftMargin, topMargin, width, height), backBuffer, height * writeableBitmap.BackBufferStride, writeableBitmap.BackBufferStride);
var saveFileDialog = new SaveFileDialog()
{
Filter = "所有图片文件|*.bmp;*.dib;*.jpg;*.jpeg;*.jpe;*.jfif;*.png|位图文件|*.bmp;*.dib|JPEG|*.jpg;*.jpeg;*.jpe;*.jfif|PNG|*.png"
};
while (saveFileDialog.ShowDialog() != true) ;
BitmapEncoder bitmapEncoder = null;
if (Regex.IsMatch(saveFileDialog.SafeFileName, @"^.+\.(?:bmp|dib)$"))
{
bitmapEncoder = new BmpBitmapEncoder();
}
else if (Regex.IsMatch(saveFileDialog.SafeFileName, @"^.+\.(?:jpg|jpeg|jpe|jfif)$"))
{
bitmapEncoder = new JpegBitmapEncoder();
}
else if (Regex.IsMatch(saveFileDialog.SafeFileName, @"^.+\.(?:png)$"))
{
bitmapEncoder = new PngBitmapEncoder();
}
bitmapEncoder.Frames.Add(BitmapFrame.Create(writeableBitmap));
var fileStream = new FileStream(saveFileDialog.FileName, FileMode.Create);
bitmapEncoder.Save(fileStream);
}
}
}

A Tool to Clip Images的更多相关文章

  1. 基于2d Tool Kit 精灵合图,动作生成工具

    http://blog.csdn.net/onerain88/article/details/18563687 2d Tool Kit 是一款出色的基于unity3d 开发2d游戏的工具,提供了丰富的 ...

  2. How to Write Doc Comments for the Javadoc Tool

    http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html This document describe ...

  3. How to installation V145 Renault CAN Clip diagnostic software

    Eobd2.fr has launched the new 2015 V145 Renault CAN Clip diagnostic tool (SP19-A and SP19-B). Here i ...

  4. [CSS] Useful CSS tool for Web designer and developer

    1. Color Picker (Chrome) You might know how to use color picker in Chrome, recently there is a featu ...

  5. Split Animation Clip From FBX and Multiply Mode Sprite

    Use Script To Creat 2D Animation Clip From Multiply Mode Sprite 很多时候美工拿过来的一张序列帧图片,我们需要转换成 Multiply M ...

  6. [免费了] SailingEase .NET Resources Tool (.NET 多语言资源编辑器)

    这是我2010年左右,写 Winform IDE (http://www.cnblogs.com/sheng_chao/p/4387249.html)项目时延伸出的一个小项目. 最初是以共享软件的形式 ...

  7. [Tool] github 入手教程

    简单的介绍一下 Github 的基本操作. 主页:https://github.com/ 首先自然是在 GitHub 注册一个帐号了.然后开始正文吧. Git 基本介绍 Git 是属于分布式版本控制系 ...

  8. jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the install tool.

    jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the ...

  9. mtk flash tool,Win7 On VirtualBox

    SP_Flash_Tool_exe_Windows_v5.1624.00.000 Win7 在 VirtualBox, 安裝 mtk flash tool, v5.1628 在燒錄時會 fail. v ...

随机推荐

  1. linux 下 php 安装 libevent

    一.安装libevent库 1.到libevent官网下载安装源码 http://libevent.org/ 如:libevent-2.0.22-stable.tar.gz 2.解压源码包 > ...

  2. Algorithmic Trading[z]

    Algorithmic Trading has been a hot topic for equity/derivative trading over a decade. Many ibanks an ...

  3. Js中的this关键字(吉木自学)

    研究生毕业答辩完,开始继续为转行努力.小白要奋斗了,加油.本文引自JS核心系列:浅谈函数的作用域. 在一个函数中,this总是指向当前函数的所有者对象,this总是在运行时才能确定其具体的指向, 也才 ...

  4. 数据库链接 mybatis spring data jpa 两种方式

    jdbc mybatis                     spring data jpa dao service webservice jaxrs     jaxws  springmvc w ...

  5. 关闭文件描述符-close

    头文件:#include<unistd.h> 原型:int close(int fd); 返回值:成功返回0,失败返回-1.

  6. mac安全与隐私只有两个选项,少了一个任何来源

    很多软件安装后就会出现,程序已损坏,请移到废纸篓的提示. 解决方法:在终端里输入:sudo spctl --master-disable 然后回车,然后输入密码,即可在安全选项中看到重新出现的允许任何 ...

  7. 2018.09.27 codeforces618F. Double Knapsack(抽屉原理+构造)

    传送门 思维题. 考虑维护两个数列的前缀和a1,a2,a3,...,ana_1,a_2,a_3,...,a_na1​,a2​,a3​,...,an​和b1,b2,b3,...,bnb_1,b_2,b_ ...

  8. 2018.08.22 hyc的xor/mex(线段树/01trie)

    hyc的xor/mex 描述 NOIP2017就要来了,备战太累,不如做做hyc的新题? 找回自信吧! 一句话题意:n个数,m个操作 操作具体来讲分两步 1.读入x,把n个数全部xor上x 2.询问当 ...

  9. 2018.07.31 bzoj4569: [Scoi2016]萌萌哒(并查集+倍增)

    传送门 对于每个限制,使用倍增的二进制拆分思想,用并查集数组fa[i][j]" role="presentation" style="position: rel ...

  10. 图形与游戏中3D数学基础的说明

    1.左手坐标系与右手坐标系没有好坏之分,不同的研究领域和不同的背景下,选择不同的坐标系:传统计算机图形学采用“左手坐标系”,线性代数则倾向于使用右手坐标系 坐标系由坐标轴与坐标原点组成.原点定义坐标系 ...