c# WPF convert photo to Sketch effects
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的更多相关文章
- wpf convert png to xaml
原文:wpf convert png to xaml 把png图片转化成xaml资源 <ResourceDictionary xmlns="http://schemas.microso ...
- WPF Convert使用
在存在基本数据缓存时,可以传入一个数据库中的数据唯一标识码,然后利用自己编写的Convert类,这个Convert类必须实现IValueConverter接口,进行转换,在进行转换的过程中,可以从基本 ...
- sketch 相关论文
sketch 相关论文 Sketch Simplification We present a novel technique to simplify sketch drawings based on ...
- 【WPF/C#】联网异步获取二进制文件(如图片)的流程
步骤: 联网异步获取Json数据. 使用Json.NET工具,反序列化Json为对应的实体类,获得该实体类的对象. 从对象身上获取图片路径(实体类中定义了头像图片是string类型的文件路径). 根据 ...
- 【C#/WPF】Bitmap、BitmapImage、ImageSource 、byte[]转换问题
C#/WPF项目中,用到图像相关的功能时,涉及到多种图像数据类型的相互转换问题,这里做了个整理.包含的内容如下: Bitmap和BitmapImage相互转换. RenderTargetBitmap ...
- ImageMagick命令执行学习笔记(常见于图片预览处)
实验版本: ImageMagick版本:6.9.2 push graphic-context viewbox 0 0 640 480 fill 'url(https://"|whoami&q ...
- 浅谈WPF中对控件的位图特效(WPF Bitmap Effects)
原文:浅谈WPF中对控件的位图特效(WPF Bitmap Effects) -------------------------------------------------------------- ...
- wpf控件提示Value ‘’ can not convert
我们在对控件的ErrorTemplate设置后,有时会出现Value '' can not convert. 为什么会出现呢? 原因:如果控件的输入值和null不能转换(比如控件要求的是int或flo ...
- WPF MultiBinding后台绑定动态属性 属性改变不调用Convert的问题
一开始的写法: MultiBinding mb = new MultiBinding(); Binding b1 = new Binding(); b1.ElementName = "tex ...
- 准备.Net转前端开发-WPF界面框架那些事,值得珍藏的8个问题
题外话 不出意外,本片内容应该是最后一篇关于.Net技术的博客,做.Net的伙伴们忽喷忽喷..Net挺好的,微软最近在跨平台方面搞的水深火热,更新也比较频繁,而且博客园的很多大牛也写的有跨平台相关技术 ...
随机推荐
- ESP8266 + L298N
L298N 知乎教程 L298N ESP8266 + L298N 连线 电机转的方向 电源引脚 VCC 外接直流电源引脚,电压范围在5~35V之间 GND GND是接地引脚,连接到电源负极 5V 驱动 ...
- SqlSugarClient 代码优先建表, 根据给定的实体类,创建SQL语句, 之后创建MySQL表
using SqlSugar; using System; using System.Collections.Generic; using System.Reflection; using Syste ...
- ubuntu 安装使用 mytop
apt搜索一下 $ sudo apt search mytop Sorting... Done Full Text Search... Done mytop/focal,focal,now 1.9.1 ...
- ElementUI ---- dialog点击取消后蒙遮层不消失
场景: 页面A打开了 dialog, 然后点击 页面A dialog 的按钮 跳转到 页面B,并且打开页面B的 dialog 但是页面B的 dialog 关闭后,蒙遮层并没消失(已经设置了 :appe ...
- 基于nginx的tomcat负载均衡和集群(超简单)
今天看到"基于apache的tomcat负载均衡和集群配置 "这篇文章成为javaEye热点. 略看了一下,感觉太复杂,要配置的东西太多,因此在这里写出一种更简洁的方法. 要集群t ...
- 基于python搭建FTP服务
使用python搭建FTP服务非常容易,且非常稳定,更重要的是可以实现一些精细化的控制,例如精细的访问权限配置,详细的日志记录等工作 这里是使用了pyftpdlib模块 1. 安装 pip insta ...
- Ubuntu默认启动到字符界面
修改/etc/default/grub sudo cp /etc/default/grub /etc/default/grub.bak sudo chmod 0777 /etc/default/gru ...
- Nuxt.js 应用中的 error 事件钩子
title: Nuxt.js 应用中的 error 事件钩子 date: 2024/12/3 updated: 2024/12/3 author: cmdragon excerpt: 在任何 Web ...
- Electron(1) - 快速入门
1.前言 本节主要讲述Electron的环境搭建以及如何快速创建一个应用 官方文档 2.环境搭建 (1)安装node.js (2)创建项目目录,初始化配置文件 //进入项目目录 并在此目录打开cmd窗 ...
- PictureMarkerSymbol透明的问题
由于我使用的是位图图片,所以不可能将图片背景处理成透明.不过还是可以通过参数的设定来达到这种效果. PictureMarkerSymbol pPMS = new PictureMarkerSymbol ...