最近做项目,需求做一个剪切图片的东东。如下图

主要是在一个canvas上面。根据crop的大小画出半透明的效果

<Canvas x:Name="imageCanvas" Visibility="Collapsed" ><Path x:Name="nonselectRegion" Fill="#88FFFFFF"  ><Path.Data><GeometryGroup><RectangleGeometry Rect="{Binding OuterRect}"></RectangleGeometry><RectangleGeometry Rect="{Binding SelectedRect}"></RectangleGeometry></GeometryGroup></Path.Data></Path><Path x:Name="selectRegion" Fill="Transparent" Stroke="{ThemeResource ApplicationForegroundThemeBrush}" StrokeThickness="1"><Path.Data><RectangleGeometry Rect="{Binding SelectedRect}"/></Path.Data></Path><Rectangle x:Name="horizontalLine" Canvas.Left="{Binding SelectedRect.Left}" Canvas.Top="{Binding HorizontalLineCanvasTop}" Height="1" Width="{Binding SelectedRect.Width}" Fill="{ThemeResource ApplicationForegroundThemeBrush}"/><Rectangle x:Name="verticalLine" Canvas.Left="{Binding VerticalLineCanvasLeft}" Canvas.Top="{Binding SelectedRect.Top}" Width="1" Height="{Binding SelectedRect.Height}" Fill="{ThemeResource ApplicationForegroundThemeBrush}"/><Rectangle x:Name="horizontalLine1" Canvas.Left="{Binding SelectedRect.Left}" Canvas.Top="{Binding HorizontalLine1CanvasTop}" Height="1" Width="{Binding SelectedRect.Width}" Fill="{ThemeResource ApplicationForegroundThemeBrush}"/><Rectangle x:Name="verticalLine1" Canvas.Left="{Binding VerticalLine1CanvasLeft}" Canvas.Top="{Binding SelectedRect.Top}" Width="1" Height="{Binding SelectedRect.Height}" Fill="{ThemeResource ApplicationForegroundThemeBrush}"/><Ellipse x:Name="topLeftThumb"  Canvas.Left="{Binding SelectedRect.Left}" Canvas.Top="{Binding SelectedRect.Top}"/><Ellipse x:Name="topRightThumb"  Canvas.Left="{Binding SelectedRect.Right}" Canvas.Top="{Binding SelectedRect.Top}"/><Ellipse x:Name="bottomLeftThumb"  Canvas.Left="{Binding SelectedRect.Left}" Canvas.Top="{Binding SelectedRect.Bottom}"/><Ellipse x:Name="bottomRightThumb"  Canvas.Left="{Binding SelectedRect.Right}" Canvas.Top="{Binding SelectedRect.Bottom}"/></Canvas>

另外一个重要的地方就是根据这个crop selection 得到剪切后的流。

