using the online website https://imagetosketch.com/

<Window x:Class="WpfMosaic.PhotoSketchWind"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfMosaic"
mc:Ignorable="d"
Title="PhotoSketchWind" Height="450" Width="800">
<Grid>
<Border>
<WrapPanel ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible"
x:Name="wrapPanel">
</WrapPanel>
</Border> </Grid>
</Window> using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Shapes; namespace WpfMosaic
{
/// <summary>
/// Interaction logic for PhotoSketchWind.xaml
/// </summary>
public partial class PhotoSketchWind : Window
{
public PhotoSketchWind()
{
InitializeComponent();
Loaded += PhotoSketchWind_Loaded;
} private void PhotoSketchWind_Loaded(object sender, RoutedEventArgs e)
{
string imgFile = @"C:\Users\gwang\source\repos\WpfMosaic\bin\Debug\12.jpg";
ProcessPhoto(imgFile);
} void ProcessPhoto(string imgFile)
{
var files = ImageSketchServer.ProcessPhoto(imgFile);
if (files != null && files.Count > 0)
{
foreach (var f in files)
{
var img = new Image() { MaxWidth = 222, Source = new BitmapImage(new Uri(f, UriKind.RelativeOrAbsolute)) };
img.Tag = f;
img.MouseLeftButtonDown += Img_MouseLeftButtonDown;
wrapPanel.Children.Add(img);
} } } private void Img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
System.Diagnostics.Process.Start("" + (sender as Image).Tag);
}
}
} using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks; namespace WpfMosaic
{
public class Httphelper
{ public static string Upload(string url, string filePath)
{
try
{
string modelId = "4f1e2e3d-6231-4b13-96a4-835e5af10394";
string updateTime = "2016-11-03 14:17:25";
string encrypt = "f933797503d6e2c36762428a280e0559";
string fileName = Path.GetFileName(filePath); byte[] fileContentByte = File.ReadAllBytes(filePath); //#region 将文件转成二进制 //FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
//fileContentByte = new byte[fs.Length]; // 二进制文件
//fs.Read(fileContentByte, 0, Convert.ToInt32(fs.Length));
//fs.Close(); //#endregion #region 定义请求体中的内容 并转成二进制 string boundary = "WebKitFormBoundarybgqrda0HwT2BjMam";
string Enter = "\r\n"; string modelIdStr = "--" + boundary + Enter
+ "Content-Disposition: form-data; name=\"modelId\"" + Enter + Enter
+ modelId + Enter; string fileContentStr = "--" + boundary + Enter
+ "Content-Type:bimage/jpeg" + Enter
+ "Content-Disposition: form-data; name=\"myfile\"; filename=\"" + fileName + "\"" + Enter + Enter; string updateTimeStr = Enter + "--" + boundary + Enter
+ "Content-Disposition: form-data; name=\"updateTime\"" + Enter + Enter
+ updateTime; string encryptStr = Enter + "--" + boundary + Enter
+ "Content-Disposition: form-data; name=\"encrypt\"" + Enter + Enter
+ encrypt + Enter + "--" + boundary + "--"; var modelIdStrByte = Encoding.UTF8.GetBytes(modelIdStr);//modelId所有字符串二进制 var fileContentStrByte = Encoding.UTF8.GetBytes(fileContentStr);//fileContent一些名称等信息的二进制(不包含文件本身) var updateTimeStrByte = Encoding.UTF8.GetBytes(updateTimeStr);//updateTime所有字符串二进制 var encryptStrByte = Encoding.UTF8.GetBytes(encryptStr);//encrypt所有字符串二进制 var endString = Encoding.UTF8.GetBytes(Enter + "--" + boundary + "--"); #endregion HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "multipart/form-data;boundary=" + boundary; Stream myRequestStream = request.GetRequestStream();//定义请求流 #region 将各个二进制 安顺序写入请求流 modelIdStr -> (fileContentStr + fileContent) -> uodateTimeStr -> encryptStr // myRequestStream.Write(modelIdStrByte, 0, modelIdStrByte.Length); myRequestStream.Write(fileContentStrByte, 0, fileContentStrByte.Length);
myRequestStream.Write(fileContentByte, 0, fileContentByte.Length); // myRequestStream.Write(updateTimeStrByte, 0, updateTimeStrByte.Length); // myRequestStream.Write(encryptStrByte, 0, encryptStrByte.Length); myRequestStream.Write(endString, 0, endString.Length); #endregion HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8")); string retString = myStreamReader.ReadToEnd(); myStreamReader.Close();
myResponseStream.Close(); return retString;
}
catch
{ return ""; } }
public static string HttpGet(string url)
{
try
{
//https://access.sketcherai.com:8999/status/iDHMujs3
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "Get";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
string retString = myStreamReader.ReadToEnd(); myStreamReader.Close();
myResponseStream.Close(); return retString;
}
catch
{ return "";
} } } public class ImageSketchServer
{
public static List<string> ProcessPhoto(string filePath)
{
string url = "https://access.sketcherai.com:8999/upload";
string token = Httphelper.Upload(url, filePath);
if (string.IsNullOrEmpty(token))
{
return null;
}
url = "https://access.sketcherai.com:8999/status/" + token;
string abcs = Httphelper.HttpGet(url); if (string.IsNullOrEmpty(abcs))
{
return null;
}
else
{ //thumb img: https://access.sketcherai.com:8889/results/iDHMujs3_a_tn.jpg
//org img: https://access.sketcherai.com:8889/results/iDHMujs3_a.jpg List<string> list = new List<string>();
foreach (var c in abcs)
{
list.Add("https://access.sketcherai.com:8889/results/iDHMujs3_" + c + "_tn.jpg");
}
return list;
} }
public static string ToOriginal(string thPath)
{ return thPath.Replace("_tn.jpg", ".jpg");
} } }

  

