/// <summary> /// 把 Emoji编码 [e]1f1e6-1f1fa[/e] /// [e]1f1e6[/e] /// [e]1f1fa[/e] /// [e]1f1e6[/e] /// [e]1f1f9[/e] 换成对应的字符串,此字符串能被window8.1,ios,andriod 直接显示. /// /// 如果在网页中显示,需要设置字体为 'Segoe UI Emoji' 如下.当然客户机还必须得有这个字体. /// /// <span style="font-family:'Segoe UI Emoji';"></span> /// /// </summary> /// <param name="paramContent"></param> /// <returns></returns> public string GetEmoji(string paramContent) { string paramContentR = paramContent.Replace("[e]", "\\u").Replace("[/e]", ""); var unicodehex = new char[6] { '0', '0', '0', '0', '0', '0' }; StringBuilder newString = new StringBuilder(2000); StringBuilder tempEmojiSB = new StringBuilder(20); StringBuilder tmps = new StringBuilder(5); int ln = paramContent.Length; for (int index = 0; index < ln; index++) { int i = index; //把指针给一个临时变量,方便出错时,现场恢复. try { if (paramContent[i] == '[') { //预测 if (paramContent[i + 1] == 'e') { if (paramContent[i + 2] == ']') //[e]的后面4位是 unicode 的16进制数值. { i = i + 3; //前进3位 i = ChangUnicodeToUTF16(paramContent, tempEmojiSB, tmps, i); if (paramContent[i] == '-') //向前探测1位 看看是否双字符 形如1f1e7-1f1ea { i++; i = ChangUnicodeToUTF16(paramContent, tempEmojiSB, tmps, i); } ; if (paramContent[i] == '[') { if (paramContent[i + 1] == '/') { if (paramContent[i + 2] == 'e') { if (paramContent[i + 3] == ']') { i = i + 3; //再前进4位 index = i; //识别转换成功 newString.Append(tempEmojiSB.ToString()); //识别转换成功 tempEmojiSB.Clear(); continue; } } } } } } } index = i; } catch (Exception ex) { ConsoleLog.Output(ex); //解析失败仍然继续 } newString.Append(paramContent[index]); } return(newString.ToString()); }
/// <summary> /// 创建二维码 /// </summary> /// <param name="QRString">二维码字符串</param> /// <param name="QRCodeEncodeMode">二维码编码(Byte、AlphaNumeric、Numeric)</param> /// <param name="QRCodeScale">二维码尺寸(Version为0时,1:26x26,每加1宽和高各加25</param> /// <param name="QRCodeVersion">二维码密集度0-40</param> /// <param name="QRCodeErrorCorrect">二维码纠错能力(L:7% M:15% Q:25% H:30%)</param> /// <param name="hasLogo">是否有logo(logo尺寸50x50,QRCodeScale>=5,QRCodeErrorCorrect为H级)</param> /// <param name="logoFilePath">logo路径</param> /// <returns></returns> public static BitmapSource CreateQRCode(string QRString, string QRCodeEncodeMode, short QRCodeScale, int QRCodeVersion, string QRCodeErrorCorrect, bool hasLogo, string logoFilePath) { QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); switch (QRCodeEncodeMode) { case "Byte": qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; break; case "AlphaNumeric": qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.ALPHA_NUMERIC; break; case "Numeric": qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.NUMERIC; break; default: qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; break; } qrCodeEncoder.QRCodeScale = QRCodeScale; qrCodeEncoder.QRCodeVersion = QRCodeVersion; switch (QRCodeErrorCorrect) { case "L": qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.L; break; case "M": qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; break; case "Q": qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.Q; break; case "H": qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H; break; default: qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.H; break; } try { System.Drawing.Image image = qrCodeEncoder.Encode(QRString, System.Text.Encoding.UTF8); if (hasLogo) { System.Drawing.Image copyImage = System.Drawing.Image.FromFile(logoFilePath); Graphics g = Graphics.FromImage(image); int x = image.Width / 2 - copyImage.Width / 2; int y = image.Height / 2 - copyImage.Height / 2; g.DrawImage(copyImage, new Rectangle(x, y, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel); g.Dispose(); copyImage.Dispose(); } System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image); image.Dispose(); return(Helpers.ConvertBitmapToBitmapSource(bmp)); } catch (Exception ex) { ConsoleLog.Output("QRCode Error:" + ex.Message); LogHelper.log.Info("QRCode Error:" + ex.Message); return(null); } }
private static void OnMessageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { try { var message = e.NewValue as Messageobject; var mapcontrol = (MapBubble)d; var serverUri = new Uri(System.Web.HttpUtility.HtmlDecode(message.content)); //解码 string url = Applicate.MapApiUrl + "location={0},{1}&title={2}&content={3}&output=html"; //删除 string mapurl = string.Format(url, message.location_x, message.location_y, "我的位置", message.objectId); string uri = message.content; //get info about the path string localpath = Applicate.LocalConfigData.CatchPath; //ChatBubbleItemModel message = mapcontrol.Tag as ChatBubbleItemModel; string filename = message.fileName.Substring( message.fileName.LastIndexOf('/') + 1, message.fileName.Length - message.fileName.LastIndexOf('/') - 1 ); var localfile = localpath + filename; //获取缓存路径 if (File.Exists(localfile)) //if file exists, fill the image of the border { var imguri = new Uri(localfile); mapcontrol.MapImg.Source = new BitmapImage(imguri); mapcontrol.transitioner.SelectedIndex = 1; mapcontrol.MouseLeftButtonUp += (sen, res) => { Process.Start(mapurl); }; } else//if not exists { WebClient web = new WebClient(); //when the progress changed , set the value of the progressbar web.DownloadProgressChanged += (s, ev) => { mapcontrol.ImageProgress.Value = ev.ProgressPercentage; }; //When download completed, fill the image of the border web.DownloadFileCompleted += (s, ev) => { if (ev.Error == null) { var imguri = new Uri(localfile); mapcontrol.MapImg.Source = new BitmapImage(imguri); mapcontrol.transitioner.SelectedIndex = 1; mapcontrol.MouseLeftButtonUp += (sen, res) => { Process.Start(mapurl); }; web.Dispose();//Dispose the WebClient } else { ConsoleLog.Output("图片下载失败"); } }; //Start download image async web.DownloadFileAsync(new Uri(uri), localfile); } } catch (Exception ex) { ConsoleLog.Output("显示地址失败:" + ex.Message); } }