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. maven的下载

    1.maven的下载地址:http://maven.apache.org/download.cgi.下载3.3.9版本(在选择下载的版本是要与JDK契合). 2.下载之后,解压的文件放的位置尽量不要有 ...

  2. linux 操作笔记

    1.设置防火墙,允许用户使用http访问本机 [root@localhost geoserver]# systemctl enable httpdCreated symlink from /etc/s ...

  3. Luogu 3960 [NOIP2017] 列队 - splay|线段树

    题解 是我从来没有做过的裂点splay... 看的时候还是很懵逼的QAQ. 把最后一列的$n$个数放在一个平衡树中, 有 $n$ 个点 剩下的$n$行数, 每行都开一个平衡树,开始时每棵树中仅有$1$ ...

  4. UI设计必用工具 — AI快捷键大全

    01 常用工具 V 选择工具 A 直接选择工具 Y 魔棒工具 Q 套索工具 P 钢笔工具 Z 缩放工具 R 旋转工具 O 镜像工具 M 矩形工具 L 椭圆工具 B 画笔工具 N 铅笔工具 C 剪刀工具 ...

  5. laravel数据库操作

    一.配置文件路径:/.env DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT= DB_DATABASE=test DB_USERNAME=root DB_P ...

  6. Mockplus教程:分分钟搞定APP首页原型设计

    Mockplus是一款快速原型设计工具,支持包括APP原型在内的多种原型与线框图设计.除了快速,Mockplus广受欢迎更因为它极低的上手门槛.今天小编就为大家展示如何用Mockplus在3分钟内完成 ...

  7. android 混淆文件proguard.cfg详解 (转载)

    -injars  androidtest.jar[jar包所在地址] -outjars  out[输出地址] -libraryjars    'D:\android-sdk-windows\platf ...

  8. 【DBCP】DBCP基本配置和重连配置+spring中配置

    最近在看一些dbcp的相关内容,顺便做一下记录,免得自己给忘记了.   1. 引入dbcp (选择1.4) <dependency> <groupId>com.alibaba. ...

  9. 【JDBC&Dbutils】JDBC&JDBC连接池&DBUtils使用方法(重要)

    -----------------------JDBC---------- 0.      db.properties文件 driver=com.mysql.jdbc.Driver url=jdbc: ...

  10. python数据类型2

    一 文件格式补充 在python3中,除字符串外,所有数据类型在内存中的编码格式都是utf-8,而字符串在内存中的格式是Unicode的格式. 由于Unicode的格式无法存入硬盘中,所以这里还有一种 ...