A Tool to Clip Images
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的更多相关文章
- 基于2d Tool Kit 精灵合图,动作生成工具
http://blog.csdn.net/onerain88/article/details/18563687 2d Tool Kit 是一款出色的基于unity3d 开发2d游戏的工具,提供了丰富的 ...
- How to Write Doc Comments for the Javadoc Tool
http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html This document describe ...
- 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 ...
- [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 ...
- Split Animation Clip From FBX and Multiply Mode Sprite
Use Script To Creat 2D Animation Clip From Multiply Mode Sprite 很多时候美工拿过来的一张序列帧图片,我们需要转换成 Multiply M ...
- [免费了] SailingEase .NET Resources Tool (.NET 多语言资源编辑器)
这是我2010年左右,写 Winform IDE (http://www.cnblogs.com/sheng_chao/p/4387249.html)项目时延伸出的一个小项目. 最初是以共享软件的形式 ...
- [Tool] github 入手教程
简单的介绍一下 Github 的基本操作. 主页:https://github.com/ 首先自然是在 GitHub 注册一个帐号了.然后开始正文吧. Git 基本介绍 Git 是属于分布式版本控制系 ...
- 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 ...
- mtk flash tool,Win7 On VirtualBox
SP_Flash_Tool_exe_Windows_v5.1624.00.000 Win7 在 VirtualBox, 安裝 mtk flash tool, v5.1628 在燒錄時會 fail. v ...
随机推荐
- php的反射
我们可以在PHP运行时,通过PHP的反射动态的获取类的方法.属性.参数等详细信息. 用途:插件的设计,文档的自动生成,扩充PHP语言. <?php class Person { const ...
- Spring框架的事务管理之基于AspectJ的注解方式(重点掌握,最简单的方式)
1. 步骤一:恢复转账的开发环境(具体开发环境实现见:https://www.cnblogs.com/wyhluckdog/p/10137283.html)2. 步骤二:applicationCont ...
- js 判断字符串是否包含某字符串,String对象中查找子字符,indexOf
var Cts = "bblText"; if(Cts.indexOf("Text") > 0 ) { alert('Cts中包含Text字符 ...
- go实现的简易TCP的客户端和服务器
今天介绍golang版本的通信基础:基于TCP的客户端和服务器实现,参考书籍:The Way To Go 那时学习java的时候也是做过通信的,当时是socket编程,服务器监听某一个端口,然后客户机 ...
- EXPAT(XML解析库)
一.简介 expat是一个由C语言编写的XML解析库.James Clark创建了这个库,现在是制定XML标准的W3组织的技术leader.现在的版本是2.0.2.0开始就由Clark Cooper领 ...
- Luogu 1070 道路游戏
看完题面想了一会发现只会写$n^3$,愣了一会才想出了单调队列优化的做法. 90分算法: 设$f_{i, j, k}$表示第$i$分钟在第$j$座城市已经走了$k$步的最大价值,转移显然,时间复杂度$ ...
- dateframe_loc.iloc.ix
import pandas as pddf=pd.DataFrame({ "a":[1,2,3], "b":[4,5,6], "c":[7, ...
- mysql 1045 access denied for user********
另一个方法Windows: 1. 管理员登陆系统,停止mysql服务或者结束mysqld-nt进程2. 进入命令行,来到mysql的安装目录.假设安装目录为 d:/mysql/ , CMD进入命令行3 ...
- Oracle SQL 硬解析和子游标
Oracle SQL 硬解析和子游标 What reasons will be happening sql hard parse and generating new child cursors 在一 ...
- ST3 插件和技巧
Emmet插件: 快速生成HTML文档结构, 快速编写跨浏览器的CSS并自动帮助你同时编辑, 强大! 语法技巧 简单实用, 值得掌握! SideBar Enhancements插件: 改进了侧边栏, ...