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. ABC372 (D,E)

    ABC372 (D,E) D 一道比较简单的二分查找题目. 观察到每个数能成为 \(j\) 的条件是独立的,因此想到统计每个数能成为它前面哪些数的 \(j\). 对于每个\(ed​\), 二分 \(1 ...

  2. python报错:If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0

    相关: https://stackoverflow.com/questions/72441758/typeerror-descriptors-cannot-not-be-created-directl ...

  3. switch、case语句的问题

    switch.case语句: 点击查看代码 int state = 1; switch(state) { case 1: { //状态1执行的程序 } case 2: { //状态2执行的程序 } d ...

  4. centos7-arm架构yum源(armhf) yum源(中国科学技术大学)

    # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # upda ...

  5. 模态内重叠优化,简单有效的CLIP微调方法 | BMVC'24 Oral

    来源:晓飞的算法工程笔记 公众号,转载请注明出处 论文: CLIP Adaptation by Intra-modal Overlap Reduction 论文地址:https://arxiv.org ...

  6. pytorch的四个hook函数

    训练神经网络模型有时需要观察模型内部模块的输入输出,或是期望在不修改原始模块结构的情况下调整中间模块的输出,pytorch可以用hook回调函数来实现这一功能.主要使用四个hook注册函数:regis ...

  7. 《Django 5 By Example》阅读笔记:p237-p338

    <Django 5 By Example>学习第11天,p237-p338总结,总计102页. 一.技术总结 1.follow system(关注功能) 表之间的关系有三种:OneToOn ...

  8. Solr 的核心就是搜索

    原文  http://www.aptusource.org/2014/06/searching-is-what-its-all-about/ Solr 的主要功能就是强大的查询处理.在本文中,你将会看 ...

  9. JDBC性能小贴

    本文由 ImportNew - 刘志军 翻译自 javarevisited.如需转载本文,请先参见文章末尾处的转载要求. 本文收集了一些用于提升JDBC性能的方法.Java应用或者JavaEE Web ...

  10. An Entry Example of Log4j

    The log4j can be configured both programmatically and externally using special configuration files. ...