代码如下:

 async static private Task<byte[]> GetPixelData(BitmapDecoder decoder, uint startPointX, uint startPointY,uint width, uint height, uint scaledWidth, uint scaledHeight){BitmapTransform transform = new BitmapTransform();BitmapBounds bounds = new BitmapBounds();bounds.X = startPointX;bounds.Y = startPointY;bounds.Height = height;bounds.Width = width;transform.Bounds = bounds;transform.ScaledWidth = scaledWidth;transform.ScaledHeight = scaledHeight;// Get the cropped pixels within the bounds of transform.PixelDataProvider pix = await decoder.GetPixelDataAsync(BitmapPixelFormat.Bgra8,BitmapAlphaMode.Straight,transform,ExifOrientationMode.IgnoreExifOrientation,ColorManagementMode.ColorManageToSRgb);byte[] pixels = pix.DetachPixelData();return pixels;}

在做这个控件的过程中发现了一个很有意思的东西。就是通过CameraCaptureUI 得到的图片。。看起来是旋转了90 度。。这是为什么呢??

拍照的时候是这样的

拍完了之后如果直接显示,却是这样的

感觉被反转了。。( ╯□╰ )。。

为什么。。等下一个随笔来说说。

有什么问题指出来,大家一起进步

转载于:https://www.cnblogs.com/FaDeKongJian/p/5158862.html

UWP crop image control相关推荐

  1. [UWP]实现一个轻量级的应用内消息通知控件

    [UWP]实现一个轻量级的应用内消息通知控件 原文:[UWP]实现一个轻量级的应用内消息通知控件 在UWP应用开发中,我们常常有向用户发送一些提示性消息的需求.这种时候我们一般会选择MessageDi ...

  2. 张高兴的 UWP 开发笔记:横向 ListView

    ListView 默认的排列方向是纵向 ( Orientation="Vertical" ) ,但如果我们需要横向显示的 ListView 怎么办? Blend for Visua ...

  3. [UWP]了解模板化控件(7):支持Command

    原文:[UWP]了解模板化控件(7):支持Command 以我的经验来说,要让TemplatedControl支持Command的需求不会很多,大部分情况用附加属性解决这个需求会更便利些,譬如UWPC ...

  4. UWP开发入门(十六)——常见的内存泄漏的原因

    原文:UWP开发入门(十六)--常见的内存泄漏的原因 本篇借鉴了同事翔哥的劳动成果,在巨人的肩膀上把稿子又念了一遍. 内存泄漏的概念我这里就不说了,之前<UWP开发入门(十三)--用Diagno ...

  5. UWP开发入门(十九)——10分钟学会在VS2015中使用Git

    原文:UWP开发入门(十九)--10分钟学会在VS2015中使用Git 写程序必然需要版本控制,哪怕是个人项目也是必须的.我们在开发UWP APP的时候,VS2015默认提供了对微软TFS和Git的支 ...

  6. win10 uwp 按下等待按钮

    我们经常需要一个按钮,在按下时,后台执行Task,这时不能再次按下按钮. 我们使用自定义控件,首先新建一个类,我把它命名是ProgressButton 一个进度条按钮,也就是我们按下时发生进度条,完成 ...

  7. 在UWP中自定义半边框样式的输入框

    Windows10发布已经有一阵子了,已经有一些公司上架了自己的UWP应用程序,为WindowsStore增添光彩.已经安装Windows10的用户也或多或少的安装了一些UWP的应用程序,针对这些UW ...

  8. UWP入门(二) -- 基础笔记

    UWP入门(二) -- 基础笔记 原文:UWP入门(二) -- 基础笔记 不错的UWP入门视频,1092417123,欢迎交流 UWP-04 - What i XMAL? XAML - XML Syn ...

  9. Inversion of Control Containers and the Dependency Injection pattern--Martin Fowler

    原文地址:https://martinfowler.com/articles/injection.html n the Java community there's been a rush of li ...

最新文章

  1. MSIL 教程(二):数组、分支、循环、使用不安全代码和如何调用Win32 API(转)...
  2. python绘图内容怎么保存_将绘图保存到图像文件,而不是使用Matplotlib显示 - python...
  3. sublime 光标由竖线变下横线
  4. G1垃圾收集器设计目标与改良手段【纯理论】
  5. CVPR 2020 Oral |神奇的自监督场景去遮挡
  6. 用触发器实现表的同步操作
  7. 测试库的接收到的数据是否完整(jrtplib为列)
  8. 使用回收站主键名、索引名问题
  9. MVC---张国亮总结心得第一季
  10. ArcGIS学习总结(四)——缓冲区分析应用
  11. html中显示日历的代码,用css+html+javascript实现简单日历的代码
  12. 用友NC系统与一卡通集成解决方案
  13. bzoj4246: 两个人的星座
  14. 正雅GS颌位重建技术为隐形正畸打开新篇章
  15. 关于517coding的10月月赛
  16. GPS导航(4):SIM908模块
  17. 华为应用内支付验签失败,报错Signature length not correct
  18. 计算机班音乐课怎么上,如何运用电脑课件进行音乐教学.doc
  19. 用计算机自动写作文,电脑写一篇作文用说明方法
  20. 最新版Kubernetes(k8s)-v1.22.3版本高可用集群

热门文章

  1. 解决首次运行WebDriverAgent手机开发者未信任问题
  2. android手机界面管理系统的设计与实现(硕士学位论文).pdf,基于Android系统的手机文件管理器的设计与实现...
  3. java 昨天_JAVA取得昨天的当前时间?
  4. mysql逻辑运算符的优先顺序_PL/SQL运算符优先级
  5. 系统策略禁止安装python_Win10系统如何禁止自动安装捆绑软件?
  6. 分享Kali Linux 2017年第23周镜像文件
  7. Xamarin Android提示内存溢出错误
  8. itstime后面跟什么_一文讲透什么是引流
  9. java任何封闭实例都不是java_《java并发编程实战》读书笔记3--对象的组合
  10. python 查看数据结构类型_python标准数据结构类型