uwp 图片剪切
public async void BitmapTransformAndSaveTest()
{
var uncroppedfile = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("uncropped.jpg");
if (uncroppedfile == null)
{
return;
} WriteableBitmap wb = null; // create a stream from the file and decode the image
var fileStream = await uncroppedfile.OpenAsync(Windows.Storage.FileAccessMode.Read);
var decoder = await BitmapDecoder.CreateAsync(fileStream); // create a new stream and encoder for the new image
using (InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream())
{
var enc = await BitmapEncoder.CreateForTranscodingAsync(ras, decoder); // convert the entire bitmap to a 100px by 100px bitmap
enc.BitmapTransform.ScaledHeight = 100;
enc.BitmapTransform.ScaledWidth = 100; var bounds = new BitmapBounds();
bounds.Height = 50;
bounds.Width = 50;
bounds.X = 50;
bounds.Y = 50;
enc.BitmapTransform.Bounds = bounds; // write out to the stream
await enc.FlushAsync(); // create a writeable bitmap from the stream
ras.Seek(0);
wb = new WriteableBitmap(100, 100);
wb.SetSource(ras);
} // save the cropped file now
var croppedfile = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("cropped.jpg", Windows.Storage.CreationCollisionOption.ReplaceExisting);
using (var stream = await croppedfile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
{
var pixelStream = wb.PixelBuffer.AsStream();
var bytes = new byte[pixelStream.Length];
pixelStream.Seek(0, SeekOrigin.Begin);
await pixelStream.ReadAsync(bytes, 0, (int)pixelStream.Length);
await pixelStream.FlushAsync(); var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, (uint)wb.PixelWidth, (uint)wb.PixelHeight, 0, 0, bytes);
await encoder.FlushAsync();
await stream.FlushAsync();
}
}
uwp 图片剪切的更多相关文章
- UWP 图片剪切旋转工具
好久没撸随笔了,明天终于放假休息了..准备去进行信仰充值,看<魔兽>去(话说surface phone 好久出,让我这个做UWP的也充点信仰..) 先上下效果图: 在设计中,遇到一个问题, ...
- iOS开发UI篇—Quartz2D使用(图片剪切)
iOS开发UI篇—Quartz2D使用(图片剪切) 一.使用Quartz2D完成图片剪切 1.把图片显示在自定义的view中 先把图片绘制到view上.按照原始大小,把图片绘制到一个点上. 代码: - ...
- 【iOS】Quartz2D图片剪切
一.使用Quartz2D完成图片剪切1.把图片显示在自定义的view中 先把图片绘制到view上.按照原始大小,把图片绘制到一个点上. 代码: - (void)drawRect:(CGRect)rec ...
- 图片上传,图片剪切jquery.imgareaselect
---恢复内容开始--- <%@ page language="java" contentType="text/html; charset=UTF-8" ...
- android——拍照,相册图片剪切其实就这么简单
接触android这么久了.还没有真正的浩浩看看android拍照,相册图片剪切到底是怎么回事,每次都是从别人的代码一扣,就过来了.其实,谷歌提供的API已经很强大.只需要用的好,就那么几句就可以搞定 ...
- 图片剪切之Croppic插件
前几天做图片上传时需要进行图片的剪切和缩放,上网查找时找到了这个插件.样式很好看,功能也很OK.但是网上都是php进行后台处理图片的例子,然后只好慢慢琢磨C#的处理.插件地址是:http://www. ...
- 用JavaScript实现图片剪切效果
学会如何获取鼠标的坐标位置以及监听鼠标的按下.拖动.松开等动作事件,从而实现拖动鼠标来改变图片大小. 还可以学习css中的clip属性. 一.CSS实现图片不透明及裁剪效果. 图片剪切三层结构 1.第 ...
- php imagemagick 处理 图片剪切、压缩、合并、插入文本、背景色透明
php有一款插件叫做imagemagick,功能很强大,提供了图片的很多操作,图片剪切.压缩.合并.插入文本.背景色透明等.并且有api方法调用和命令行操作两种方式,如果只是简单处理的话建议api方法 ...
- opencv 图片剪切
import cv2 as cv import numpy as np # 图片剪切 img = cv.imread('../images/moon.jpg', flags=1) # flags=1读 ...
- android 7.0以上共享文件(解决调用系统照相和图片剪切出现的FileUriExposedException崩溃问题)
在android7.0开始试共享“file://”URI 将会导致引发 FileUriExposedException. 如果应用需要与其他应用共享私有文件,则应该使用 FileProvider, F ...
随机推荐
- 无套路领取《AI应用开发专栏》
最近有些时间没有更新技术文章了,都在忙着写<AI应用开发入门>专栏,专栏已整理放到了github上,有兴趣的小伙伴可以移步github阅读,地址见文末. 1.为什么写这个文档 之前陆续写了 ...
- 从0.1开始学java(2)
string串池 现在都在堆中 "=="号的比较 字符串比较一般调用equals或者equalsignoreCase API来比较(后者忽略大小写) StringBuilder 可 ...
- Java,启动!
即日起,Java启动!目标是年后找到大厂Java日常实习,特立此随笔作证. 学习路线: Java基础(Java基础用不了多少时间,因为之前有学习过,大概花费1~2周,做到理解案例代码,看懂知识点原理即 ...
- Dash 2.18.2版本更新:模式匹配回调性能大提升
本文示例代码已上传至我的Github仓库:https://github.com/CNFeffery/dash-master Gitee同步仓库地址:https://gitee.com/cnfeffer ...
- 从编译链接到cmake
.c(.cpp)文件到可执行文件 对于一份简单的.c/.cpp为后缀的源文件,他所使用的语言是人类可以阅读并看懂的,但是对于计算机来说,其可理解并执行的是二进制的机器码. 也就是说,计算机所能运行的是 ...
- Lattice ICE40LP8K开发
一.开发工具: ICEcube2,界面非常原始,只有PLL IP核添加功能,其他IP核貌似只能使用primitive替换. 不支持时序分析.在线仿真等功能. 二.原语使用 全局布线资源 在 iCE40 ...
- 解决MindSpore-2.4-GPU版本的安装问题
问题背景 虽说在MindSpore-2.3之后的版本中不在正式的发行版中支持GPU硬件后端,但其实在开发分支版本中对GPU后端是有支持的: 但是在安装的过程中可能会遇到一些问题或者报错,这里复现一下我 ...
- flask+gunicorn+supervisor部署项目
一.安装模块 pip install gunicorn gevent # 如果使用python supervisor,需要安装模块 pip install supervisor # 建议使用yum安装 ...
- An Entry Example of Log4j
The log4j can be configured both programmatically and externally using special configuration files. ...
- Vue CLI中views和components文件夹的区别
首先,src/components和文件夹src/views都包含Vue组件. 关键区别在于某些Vue组件充当路由视图. 在Vue中(通常是Vue Router)处理路由时,将定义路由以切换组件中使用 ...