/// <summary> /// Saves the provided image with the specified dimensions and then adds references to the results in the persistance store. /// Then the image object is disposed, and an image entity is returned. /// </summary> public Picture Persist(Image image, PictureSize size = PictureSize.All) { throw new NotImplementedException(); Ensure.That(() => image).IsNotNull(); if (size == PictureSize.None) { return null; } Picture picture = null; // pictureRepository.Create(); string filename = fsHelper.GenerateRandomFilenameFormat(); using (image) { foreach (KeyValuePair<PictureSize, Action<Picture, string>> option in GetResizeOptions()) { if (size.HasFlag(option.Key)) { int max = option.Key.GetAttribute<PicturePixelsAttribute>().Pixels; option.Value(picture, SizeAndSaveImage(filename, image, max)); } } return picture; } }
public async Task<string> GetProfilePictureAsync(PictureSize size = PictureSize.Medium) { var response = await Execute(() => RequestGenerator.GetProfilePicture(size), _clientContentNoRedirection).ConfigureAwait(false); var locationHeader = response.Headers.Location; if (locationHeader != null) return locationHeader.AbsoluteUri; return null; }
/// <summary>画像ダウンロード用ストリームの取得</summary> public Task<WebResponse> GetStreamAsync(PictureSize PictureSize = PictureSize.None) { var request = (HttpWebRequest)WebRequest.Create(Url + PictureSize.ToKey()); request.Method = ContentMethod.Get; request.CookieContainer = cookieContainer; return request.GetResponseAsync(); }
public bool HasPicture(PictureSize aSize) { switch (aSize) { case PictureSize.SMALL: { return string.IsNullOrEmpty(GetImage(SmallPicture, SmallCover)); } case PictureSize.MEDIUM: { return string.IsNullOrEmpty(GetImage(MediumPicture, MediumCover)); } case PictureSize.LARGE: { return string.IsNullOrEmpty(GetImage(LargePicture, LargeCover)); } default: { return false; } } }
public string GetPicture(PictureSize aSize) { switch (aSize) { case PictureSize.SMALL: { return GetImage(SmallPicture, SmallCover); } case PictureSize.MEDIUM: { return GetImage(MediumPicture, MediumCover); } case PictureSize.LARGE: { return GetImage(LargePicture, LargeCover); } default: { return string.Empty; } } }
public static void CreateThumbPicture(string sourcePath, string thumbPath, PictureSize pictureSize) { var fileExtension = Path.GetExtension(sourcePath); if (!File.Exists(sourcePath)) return; using (var b = new Bitmap(sourcePath)) { var targetSize = 0; switch (pictureSize) { case PictureSize.Tiny: targetSize = 50; break; case PictureSize.Small: targetSize = 100; break; case PictureSize.Medium: targetSize = 150; break; case PictureSize.Large: targetSize = 250; break; } var newSize = CalculateDimensions(b.Size, targetSize); if (newSize.Width < 1) newSize.Width = 1; if (newSize.Height < 1) newSize.Height = 1; //temp //_mediaSettings.DefaultImageQuality = 80; using (var newBitMap = new Bitmap(newSize.Width, newSize.Height)) { using (var g = Graphics.FromImage(newBitMap)) { int DefaultImageQuality = 80; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.DrawImage(b, 0, 0, newSize.Width, newSize.Height); var ep = new EncoderParameters(); ep.Param[0] = new EncoderParameter(Encoder.Quality, DefaultImageQuality); ImageCodecInfo ici = GetImageCodecInfoFromExtension(fileExtension); if (ici == null) ici = GetImageCodecInfoFromMimeType("image/jpeg"); newBitMap.Save(thumbPath, ici, ep); } } } }
public void AddPicture(Uri pictureUri, PictureSize size) { var newPic = new Picture(HandleEvent); newPic.HandleEvent(new PictureAddedToAdvertisement { PictureId = new Guid(), ClassifiedAdId = Id, Url = pictureUri.ToString(), Height = size.Height, Width = size.Width }); Pictures.Add(newPic); }
public async Task <string> MakePhoto() { var filePath = $"{Guid.NewGuid()}.jpg"; var cameras = Cameras.DeclareDevice() .Named("Camera 1") .WithDevicePath("/dev/video0") .Memorize(); var camera = cameras.Get("Camera 1"); var pictureSize = new PictureSize(1280, 720); camera.SavePicture(pictureSize, filePath, 0); return(filePath); }
/// <summary> /// Get picture URL by Picture id /// </summary> /// <param name="pictureId"></param> /// <param name="pictureType"></param> /// <param name="pictureSize"></param> /// <returns></returns> public string GetPictureUrl(long pictureId, PictureType pictureType, PictureSize pictureSize) { var picture = GetByPictureId(pictureId); if (picture == null) { return(null); } var fileName = picture.FileName; var thumbFileUrl = GetPictureUrl(fileName, pictureType, pictureSize); return(thumbFileUrl); }
protected override void SetStateByEvent(IEvent @event) { switch (@event) { case PictureAddedToAdvertisment e: Id = e.PictureId; Location = PictureUrl.FromString(e.Url); Size = new PictureSize(e.Height, e.Width); Order = e.Order; break; case AdvertismentPictureResized e: Size = new PictureSize(e.Height, e.Width); break; } }
public static Image GetImage(string pictureId, PictureSize size) { var def = new PictureDefinition(pictureId, size); if (!cache.ContainsKey(def)) { (var isDefault, var bytes) = PictureStorage.GetPicture(def); var image = ImageReader.ToImage(bytes); if (isDefault) { return(image); } cache[def] = image; } return(cache[def]); }
public string FileName(PictureSize size) { // check if we have converted files //if (IsConverted) //{ switch (AngelType) { case RotationAngle.Rotated0: return(string.Format(tblPicture.convertedFilename, (int)size)); break; case RotationAngle.Rotated90: if (!string.IsNullOrWhiteSpace(tblPicture.convertedFilename90)) { return(string.Format(tblPicture.convertedFilename90, (int)size)); } break; case RotationAngle.Rotated180: if (!string.IsNullOrWhiteSpace(tblPicture.convertedFilename180)) { return(string.Format(tblPicture.convertedFilename180, (int)size)); } break; case RotationAngle.Rotated270: if (!string.IsNullOrWhiteSpace(tblPicture.convertedFilename270)) { return(string.Format(tblPicture.convertedFilename270, (int)size)); } break; } return(""); //} //else //{ // if (tblPicture.originalFilepath.StartsWith("http:", StringComparison.InvariantCultureIgnoreCase)) // { // return Path.GetFileName(tblPicture.originalFilepath); // } // return tblPicture.originalFilepath; //} }
public ButtonDecoration() { TextAlignment = new TextAlignment { Horizontal = HorizontalTextAlignment.Center, Vertical = VerticalTextAlignment.Center, }; BackgroundColor = new AutoColor(); TextColor = new AutoColor(); BorderColor = new AutoColor(); TextFont = new AutoFont(); PicturePosition = ButtonPicturePosition.Left; Picture = new EmptyPicture(); PictureSize = PictureSize.AutoSize; }
/// <summary> /// 选择显示不同大小的图片 /// </summary> /// <param name="originalPath">原图路径</param> /// <param name="nullPath">null</param> /// <param name="size">图片尺寸:大large,中middle,小small</param> /// <returns></returns> public static string ShowPicture(string originalPath, string nullPath, PictureSize size) { string path = originalPath == "" ? nullPath : originalPath; switch (Convert.ToInt32(size)) { case 1: path = path.Insert(path.LastIndexOf('.'), "mid"); break; case 0: path = path.Insert(path.LastIndexOf('.'), "small"); break; default: break; } return(path); }
/// <summary> /// The crop adjust. /// </summary> private void CropAdjust() { PictureSize.AnamorphicResult result = PictureSize.hb_set_anamorphic_size(this.GetPictureSettings(), this.GetPictureTitleInfo()); switch (this.SelectedAnamorphicMode) { case Anamorphic.None: // this.Width = result.OutputWidth; // this.Height = result.OutputHeight; break; case Anamorphic.Strict: case Anamorphic.Loose: case Anamorphic.Custom: double dispWidth = Math.Round((result.OutputWidth * result.OutputParWidth / result.OutputParHeight), 0); this.DisplaySize = this.sourceResolution.IsEmpty ? string.Empty : string.Format("Storage: {0}x{1}, Display: {2}x{3}", result.OutputWidth, result.OutputHeight, dispWidth, result.OutputHeight); break; } }
public void test_resize_picture() { var added = new PictureAdded( Guid.NewGuid(), Guid.NewGuid(), new Uri("https://google.com.tw").ToString(), 800, 600, 1); _picture.Handle(added); var resize = new PictureSize(801, 601); //When _picture.Handle(new PictureResized(Guid.NewGuid(), resize.Height, resize.Width)); //Then Assert.Equal(resize.Width, _picture.Size.Width); Assert.Equal(resize.Height, _picture.Size.Height); }
/// <summary> /// Set the display size text /// </summary> private void SetDisplaySize() { /* * Handle Anamorphic Display */ if (this.SelectedAnamorphicMode != Anamorphic.None) { PictureSize.AnamorphicResult result = PictureSize.hb_set_anamorphic_size(this.GetPictureSettings(), this.GetPictureTitleInfo()); double dispWidth = Math.Round((result.OutputWidth * result.OutputParWidth / result.OutputParHeight), 0); this.DisplaySize = this.sourceResolution.IsEmpty ? string.Format(Properties.Resources.PictureSettings_OutputResolution, "None") : string.Format("Output: {0}x{1}, Anamorphic: {2}x{3}", result.OutputWidth, result.OutputHeight, dispWidth, result.OutputHeight); } else { this.DisplaySize = this.sourceResolution.IsEmpty ? string.Empty : string.Format("Output: {0}x{1}", this.Width, this.Height); } }
private void ResizePicture(EventMetadataVm eventMetaVm, PictureSize size) { FileUtil.ResizePicture(eventMetaVm, size, _imageProfileManager, Logger); FileUtil.ResizePicture(eventMetaVm.Host, size, _imageProfileManager, Logger); if (eventMetaVm.Venues == null) { return; } foreach (var venueVm in eventMetaVm.Venues) { FileUtil.ResizePicture(venueVm, PictureSize.Small, _imageProfileManager, Logger); if (venueVm.Shows == null) { continue; } foreach (var showVm in venueVm.Shows) { FileUtil.ResizePicture(showVm, PictureSize.Small, _imageProfileManager, Logger); } } }
protected override void When(object @event) { switch (@event) { case Events.PictureAddedToAClassifiedAd e: Id = new PictureId(e.PictureId); Location = new Uri(e.Url); Size = new PictureSize { Height = e.Height, Width = e.Width }; Order = e.Order; break; case Events.ClassifiedAdPictureResized e: Size = new PictureSize { Height = e.Height, Width = e.Width, }; break; } }
public string FileName(PictureSize size) { // check if we have converted files //if (IsConverted) //{ switch (AngelType) { case RotationAngle.Rotated0: return(string.Format(tblPicture.convertedFilename, (int)size)); break; case RotationAngle.Rotated90: if (!string.IsNullOrWhiteSpace(tblPicture.convertedFilename90)) { return(string.Format(tblPicture.convertedFilename90, (int)size)); } break; case RotationAngle.Rotated180: if (!string.IsNullOrWhiteSpace(tblPicture.convertedFilename180)) { return(string.Format(tblPicture.convertedFilename180, (int)size)); } break; case RotationAngle.Rotated270: if (!string.IsNullOrWhiteSpace(tblPicture.convertedFilename270)) { return(string.Format(tblPicture.convertedFilename270, (int)size)); } break; } return(""); }
private static byte[] getDefaultImage(PictureSize size) => defaultImages.ContainsKey(size) ? defaultImages[size] : new byte[0];
public static void SetDefaultImage(PictureSize pictureSize, byte[] bytes) => defaultImages[pictureSize] = bytes;
public virtual bool HasPicture(PictureSize aSize) => !string.IsNullOrEmpty(GetPicture(aSize));
public override bool HasPicture(PictureSize aSize) { bool baseResult = base.HasPicture(aSize); return((baseResult) ? baseResult : AlbumInternal.HasPicture(aSize)); }
//Tracks don't often come with their own images so if there is none, we can use that from the album in which it belongs. public override string GetPicture(PictureSize aSize) { string url = base.GetPicture(aSize); return((url == string.Empty) ? AlbumInternal.GetPicture(aSize) : url); }
public static MvcHtmlString GalleryPicture(this HtmlHelper helper, Gallery gallery, PictureSize size) { if (string.IsNullOrEmpty(gallery.DefaultPhoto)) { return(MvcHtmlString.Empty); } var url = new UrlHelper(helper.ViewContext.RequestContext); return(MvcHtmlString.Create(string.Format("<img width='200' src='{0}{3}/{4}/{2}' title='{1}'/>", url.Content("~/public/userfiles/galleries/"), gallery.Title, gallery.DefaultPhoto, size, gallery.Id))); }
public string GetFilePath(PictureSize size) { return SetFileName(size); }
public Image GetImage(InventoryType type, PictureSize size) { if (!PictureExists(type, size)) return null; return Image.FromStream(GetTargetFile(type, size).OpenRead()); }
/// <summary> /// Get pictureURL by RefId /// </summary> /// <param name="refId"></param> /// <param name="pictureType"></param> /// <param name="pictureSize"></param> /// <returns></returns> public IEnumerable <string> GetPictureUrlsByRef(long refId, PictureType pictureType, PictureSize pictureSize = PictureSize.Auto) { var pictures = GetByRef(refId, pictureType.ToString()); List <string> pictureURLs = new List <string>(); foreach (var picture in pictures) { var pictureUrl = GetPictureUrl(picture.Id, pictureType, pictureSize); pictureURLs.Add(pictureUrl); } return(pictureURLs); }
public static string FullPathPicture(string fileName, PictureType pictureType, PictureSize pictureSize) { var path = "~/Images/" + pictureType + "/" + pictureSize + "/" + fileName; return path; }
public string GetFilePath(PictureSize size) { // check if we have converted files return(FileName(size)); }
private string GetTargetFileName(InventoryType type, PictureSize size) { return string.Format("{0}_{1}.{2}", type.Id, size, EveStaticPicturesExtension); }
public PictureDefinition(string pictureId, PictureSize pictureSize) { PictureId = pictureId; Size = pictureSize; }
public string SetFileName(PictureSize size) { switch (AngelType) { case RotationAngle.Rotated0: return string.Format(File.ConvertedFilename, (int)size); case RotationAngle.Rotated90: if (!string.IsNullOrWhiteSpace(File.ConvertedFilename90Degree)) return string.Format(File.ConvertedFilename90Degree, (int)size); break; case RotationAngle.Rotated180: if (!string.IsNullOrWhiteSpace(File.ConvertedFilename180Degree)) return string.Format(File.ConvertedFilename180Degree, (int)size); break; case RotationAngle.Rotated270: if (!string.IsNullOrWhiteSpace(File.ConvertedFilename270Degree)) return string.Format(File.ConvertedFilename270Degree, (int)size); break; } return ""; }
/// <summary> /// Recalculate the picture settings when the user changes a particular field defined in the ChangedPictureField enum. /// The properties in this class are dumb. They simply call this method if there is a change. /// It is the job of this method to update all affected private fields and raise change notifications. /// </summary> /// <param name="changedField"> /// The changed field. /// </param> private void RecaulcatePictureSettingsProperties(ChangedPictureField changedField) { // Sanity Check if (this.currentTitle == null) { return; } // Step 1, Update what controls are visible. this.UpdateVisibileControls(); // Step 2, Set sensible defaults if (changedField == ChangedPictureField.Anamorphic && (this.SelectedAnamorphicMode == Anamorphic.None || this.SelectedAnamorphicMode == Anamorphic.Loose)) { this.Task.Width = this.sourceResolution.Width > this.MaxWidth ? this.MaxWidth : this.sourceResolution.Width; this.Task.KeepDisplayAspect = true; } // Choose which setting to keep. PictureSize.KeepSetting setting = PictureSize.KeepSetting.HB_KEEP_WIDTH; switch (changedField) { case ChangedPictureField.Width: setting = PictureSize.KeepSetting.HB_KEEP_WIDTH; break; case ChangedPictureField.Height: setting = PictureSize.KeepSetting.HB_KEEP_HEIGHT; break; } // Step 2, For the changed field, call hb_set_anamorphic_size and process the results. PictureSize.AnamorphicResult result = PictureSize.hb_set_anamorphic_size2(this.GetPictureSettings(changedField), this.GetPictureTitleInfo(), setting); double dispWidth = Math.Round((result.OutputWidth * result.OutputParWidth / result.OutputParHeight), 0); this.Task.Width = result.OutputWidth; this.Task.Height = result.OutputHeight; long x, y; HandBrakeUtils.Reduce((int)Math.Round(result.OutputParWidth, 0), (int)Math.Round(result.OutputParHeight, 0), out x, out y); this.Task.PixelAspectX = (int)Math.Round(result.OutputParWidth, 0); this.Task.PixelAspectY = (int)Math.Round(result.OutputParHeight, 0); this.Task.DisplayWidth = dispWidth; // Step 3, Set the display width label to indicate the output. this.DisplaySize = this.sourceResolution == null || this.sourceResolution.IsEmpty ? string.Empty : string.Format(Resources.PictureSettingsViewModel_StorageDisplayLabel, dispWidth, result.OutputHeight, this.ParWidth, this.ParHeight); // Step 4, Force an update on all the UI elements. this.NotifyOfPropertyChange(() => this.Width); this.NotifyOfPropertyChange(() => this.Height); this.NotifyOfPropertyChange(() => this.DisplayWidth); this.NotifyOfPropertyChange(() => this.ParWidth); this.NotifyOfPropertyChange(() => this.ParHeight); this.NotifyOfPropertyChange(() => this.CropTop); this.NotifyOfPropertyChange(() => this.CropBottom); this.NotifyOfPropertyChange(() => this.CropLeft); this.NotifyOfPropertyChange(() => this.CropRight); this.NotifyOfPropertyChange(() => this.SelectedModulus); this.NotifyOfPropertyChange(() => this.MaintainAspectRatio); // Step 5, Update the Preview if (delayedPreviewprocessor != null && this.Task != null && this.StaticPreviewViewModel != null && this.StaticPreviewViewModel.IsOpen) { delayedPreviewprocessor.PerformTask(() => this.StaticPreviewViewModel.UpdatePreviewFrame(this.Task, this.scannedSource), 800); } }
private bool PictureExists(InventoryType type, PictureSize size) { return GetTargetFile(type, size) != null; }
public void Resize(PictureSize newSize) => Apply(new ClassifiedAdPictureResized { Height = newSize.Height, Width = newSize.Width, PictureId = Id.Value });
private FileInfo GetTargetFile(InventoryType type, PictureSize size) { var matchingFiles = _baseDirectory.GetFiles(GetTargetFileName(type, size)); if (matchingFiles.Length == 0) return null; return matchingFiles[0]; }
/// <summary> /// Get first pictureURL by ref /// </summary> /// <param name="refId"></param> /// <param name="pictureType"></param> /// <param name="pictureSize"></param> /// <returns></returns> public string GetPictureUrlByRef(long refId, PictureType pictureType, PictureSize pictureSize = PictureSize.Auto) { return(GetPictureUrlsByRef(refId, pictureType, pictureSize).FirstOrDefault()); }
public void Add(PictureSize picSize) { BaseAdd(picSize); }
public string GetThumbLocalPath(string thumbFileName, PictureType pictureType, PictureSize pictureSize) { var thumbsDirectoryPath = _webHelper.MapPath("~/Images/" + pictureType + "/" + pictureSize); //get the first two letters of the file name var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(thumbFileName); if (fileNameWithoutExtension != null && fileNameWithoutExtension.Length > MULTIPLE_THUMB_DIRECTORIES_LENGTH) { if (!Directory.Exists(thumbsDirectoryPath)) { Directory.CreateDirectory(thumbsDirectoryPath); } } var thumbFilePath = Path.Combine(thumbsDirectoryPath, thumbFileName); return(thumbFilePath); }
public void Remove(PictureSize serviceConfig) { BaseRemove(serviceConfig.Name); }
public string GetFilePathPhysical(PictureSize size) { return Utility.DirectoryPhysical(string.Empty) + SetFileName(size); }
public static bool HasPictureOfSize(this IImages images, PictureSize pictureSize) => images.AvailableSizes() .Contains(pictureSize);
public static MvcHtmlString GalleryPicture(this HtmlHelper helper, Gallery gallery, PictureSize size) { if (string.IsNullOrEmpty(gallery.DefaultPhoto)) return MvcHtmlString.Empty; var url = new UrlHelper(helper.ViewContext.RequestContext); return MvcHtmlString.Create(string.Format("<img width='200' src='{0}{3}/{4}/{2}' title='{1}'/>", url.Content("~/public/userfiles/galleries/"), gallery.Title, gallery.DefaultPhoto, size, gallery.Id)); }
public IRequest GetProfilePicture(PictureSize size = PictureSize.Medium) { var request = ContentRequest(HttpMethod.Get, ContentUrlBase, "me/picture"); request.AddParameter("type", size.GetDescription()); return request; }