private void SaveSelectedImage() { if ((this.bestPicListView.Items.Count <= 0) || (this.bestPicListView.FocusedItem == null)) { return; } ImagePair ip = this.bestPicListView.FocusedItem.Tag as ImagePair; ImageDetail imgInfo = ImageDetail.FromPath(ip.FacePath); string bigImgPath = ip.BigImagePath; using (SaveFileDialog saveDialog = new SaveFileDialog()) { saveDialog.RestoreDirectory = true; saveDialog.Filter = "Jpeg 文件|*.jpg"; //saveDialog.FileName = filePath.Substring(filePath.Length - 27, 27); string fileName = Path.GetFileName(ip.FacePath); saveDialog.FileName = fileName; if (saveDialog.ShowDialog() == DialogResult.OK) { if (pictureBoxFace.Image != null) { string path = saveDialog.FileName; pictureBoxFace.Image.Save(path); path = path.Replace(fileName, Path.GetFileName(bigImgPath)); pictureBoxWholeImg.Image.Save(path); } } } }
// /Chat/SendMessage public ActionResult SendMessage(string chatPk, string collocutorPk, string text, HttpPostedFileBase file) { var serializer = new JavaScriptSerializer(); var chatPkString = string.IsNullOrEmpty(chatPk) ? string.Empty : serializer.Deserialize <string>(chatPk); var textString = string.IsNullOrEmpty(text) ? string.Empty : serializer.Deserialize <string>(text); var collocutorPkString = string.IsNullOrEmpty(collocutorPk) ? string.Empty : serializer.Deserialize <string>(collocutorPk); ImagePair imagePair = null; if (file != null) { imagePair = SaveFile(file); if (imagePair == null) { return(Json(new { IsSuccess = false })); } } Guid chatPkGuid; Guid.TryParse(chatPkString, out chatPkGuid); var saveResult = _message.SaveMessage(chatPkGuid, textString, imagePair); if (!saveResult.IsSuccess) { return(Json(new { IsSuccess = false })); } HubClient.SendChatMessage(collocutorPkString, textString, imagePair?.Small, imagePair?.Large); return(Json(new { IsSuccess = true })); }
public OperationResult <string> SaveMessage(Guid chatPk, string text, ImagePair attachment) { try { var chat = _chats.GetSingleOrDefault(x => x.PublicKey == chatPk); if (chat == null) { return(new OperationResult <string>(new Exception("SaveMessage: Chat with Pk-" + chatPk + " does not found"))); } _chatMessages.Add(new ChatMessages { AttachmentMin = attachment?.Small, AttachmentMax = attachment?.Large, BelongToChat = chat.ID, Created = DateTime.Now, IsNew = true, Message = text, PublicKey = Guid.NewGuid() }); chat.IsBidirectional = true; _chats.UnitOfWork.Commit(); _chatMessages.UnitOfWork.Commit(); return(new OperationResult <string>()); } catch (Exception ex) { return(new OperationResult <string>(ex)); } }
/// <summary> /// Composes an icon from image data with the size of 16x16 /// </summary> public static Image GetComposedBitmapSize16(string data, bool autoAdjusted) { if (Size == Size16) { return(GetComposedBitmap(data, autoAdjusted)); } string key = Components.Parse(data, Size16).Key; if (!Cache.ContainsKey(key)) { var image32 = GetComposedBitmap(data, false); int size = ScaleHelper.Scale(Size16); var image16 = new Bitmap(size, size); using (var graphics = Graphics.FromImage(image16)) { graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.DrawImage(image32, 0, 0, image16.Width, image16.Height); } Cache[key] = new ImagePair(image16); } if (autoAdjusted) { var imagePair = Cache[key]; return(imagePair.Adjusted ?? AddAutoAdjustImage(imagePair)); } return(Cache[key].Original); }
/// <summary> /// Adds a pair to the update list. /// </summary> static Image AddAutoAdjustImage(ImagePair pair) { if (!AutoAdjusted.Contains(pair)) { AutoAdjusted.Add(pair); } return(pair.Adjusted = SetImageAdjustment(pair.Original)); }
public void OnTangoImageAvailableEventHandler(TangoEnums.TangoCameraId cameraId, TangoUnityImageData imageBuffer) { if (imageIsRecording) { ImagePair ip = new ImagePair(cameraId, imageBuffer); image_queue.Enqueue(ip); } }
/// <summary> /// 将当前实例包含的图像文件的集合转换为 <see cref="ImagePair"/> 的数组。 /// </summary> /// <returns>转换得到的 <see cref="ImagePair"/> 的数组</returns> public ImagePair[] ToImagePairs() { var sourceFiles = this.SourceFiles; var compareFiles = this.CompareFiles; var length = Math.Min(sourceFiles.Count, compareFiles.Count); var imagePairs = new ImagePair[length]; for (int i = 0; i < length; i++) { imagePairs[i] = new ImagePair(sourceFiles[i], compareFiles[i]); } return(imagePairs); }
public void AddFace(ImagePair pair) { this.faceImageList.Images.Add(pair.Face); string text = System.IO.Path.GetFileName(pair.FacePath); ListViewItem item = new ListViewItem { Tag = pair, Text = text, ImageIndex = this.faceImageList.Images.Count - 1, }; this.facesListView.Items.Add(item); }
public ImagePair[] FacesCapturedAt(int cameraID, DateTime time) { string[] files = ImageSearch.FacesCapturedAt(time, cameraID, true); ImagePair[] bmps = new ImagePair[files.Length]; for (int i = 0; i < files.Length; i++) { ImagePair ip = new ImagePair(); ip.Face = (Bitmap)Bitmap.FromFile(files[i]); ip.FacePath = files[i]; bmps[i] = ip; } return(bmps); }
private void toolStripButtonPlayVideo_Click(object sender, EventArgs e) { if (SearchProxy == null) { return; } if (this.bestPicListView.SelectedItems.Count != 1) { return; } ImagePair ip = this.bestPicListView.SelectedItems[0].Tag as ImagePair; ImageDetail imgInfo = ImageDetail.FromPath(ip.FacePath); string video = null; try { video = SearchProxy.VideoFilePathRecordedAt(imgInfo.CaptureTime, imgInfo.FromCamera); } catch (System.ServiceModel.CommunicationException) { MessageBox.Show("通讯错误, 请重试"); IChannel ch = SearchProxy as IChannel; if (ch.State == CommunicationState.Faulted) { this.CreateProxy(); } return; } if (string.IsNullOrEmpty(video)) { MessageBox.Show("未找到相关视频"); return; } this.ReceiveVideoStream(); StreamProxy.StreamVideo(video); isPlaying = true; }
public ImagePair GetFace(string path) { Bitmap face = (Bitmap)Damany.Util.Extensions.MiscHelper.FromFileBuffered(path); string bigImgPath = new FileSystemStorage(Properties.Settings.Default.OutputPath).BigImgPathForFace(Core.ImageDetail.FromPath(path)); Bitmap big = (Bitmap)Damany.Util.Extensions.MiscHelper.FromFileBuffered(bigImgPath); ImagePair ip = new ImagePair(); ip.Face = face; ip.FacePath = path; ip.BigImage = big; ip.BigImagePath = bigImgPath; return(ip); }
public ImagePair GetFace(string path) { Bitmap face = (Bitmap)Image.FromFile(path); string bigImgPath = FileSystemStorage.BigImgPathForFace(Core.ImageDetail.FromPath(path)); Bitmap big = (Bitmap)Image.FromFile(bigImgPath); ImagePair ip = new ImagePair(); ip.Face = face; ip.FacePath = path; ip.BigImage = big; ip.BigImagePath = bigImgPath; return(ip); }
void save_image_task() { if (image_queue.Count > 0) { ImagePair ip = image_queue.Peek(); // Not a new image if (ip.imageBuffer.timestamp == last_timestamp) { return; } last_timestamp = ip.imageBuffer.timestamp; saveImage(ip.imageBuffer, ip.cameraName); image_queue.Dequeue(); } }
/// <summary> /// Composes an icon from image data. /// </summary> public static Image GetComposedBitmap(string data, bool autoAdjusted) { var c = Components.Parse(data); string key = c.Key; if (!Cache.ContainsKey(key)) { var original = new Bitmap(Size, Size); var srcRect = new Rectangle(0, 0, Size, Size); var destRect = new Rectangle(Padding, Padding, Size - (Padding * 2), Size - (Padding * 2)); using (var graphics = Graphics.FromImage(original)) { graphics.Clear(Color.Transparent); if (c.Icon >= 0) { srcRect.X = (c.Icon % Size16) * Size; srcRect.Y = (c.Icon / Size16) * Size; graphics.DrawImage(Source, destRect, srcRect, GraphicsUnit.Pixel); } if (c.Bullet >= 0) { srcRect.X = (c.Bullet % Size16) * Size; srcRect.Y = (c.Bullet / Size16) * Size; destRect.X += (Size == Size32) ? c.X * 2 : c.X; destRect.Y += (Size == Size32) ? c.Y * 2 : c.Y; graphics.DrawImage(Source, destRect, srcRect, GraphicsUnit.Pixel); } } original = ScaleHelper.Scale(original); Cache[key] = new ImagePair(original); } if (autoAdjusted) { var imagePair = Cache[key]; return imagePair.Adjusted ?? AddAutoAdjustImage(imagePair); } return Cache[key].Original; }
/// <summary> /// Composes an icon from image data. /// </summary> public static Image GetComposedBitmap(string data, bool autoAdjusted) { var c = Components.Parse(data); string key = c.Key; if (!Cache.ContainsKey(key)) { var original = new Bitmap(Size, Size); var srcRect = new Rectangle(0, 0, Size, Size); var destRect = new Rectangle(Padding, Padding, Size - (Padding * 2), Size - (Padding * 2)); using (var graphics = Graphics.FromImage(original)) { graphics.Clear(Color.Transparent); if (c.Icon >= 0) { srcRect.X = (c.Icon % Size16) * Size; srcRect.Y = (c.Icon / Size16) * Size; graphics.DrawImage(Source, destRect, srcRect, GraphicsUnit.Pixel); } if (c.Bullet >= 0) { srcRect.X = (c.Bullet % Size16) * Size; srcRect.Y = (c.Bullet / Size16) * Size; destRect.X += (Size == Size32) ? c.X * 2 : c.X; destRect.Y += (Size == Size32) ? c.Y * 2 : c.Y; graphics.DrawImage(Source, destRect, srcRect, GraphicsUnit.Pixel); } } original = ScaleHelper.Scale(original); Cache[key] = new ImagePair(original); } if (autoAdjusted) { var imagePair = Cache[key]; return(imagePair.Adjusted ?? AddAutoAdjustImage(imagePair)); } return(Cache[key].Original); }
//以前 //02_090702150918-0001.jpg -->大图片 //02_090702152518-0006-0000.jpg--> 小图片 //现在 //02_090807144104343.jpg-->大图片 //02_090807144104343-0000.jpg-->小图片 private void bestPicListView_ItemActivate(object sender, System.EventArgs e) { ImagePair ip = this.bestPicListView.FocusedItem.Tag as ImagePair; this.pictureBoxFace.Image = ip.Face; //detail infomation ImageDetail imgInfo = ImageDetail.FromPath(ip.FacePath); string captureLoc = string.Format("抓拍地点: {0}", imgInfo.FromCamera); this.labelCaptureLoc.Text = captureLoc; string captureTime = string.Format("抓拍时间: {0}", imgInfo.CaptureTime); this.labelCaptureTime.Text = captureTime; this.pictureBoxWholeImg.Image = ip.BigImage; }
void ShowCurrentPage() { bestPicListView.BeginUpdate(); ClearCurPageList(); for (int i = (currentPage - 1) * PageSize; (i < currentPage * PageSize) && (i < imagesFound.Length); ++i) { ImagePair ip = null; try { ip = SearchProxy.GetFace(imagesFound[i]); } catch (System.ServiceModel.CommunicationException) { MessageBox.Show("通讯错误, 请重试"); IChannel ch = SearchProxy as IChannel; if (ch.State == CommunicationState.Faulted) { this.CreateProxy(); } break; } this.imageList1.Images.Add(ip.Face); string text = System.IO.Path.GetFileName(ip.FacePath as string); ListViewItem item = new ListViewItem() { Tag = ip, Text = text, ImageIndex = i % PageSize }; this.bestPicListView.Items.Add(item); } bestPicListView.EndUpdate(); }
private ImagePair SaveFile(HttpPostedFileBase file) { ImagePair imagePair = null; var imgMax = Image.FromStream(file.InputStream); var attachMaxPath = @"\Storage\Chat\" + Guid.NewGuid() + ".png"; var resMax = ImgHandler.SaveImage(imgMax, Server.MapPath("~") + attachMaxPath); var imgMini = ImgHandler.CreateMiniImage(imgMax, 128, 128); var attachMinPath = @"\Storage\Chat\" + Guid.NewGuid() + ".png"; var resMin = ImgHandler.SaveImage(imgMini, Server.MapPath("~") + attachMinPath); if (resMax && resMin) { imagePair = new ImagePair { Small = attachMinPath, Large = attachMaxPath } } ; return(imagePair); } }
public OperationResult <ImagePair> RemovePortfolioJobImage(Guid userPk, Guid jobPk, Guid imagePk) { try { var user = _users.GetSingleOrDefault(x => x.PublicKey == userPk); if (user == null) { return(new OperationResult <ImagePair>(new Exception("[ImpPortfolios]/[RemovePortfolioJobImage] User with Pk:" + userPk + " doesnt found."))); } var portfolio = _portfolios.GetSingleOrDefault(x => x.BelongsToUser == user.ID); if (portfolio == null) { return(new OperationResult <ImagePair>(new Exception("[ImpPortfolios]/[RemovePortfolioJobImage]: portfolio does not found"))); } var job = _portfolioJobs.GetSingleOrDefault(x => x.PublicKey == jobPk && x.BelongsToPortfolio == portfolio.ID); if (job == null) { return(new OperationResult <ImagePair>(new Exception("[ImpPortfolios]/[RemovePortfolioJobImage]: job does not found"))); } var result = new ImagePair(); var image = _portfolioJobImages.GetSingleOrDefault(x => x.BelongsToPortfolioJob == job.ID && x.PublicKey == imagePk); if (image != null) { result.Small = image.Small; result.Large = image.Large; _portfolioJobImages.Remove(image); _portfolioJobImages.UnitOfWork.Commit(); } return(new OperationResult <ImagePair>(result)); } catch (Exception ex) { return(new OperationResult <ImagePair>(ex)); } }
/// <summary> /// Adds a pair to the update list. /// </summary> static Image AddAutoAdjustImage(ImagePair pair) { if (!AutoAdjusted.Contains(pair)) AutoAdjusted.Add(pair); return pair.Adjusted = SetImageAdjustment(pair.Original); }
/// <summary> /// Composes an icon from image data with the size of 16x16 /// </summary> public static Image GetComposedBitmapSize16(string data, bool autoAdjusted) { if (Size == Size16) return GetComposedBitmap(data, autoAdjusted); string key = Components.Parse(data, Size16).Key; if (!Cache.ContainsKey(key)) { var image32 = GetComposedBitmap(data, false); int size = ScaleHelper.Scale(Size16); var image16 = new Bitmap(size, size); using (var graphics = Graphics.FromImage(image16)) { graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.DrawImage(image32, 0, 0, image16.Width, image16.Height); } Cache[key] = new ImagePair(image16); } if (autoAdjusted) { var imagePair = Cache[key]; return imagePair.Adjusted ?? AddAutoAdjustImage(imagePair); } return Cache[key].Original; }
/// <summary> /// 向 <see cref="ImagePair"/> 集合中添加指定的新项目。 /// </summary> /// <param name="imagePair">要添加到集合的 <see cref="ImagePair"/>。</param> public void AddImagePair(ImagePair imagePair) { this.ImagePairs.Add(imagePair); }
/// <summary> /// 从 <see cref="ImagePair"/> 集合中删除指定的项目。 /// </summary> /// <param name="imagePair">要删除的项目。</param> public void DeleteImagePair(ImagePair imagePair) { this.ImagePairs.Remove(imagePair); imagePair.Dispose(); }
private void PopulateQuestionList() { csvFile = new TextAsset(); csvFile = Resources.Load <TextAsset>(SessionInfoCSVFileName); StringReader reader = new StringReader(csvFile.text); string line = reader.ReadLine(); while (line != null) { string[] valuesInString = line.Split(','); int difficulty = int.Parse(valuesInString[4]); int numImages = int.Parse(valuesInString[0]); string[] imageFiles = new string[numImages]; string[] choices = new string[numChoices]; int choiceIndex = 0; string[] notAnswers; if (difficulty == 0) { notAnswers = new string[numImages - 1]; } else { notAnswers = new string[numImages - 2]; } int notAnswerIndex = 0; bool answerUsed = false; int curIndex = 1; // Index in valuesInString string answerFileName = ""; // Populate imageFiles for (int imageFilesIndex = 0; imageFilesIndex < numImages; ++imageFilesIndex) { if (valuesInString[curIndex] == "" || curIndex > 3) { string filename = returnPlaceHolder(); imageFiles[imageFilesIndex] = filename; if (difficulty == 0 && !answerUsed) { choices[choiceIndex] = filename; answerFileName = filename; choiceIndex++; answerUsed = true; } else { notAnswers[notAnswerIndex] = filename; notAnswerIndex++; } } else { ImagePair tempImagePair = returnImagePair(int.Parse(valuesInString[curIndex])); imageFiles[imageFilesIndex] = tempImagePair.image1; imageFilesIndex++; imageFiles[imageFilesIndex] = tempImagePair.image2; if (difficulty == int.Parse(valuesInString[curIndex]) && !answerUsed) { choices[choiceIndex] = tempImagePair.image1; choices[choiceIndex + 1] = tempImagePair.image2; answerFileName = tempImagePair.image1; choiceIndex += 2; answerUsed = true; } else { notAnswers[notAnswerIndex] = tempImagePair.image1; notAnswers[notAnswerIndex + 1] = tempImagePair.image2; notAnswerIndex += 2; } } curIndex += 1; } notAnswers = StringShuffle(notAnswers, notAnswerIndex); for (int i = choiceIndex; i < numChoices; ++i) { choices[i] = notAnswers[i - choiceIndex]; } choices = StringShuffle(choices, numChoices); imageFiles = StringShuffle(imageFiles, numImages); QuestionList.Add(new MemorizationQuestion(imageFiles, choices, answerFileName, numImages, difficulty)); line = reader.ReadLine(); } reader.Close(); }