UWP 裁切 SoftwareBitmap
//设置源图ImageSource为WriteableBitmap类型
BitmapImage himage = this.imageTarget2.Source as BitmapImage; RandomAccessStreamReference random = RandomAccessStreamReference.CreateFromUri(himage.UriSource); using (IRandomAccessStream stream = await random.OpenReadAsync())
{
stream.Seek();
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
BitmapFrame bitmapFrame = await decoder.GetFrameAsync();
// Get the pixels
var transform = new BitmapTransform { ScaledWidth = decoder.PixelWidth, ScaledHeight = decoder.PixelHeight };
PixelDataProvider dataProvider =
await bitmapFrame.GetPixelDataAsync(BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Straight,
transform,
ExifOrientationMode.RespectExifOrientation,
ColorManagementMode.ColorManageToSRgb); var image_array = dataProvider.DetachPixelData();
var image_array_width = (int)decoder.PixelWidth;
var image_array_height = (int)decoder.PixelHeight;
var writeableBitmap = new WriteableBitmap(image_array_width, image_array_height);
stream.Seek();
await writeableBitmap.SetSourceAsync(stream);
this.imageSource1.Source = writeableBitmap;//WriteableBitmap 类型很重要
}
//裁切方法
public async static Task<SoftwareBitmap> GetCroppedBitmapAsync(SoftwareBitmap softwareBitmap, uint x, uint y, uint width, uint height)
{
using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream); encoder.SetSoftwareBitmap(softwareBitmap); encoder.BitmapTransform.Bounds = new BitmapBounds()
{
X = x,
Y = y,
Height = height,
Width = width
}; await encoder.FlushAsync(); BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); return await decoder.GetSoftwareBitmapAsync(softwareBitmap.BitmapPixelFormat, softwareBitmap.BitmapAlphaMode);
}
}
//实例:
WriteableBitmap wb = this.imageSource1.Source as WriteableBitmap; ;
SoftwareBitmap sb = new SoftwareBitmap(BitmapPixelFormat.Bgra8, wb.PixelWidth, wb.PixelHeight);
sb.CopyFromBuffer(wb.PixelBuffer);//WriteableBitmap转为SoftwareBitmap
var sbmp = await GetCroppedBitmapAsync(sb, 0, 50, 100, 100);//调用裁切方法
WriteableBitmap writeableBitmap = new WriteableBitmap(sbmp.PixelWidth, sbmp.PixelHeight);
sbmp.CopyToBuffer(writeableBitmap.PixelBuffer);//SoftwareBitmap转为WriteableBitmap
this.imageTarget2.Source = writeableBitmap;//设置目标图ImageSource为WriteableBitmap类型
UWP 裁切 SoftwareBitmap的更多相关文章
- [uwp]自定义图形裁切控件
开始之前,先上一张美图.图中的花叫什么,我已经忘了,或者说从来就不知道,总之谓之曰“野花”.只记得花很美,很香,春夏时节,漫山遍野全是她.这大概是七八年前的记忆了,不过她依旧会很准时的在山上沐浴春光, ...
- UWP 使用Windows.Media.FaceAnalysis.FaceDetector检测人脸
话说现在检测人脸的技术有很多.有在线AI服务,比如Megvii Face++,Microsoft Cognitive Services,Tencent AI等等.还有本地的库实现的,比如OpenCV. ...
- 19、UWP 新特性(Creator Update)
Build 版本 15063+ 1.能够为 CompositionObjects 的其他属性(阴影,裁剪,属性集合)添加动画 2.当设备插上电源的时候,通过 Extended Excution Ses ...
- 05、Windows Store app 的图片裁切(更新)
在 Win Phone Silverlight api 中,有一个 PhotoChooserTask 选择器,指定宽.高属性,在选择图片的时候, 可以进行裁切,代码: PhotoChooserTask ...
- UWP通过机器学习加载ONNX进行表情识别
首先我们先来说说这个ONNX ONNX是一种针对机器学习所设计的开放式的文件格式,用于存储训练好的模型.它使得不同的人工智能框架(如Pytorch, MXNet)可以采用相同格式存储模型数据并交互. ...
- UWP 律师查询 MVVM
APP简介 律师查询是基于聚合数据的律师查询接口做的,这个接口目前处于停用状态,但是,由于我是之前申请的,所以,还可以用,应该是无法再申请了. 效果图 开发 一.HttpHelper 既然是请求接口的 ...
- 领域驱动和MVVM应用于UWP开发的一些思考
领域驱动和MVVM应用于UWP开发的一些思考 0x00 起因 有段时间没写博客了,其实最近本来是根据梳理的MSDN上的资料(UWP开发目录整理)有条不紊的进行UWP学习的.学习中有了心得体会或遇到了问 ...
- UWP中实现自定义标题栏
UWP中实现自定义标题栏 0x00 起因 在UWP开发中,有时候我们希望实现自定义标题栏,例如在标题栏中加入搜索框.按钮之类的控件.搜了下资料居然在一个日文网站找到了一篇介绍这个主题的文章: http ...
- UWP中新加的数据绑定方式x:Bind分析总结
UWP中新加的数据绑定方式x:Bind分析总结 0x00 UWP中的x:Bind 由之前有过WPF开发经验,所以在学习UWP的时候直接省略了XAML.数据绑定等几个看着十分眼熟的主题.学习过程中倒是也 ...
随机推荐
- 用Ajax图片上传、预览、修改图片
首选图片的上传和下载并不是很难,但要注意细节. 一,给出前端图片上传的html代码 1.图片上传的控件 <img src="/${res}/images/default.png&quo ...
- kvm 虚拟化概述及 virt-manager 安装虚拟机
一.KVM定义 基于内核的虚拟机(英语:Kernel-based Virtual Machine,简称KVM),是一种用于Linux内核中的虚拟化基础设施. KVM眼下支持Intel VT及AMD-V ...
- Android 基于Bmob平台数据管理常用方法整理
最近想搞一下基于Bmob平台的应用开发,发现确实挺方便的,很好的解决了服务器后台部署的难题, 但是也有一些弊端,数据架构的可扩展性不强,做一些数据结构简单的应用还是可以的. package com.b ...
- Android SqlDelight具体解释和Demo样例
一.简单介绍 SQLDelight 和 SqlBrite 是 Square 公司推出的一个 Android 平台数据库解决方式. 在了解这个两个东西前,必须先得有Andorid的Sqlite的知识(S ...
- 【codeforces 750A】New Year and Hurry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- ZOJ Monthly, June 2014 解题报告
A.Another Recurrence Sequence problemId=5287">B.Gears 题目大意:有n个齿轮,一開始各自为一组.之后进行m次操作,包含下面4种类型: ...
- Gini 系数与熵的关系
首先来看二者的基本定义: ⎧⎩⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪H(X)=−∑k=1KpklnpkGini(X)=∑k=1Kpk(1−pk) 将 f(x)=−lnx 在 x=1 处进行一阶泰勒展开(忽略高阶无穷小 ...
- SQL生成n位随机字符串
--1.随着newid() go --创建一个视图(因为不能在功能直接用于newid()) create view vnewid as select newid() N'MacoId'; go --创 ...
- Linux的设备文件名与硬盘分区已经挂载点的关系
以CentOS6.3为例. 选择的硬盘设备名是/dev/sda,即第一块STAT硬盘,然后在该硬盘分了3个主分区和1个扩展分区,设备名分别是/dev/sda1,/dev/sda2,/dev/sda3, ...
- 【27.48%】【codeforces 699D】 Fix a Tree
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...