c# WPF convert photo to Sketch effects的更多相关文章

  1. wpf convert png to xaml

    原文:wpf convert png to xaml 把png图片转化成xaml资源 <ResourceDictionary xmlns="http://schemas.microso ...

  2. WPF Convert使用

    在存在基本数据缓存时,可以传入一个数据库中的数据唯一标识码,然后利用自己编写的Convert类,这个Convert类必须实现IValueConverter接口,进行转换,在进行转换的过程中,可以从基本 ...

  3. sketch 相关论文

    sketch 相关论文 Sketch Simplification We present a novel technique to simplify sketch drawings based on ...

  4. 【WPF/C#】联网异步获取二进制文件(如图片)的流程

    步骤: 联网异步获取Json数据. 使用Json.NET工具,反序列化Json为对应的实体类,获得该实体类的对象. 从对象身上获取图片路径(实体类中定义了头像图片是string类型的文件路径). 根据 ...

  5. 【C#/WPF】Bitmap、BitmapImage、ImageSource 、byte[]转换问题

    C#/WPF项目中,用到图像相关的功能时,涉及到多种图像数据类型的相互转换问题,这里做了个整理.包含的内容如下: Bitmap和BitmapImage相互转换. RenderTargetBitmap ...

  6. ImageMagick命令执行学习笔记(常见于图片预览处)

    实验版本: ImageMagick版本:6.9.2 push graphic-context viewbox 0 0 640 480 fill 'url(https://"|whoami&q ...

  7. 浅谈WPF中对控件的位图特效(WPF Bitmap Effects)

    原文:浅谈WPF中对控件的位图特效(WPF Bitmap Effects) -------------------------------------------------------------- ...

  8. wpf控件提示Value ‘’ can not convert

    我们在对控件的ErrorTemplate设置后,有时会出现Value '' can not convert. 为什么会出现呢? 原因:如果控件的输入值和null不能转换(比如控件要求的是int或flo ...

  9. WPF MultiBinding后台绑定动态属性 属性改变不调用Convert的问题

    一开始的写法: MultiBinding mb = new MultiBinding(); Binding b1 = new Binding(); b1.ElementName = "tex ...

  10. 准备.Net转前端开发-WPF界面框架那些事,值得珍藏的8个问题

    题外话 不出意外,本片内容应该是最后一篇关于.Net技术的博客,做.Net的伙伴们忽喷忽喷..Net挺好的,微软最近在跨平台方面搞的水深火热,更新也比较频繁,而且博客园的很多大牛也写的有跨平台相关技术 ...

随机推荐

  1. SpringBoot项目集成MinIO

    一.MinIO的下载安装以及基本使用 1.下载地址:https://dl.min.io/server/minio/release/windows-amd64/minio.exe 2.下载好后需要手动创 ...

  2. MPLS多协议标签交换

    多协议标签交换 MPLS(Multiprotocol Label Switching)是一种网络协议,用于在数据包交换网络中高效地进行数据路由转发.MPLS通过引入标签(Label)来对数据包进行标识 ...

  3. 用于自然语言处理的循环神经网络RNN

    前一篇:<人工智能模型学习到的知识是怎样的一种存在?> 序言:在人工智能领域,卷积神经网络(CNN)备受瞩目,但神经网络的种类远不止于此.实际上,不同类型的神经网络各有其独特的应用场景.在 ...

  4. 创建一个具有商业品质的 Eclipse IDE

    创建具有商业品质且可插入 Eclipse 的专业 IDE Prashant Deva (pdeva@placidsystems.com), 创始人, Placid Systems 简介:  " ...

  5. 【原创】linux实时操作系统xenomai看门狗(watchdog)机制及作用介绍

    版权声明:本文为本文为博主原创文章,转载请注明出处 https://www.cnblogs.com/wsg1100.如有错误,欢迎指正. 目录 一.前言 PREEMPT-RT(RT Throttlin ...

  6. golang之类型转换cast

    Go 语言作为强类型语言,在使用 Golang 开发项目时,经常会遇到类型转换的场景,整型之间可以直接转换,字节切片和字符串之间也可以直接转换. 但是,如果整型和字符串之间做类型转换,则需要使用 st ...

  7. Element-UI 中关于 Table 的几个功能点简介(行列的合并和样式、合计行配置等)

    〇.前言 本文记录了关于 Element 框架中 Table 的几个功能点,后续将持续更新. el-table 官网地址:https://element.eleme.cn/#/zh-CN/compon ...

  8. PostgreSql Docker 主从热备,异步流复制方案

    环境说明 Docker Windows 11 PostgreSql 16 方案步骤 0. 宿主机准备: 找个地方创建一个文件夹用来挂载容器中数据库Data文件夹,这里我用的是: C:\Users\Ad ...

  9. Nuxt.js 应用中的 render:html 事件钩子

    title: Nuxt.js 应用中的 render:html 事件钩子 date: 2024/11/30 updated: 2024/11/30 author: cmdragon excerpt: ...

  10. Echarts 颜色管理

    1.Echarts的颜色设计 Echarts的颜色的设置分为两种:色盘和具体颜色 色盘适合做全局设置,因为他里面有多个颜色,通俗的说色盘就是颜色预设值列表,色盘统一使用color属性进行配置. 而具体 ...