裁剪图像(从屏幕)

时间:2017-06-23 22:33:27

标签: c# image crop system.drawing

我已经阅读了很多关于此的问题。但我的问题有点不同。我需要做什么从屏幕裁剪图像。

有我的代码

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="test">
  <div ng-controller="TestController as test">
    {{ test.title }}
    <input type="checkbox" name="chk" ng-model="test.value" ng-value="true" />
    <button ng-click="test.toggle('sm',$event)">Toggle</button>
  </div>
</div>

还有我的裁剪代码

Bitmap photo = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.primaryScreen.Bounds.Height)
Graphics gr = Graphics.FromImage(photo);
gr.CopyFromScreen(0,0,0,0 new size(foto.Width,foto.Height));
picturebox1.Image = photo;

我想裁剪这张照片的中间部分并与自己进行比较。  谢谢你提前

1 个答案:

答案 0 :(得分:0)

要按照以下sketch所示对称地裁剪图像,请尝试创建一个在X和Y轴上具有边距的位图,然后通过在CopyFromScreen()中使用这些边距来裁剪屏幕快照图像:

Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width - 2 * xmargin, Screen.PrimaryScreen.Bounds.Height - 2 * ymargin);
Graphics graphics = Graphics.FromImage(printscreen as Image);
graphics.CopyFromScreen(xmargin, ymargin, 0, 0, printscreen.Size);