前端xaml页面代码

<Window x:Class="WpfApplication6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="" Width="">
<Grid> <Canvas x:Name="Screen" Width="96 " Height="">
<InkCanvas x:Name="inkCanvas" Height="" Width="" Canvas.Left="-203" Canvas.Top="-108" />
<TextBlock Canvas.Left="" Canvas.Top="" x:Name="VSSize" ></TextBlock>
</Canvas> <Button Content="保存" Height="" HorizontalAlignment="Right" Margin="0,274,0,12" Name="button1" Width="" Click="button1_Click" />
</Grid>
</Window>

后台cs页面代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Windows.Ink; namespace WpfApplication6
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
DrawingAttributes drawingAttributes;
public MainWindow()
{
InitializeComponent();
//创建 DrawingAttributes 类的一个实例
drawingAttributes = new DrawingAttributes();
//将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
//InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
inkCanvas.DefaultDrawingAttributes = drawingAttributes;
//设置 DrawingAttributes 的 Color 属性设置颜色
drawingAttributes.Color = Colors.Red;
} private void button1_Click(object sender, RoutedEventArgs e)
{
RenderTargetBitmap rtb = new RenderTargetBitmap(, , this.Screen.Width, this.Screen.Height, PixelFormats.Default);
rtb.Render(this.inkCanvas);
BmpBitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
string file = "d:\\xxx.jpg";
using (Stream stm = File.Create(file))
{
encoder.Save(stm);
}
} }
}

C# wpf InkCanvas 保存图片jpg的更多相关文章

  1. WPF InkCanvas 毛笔效果

    原文:WPF InkCanvas 毛笔效果 1.先来看看InkCanvas的一般用法: <InkCanvas>     <InkCanvas.DefaultDrawingAttrib ...

  2. WPF InkCanvas 画图 基础使用教程

    大家好,由于很多原因,我有很长一段时间没有在 CSDN 上分享我的学习成果了,如今终于可以回归分享之路了. 之前在做一个项目的时候,想在一个区域里绘制自己的图形,于是上网搜索资料,无意中找到了 Ink ...

  3. WPFのInkCanvas作为蒙版透明笔迹不透明

    本人最近利用inkcavas做一个蒙版的功能,结果发现笔迹稀释了,经过一番查找发现:应该讲inkcavas的背景设置为白色,然后透明,而不是将整个控件透明,具体代码: <InkCanvas Na ...

  4. WPF InkCanvas EditingMode为Select时 在其选择时各种事件中撤销Select模式的方法

    InkCanvas有多种输入模式. 通过InkCanvasEditingMode来进行对其调整 分别是 None=0// 忽略鼠标和手写笔输入 Ink = 1// 允许用户绘制批注,默认模式.使用鼠标 ...

  5. WPF InkCanvas MouseDown及MouseLeftButtonDown事件不触发的代替事件

    PreviewMouseDown事件可以触发  再通过e.LeftButton 的状态判断是否按钮被按下 特此备忘

  6. WPF InkCanvas 书写毛笔效果

    https://www.cnblogs.com/younShieh/p/10602787.html

  7. WPF 毛笔字

    1.先来看看InkCanvas的一般用法: <InkCanvas>     <InkCanvas.DefaultDrawingAttributes>           < ...

  8. 多点触摸画板(MultiTouchCanvas)

    这是个简单的支持多点触摸的画板控件, 绘制功能基于WPF InkCanvas,也是我drawTool系列文章的开篇. 阅读该文章后可能产生一些问题: 1. 如果对生成的笔迹对象进行控制 如果要对生成的 ...

  9. WPF布局管理之Canvas、InkCanvas (转)

    一.Canvas 在WPF中子元素的绝对定位的布局控件 其子元素使用Width.Height定义元素的宽度和高度 使用Convas.Left(Convas.Right).Convas.Top(Conv ...

随机推荐

  1. 安装tftp服务器进行文件传输

    1. 安装: sudo apt-get install tftp-hpa tftpd-hpa ps: tftpd是服务器,tftp是客户端,客户端能发送和获取,服务器不能动. 2. 配置文件: sud ...

  2. [leetcode]124. Binary Tree Maximum Path Sum二叉树最大路径和

    Given a non-empty binary tree, find the maximum path sum. For this problem, a path is defined as any ...

  3. [leetcode]173. Binary Search Tree Iterator 二叉搜索树迭代器

    Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro ...

  4. linux下安装memcached以及扩展(xampp环境)

    网上有很多相关的文章,就不具体写了.(假设这里文件都上传到更目录下的tmp文件夹下) 1.大致流程先装 libevent 和 memcache http://www.cnblogs.com/zgx/a ...

  5. mysql优化概述3

    1.前缀索引 建立索引关键字一种方案. 通常会使用字段的整体作为索引关键字. 有时,使用字段前部分数据,也可以去识别某些记录. 语法: index `索引名` (`字段`(N)); 使用字段前N个字符 ...

  6. JTSL/EL Expression学习

    最早的一个学习笔记,时间过去了久了,供java web初学者参考. JTSL/EL Expression学习安排 学习目标:掌握几个常见标签的使用,通晓工作原理,详细到代码层面,遇到问题时能查得出异常 ...

  7. PAT 1052 卖个萌 (20)(代码+思路)

    1052 卖个萌 (20)(20 分) 萌萌哒表情符号通常由"手"."眼"."口"三个主要部分组成.简单起见,我们假设一个表情符号是按下列格 ...

  8. geoserver的rest服务介绍,搭建java程序

    在geoserver中使用 Restlet 来提供所有的rest服务,并且geoserver中所有的在/rest目录下的请求都被看作为一个restful server,下图就是rest服务的调用过程 ...

  9. vue run dev 8080端口被占用

    用vue 官方脚手架vue-cli构建项目容易碰到一些小错误 vue init webpack project-name ...... cd project-name npm install npm ...

  10. ubuntu系统中安装RoboMongo

    1.下载RoboMongo RoboMongo官网下载链接.选择好相应版本. 2.解压文件 tar -xzf robomongo--linux-x86_64-.tar.gzcd robomongo-0 ...