Bloom.Edit.PageEditingModel.ChangePicture C# (CSharp) Method

ChangePicture() public method

public ChangePicture ( string bookFolderPath, ElementProxy imgOrDivWithBackgroundImage, SIL.Windows.Forms.ImageToolbox.PalasoImage imageInfo, IProgress progress ) : void
bookFolderPath string
imgOrDivWithBackgroundImage ElementProxy Can be an XmlElement (during testing)
imageInfo SIL.Windows.Forms.ImageToolbox.PalasoImage
progress IProgress
return void
        public void ChangePicture(string bookFolderPath, ElementProxy imgOrDivWithBackgroundImage, PalasoImage imageInfo,
			IProgress progress)
        {
            var isSameFile = IsSameFilePath(bookFolderPath, HtmlDom.GetImageElementUrl(imgOrDivWithBackgroundImage), imageInfo);
            var imageFileName = ImageUtils.ProcessAndSaveImageIntoFolder(imageInfo, bookFolderPath, isSameFile);
            HtmlDom.SetImageElementUrl(imgOrDivWithBackgroundImage,
                UrlPathString.CreateFromUnencodedString(imageFileName));
            UpdateMetadataAttributesOnImage(imgOrDivWithBackgroundImage, imageInfo);
        }

Usage Example

 public void ChangePicture_PictureIsFromOutsideProject_PictureCopiedAndAttributeChanged()
 {
     var dom = new XmlDocument();
     dom.LoadXml("<html><body><div/><div><img id='one'/><img id='two' src='old.png'/></div></body></html>");
     var model = new PageEditingModel();
     using (var src = new TemporaryFolder("bloom pictures test source"))
     using (var dest = new TemporaryFolder("bloom picture tests dest"))
     {
         var newImagePath = src.Combine("new.png");
         using (var original = MakeSamplePngImage(newImagePath))
         {
             model.ChangePicture(dest.Path, dom, "two", original);
             Assert.IsTrue(File.Exists(dest.Combine("new.png")));
             AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath(@"//img[@id='two' and @src='new.png']", 1);
         }
     }
 }
All Usage Examples Of Bloom.Edit.PageEditingModel::ChangePicture