private async void Button_Clicked_2(object sender, EventArgs e) { if (photoFile3.Count == 0) { await DisplayAlert("警告", "请选择要现形的图片!", "确认"); return; } List <FileStream> photo3Stream = new List <FileStream>(); try { foreach (FileResult file in photoFile3) { photo3Stream.Add(new FileStream(file.FullPath, FileMode.Open)); } } catch (UnauthorizedAccessException) { await DisplayAlert("警告", "权限异常!", "确认"); photo3Stream.Clear(); return; } catch (FileNotFoundException) { await DisplayAlert("警告", "文件不存在!", "确认"); photo3Stream.Clear(); return; } foreach (SInsideFile insFile in insideFile) { insFile.File.Dispose(); } insideFile.Clear(); Image4.Source = null; ActivityIndicator1.IsRunning = true; Button1.IsEnabled = false; Button2.IsEnabled = false; await Task.Run(() => { foreach (FileStream fs in photo3Stream) { MemoryStream tempStream = LsbTank.Decode(fs, out string tempName); if (tempStream != null) { insideFile.Add(new SInsideFile(tempName, tempStream)); tempStream.Dispose(); } } }); LabelTips4.Text = ""; if (insideFile.Count == 0) { await DisplayAlert("警告", "这些图不是无影坦克!", "确认"); if (MimeUtility.GetMimeMapping(photoFile3[0].FileName) != MimeUtility.GetMimeMapping(".png")) { await DisplayAlert("警告", "如果确定这不是一张锤子图,请 *查看原图* 后 保存 再现形!", "确认"); } LabelFileName.Text = ""; } else if (insideFile.Count == 1) { string extension = insideFile[0].Name.Substring(insideFile[0].Name.LastIndexOf(".") + 1).ToLower(); if (extension == "png" || extension == "jpg" || extension == "jpeg" || extension == "bmp" || extension == "gif") { Image4.Source = ImageSource.FromStream(() => new MemoryStream(insideFile[0].File.ToArray())); } else { Image4.Source = ImageSource.FromResource("WarFactory.Resources.File.png"); } LabelFileName.Text = insideFile[0].Name; } else { Image4.Source = ImageSource.FromResource("WarFactory.Resources.Images.png"); LabelFileName.Text = "成功现形" + insideFile.Count.ToString() + "个文件,点击进入查看列表"; } Button1.IsEnabled = true; Button2.IsEnabled = true; ActivityIndicator1.IsRunning = false; foreach (FileStream ms in photo3Stream) { ms.Close(); } }
private async void Button_Clicked_1(object sender, EventArgs e) { if (photoFile1 == null || photoFile2 == null || photoFile1.Count == 0 || photoFile2.Count == 0) { await DisplayAlert("警告", "缺少图片!", "确认"); return; } foreach (FileResult pf1 in photoFile1) { foreach (FileResult pf2 in photoFile2) { if (pf1.FullPath == pf2.FullPath) { await DisplayAlert("警告", "里图不能与表图重复!", "确认"); return; } } } foreach (SInsideFile insFile in insideFile) { insFile.File.Dispose(); } insideFile.Clear(); LabelFileName.Text = ""; Image4.Source = null; ActivityIndicator1.IsRunning = true; Button1.IsEnabled = false; Button2.IsEnabled = false; if (compression >= 6) { await DisplayAlert("警告", "支持压缩度大于等于6的无影坦克的网站很少,很有可能只有本APP能够现形,并且十分不稳定,请酌情考虑是否保存!", "确认"); } string fileName = "Tank_" + DateTime.Now.ToLocalTime().ToString("yyyyMMdd_HHmmss"); int photoIndex = 0; if ((string.IsNullOrEmpty(info) || string.IsNullOrWhiteSpace(info)) && photoFile2.Count == 1) { info = "TK"; } await Task.Run(() => { foreach (FileResult fr in photoFile2) { photoIndex++; MemoryStream tempStream = LsbTank.Encode(new FileStream(photoFile1[photoIndex % photoFile1.Count].FullPath, FileMode.Open), new FileStream(fr.FullPath, FileMode.Open), info + (photoFile2.Count == 1 ? "" : photoIndex.ToString()), compression); if (tempStream != null) { insideFile.Add(new SInsideFile(fileName + "_" + photoIndex.ToString() + ".png", tempStream)); tempStream.Dispose(); } } }); LabelTips4.Text = ""; if (insideFile.Count == 1) { Image4.Source = ImageSource.FromStream(() => new MemoryStream(insideFile[0].File.ToArray())); LabelFileName.Text = "成功生成!发送时记得原图发送并且关闭水印!"; } else { Image4.Source = ImageSource.FromResource("WarFactory.Resources.Images.png"); LabelFileName.Text = "成功生成" + insideFile.Count.ToString() + "个文件,点击进入查看列表"; } if (DeviceInfo.Platform == DevicePlatform.iOS) { await DisplayAlert("警告", "iOS设备似乎即使发送原图也会被压缩,这也就注定了iOS发出去的坦克图全是锤子,因此请谨慎发图!", "确认"); } Button1.IsEnabled = true; Button2.IsEnabled = true; ActivityIndicator1.IsRunning = false; }