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. 银河麒麟操作系统root用户登录图形化界面

    第一步.为root用户设置密码 sudo passwd 设置root用户密码 第二步.开启root登录权限 vim /usr/share/lightdm/lightdm.conf.d/60-kylin ...

  2. 支持多语言、多商店的商城,.Net7 + EF7领域驱动设计架构

    推荐一个跨平台.模块化.可扩展且超快速的开源一体化电子商务平台. 01项目简介 Smartstore 支持桌面和移动平台.多语言.多商店.多货币的商城,并支持SEO优化,支持无限数量的产品和类别.报表 ...

  3. Quartz集群增强版_00.How to use?(如何使用)

    Quartz集群增强版_00.How to use?(如何使用) 转载请著名出处 https://www.cnblogs.com/funnyzpc/p/18540378 开源地址 https://gi ...

  4. jquery datatable 全选,反选 参考文档

    1 版本号 DataTables 1.10.12 2 API文档地址 http://datatables.club/reference/option/ 官方option http://datatabl ...

  5. Java真的没出路了吗?

    Java从1991年由James Gosling和他的同事们开发, 至今已经三十多年, 我们知道,任何产品都有生命周期, 都要经历从诞生.发展.成熟.消亡四个阶段, 目前的Java已经处在成熟阶段, ...

  6. 最全ECharts 实战大全(速记版+资源)

    hello,大家好,我是程序员海军,公众号已经快一年多没更新了,没更新的这段时间,我去哪了呢.这两年经历了很多事情,主要情感上占据大部分时间, 从失恋 - 谈对象 - 再失恋. 言归正传,近期我负责的 ...

  7. python之异步任务框架Celery

    官网参考: Celery 官网:http://www.celeryproject.org/ Celery 官方文档英文版:http://docs.celeryproject.org/en/latest ...

  8. 【论文系列】PPO知识点梳理 (尽我可能细致通俗理解!)

    零.题记 这篇博客一方面为了记录当前的知识点,另一方面PPO算法实在是太重要了,不但要从理论上理解它到底是怎样实现的,还需要从代码方面进行学习和记录,这里我就通俗的将这个知识点进行简单的记录,用来日后 ...

  9. CHDFS 安全便捷的大数据访问体验

    一.背景 云 HDFS(Cloud HDFS,CHDFS)是腾讯云提供的支持标准 HDFS 访问协议.卓越性能.分层命名空间的分布式文件系统. CHDFS 主要解决大数据场景下海量数据存储和数据分析, ...

  10. Flutter shared_preferrence报错

    Flutter shared_preferrence报错 在main函数中runApp之前添加**WidgetsFlutterBinding.ensureInitialized();确保初始化成功 v ...