public override bool IsEditableEmbeddedImage() { if (!IsEmbeddedImage()) { return(false); } string path = _imageData.GetImageSourceFile().Uri.LocalPath; if (ImageHelper2.IsAnimated(path)) { return(false); } return(!ImageHelper2.IsMetafile(path)); }
public Bitmap ApplyImageDecorators(Bitmap bitmap) { _currImage = bitmap; _originalImage = bitmap; bool borderNeedsReset = true; foreach (ImageDecorator decorator in _decoratorsList) { ApplyImageDecorator(decorator, _currImage, ref borderNeedsReset); } //update the rotation and size info in the image properties if (_embedType == ImageEmbedType.Embedded) { // if (borderNeedsReset) // BorderMargin = ImageBorderMargin.Empty; if (!ImageHelper2.IsAnimated(_currImage)) { Size currImageSize = _currImage.Size; //update the inline image size (don't forget to remove size added by borders) ImageBorderMargin borderMargin = BorderMargin; Size borderlessImageSize = new Size( currImageSize.Width - borderMargin.Width, currImageSize.Height - borderMargin.Height); _imageInfo.InlineImageSize = borderlessImageSize; } } else { _imageInfo.LinkTargetImageSize = _currImage.Size; } _originalImage = null; return(_currImage); }
public void Decorate(ImageDecoratorContext context) { bool useOriginalImage = true; HtmlImageResizeDecoratorSettings settings = new HtmlImageResizeDecoratorSettings(context.Settings, context.ImgElement); if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert || context.InvocationSource == ImageDecoratorInvocationSource.Reset) { // WinLive 96840 - Copying and pasting images within shared canvas should persist source // decorator settings. // If ImageSizeName is set, then use that instead of default values if (settings.IsImageSizeNameSet && context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert) { // We must be copying settings from another instance of the same image settings.SetImageSize(settings.ImageSize, settings.ImageSizeName); // WinLive 96840 - Copying and pasting images within shared canvas should persist source // decorator settings. // Also if we are copying settings, then use the image instance from context instead of the // original image. This ensures we use the cropped image (if any) to resize. useOriginalImage = false; } else { //calculate the default image size and rotation. If the camera has indicated that the //orientation of the photo is rotated (in the EXIF data), shift the rotation appropriately //to insert the image correctly. //Fix the image orientation based on the Exif data (added by digital cameras). RotateFlipType fixedRotation = ImageUtils.GetFixupRotateFlipFromExifOrientation(context.Image); settings.Rotation = fixedRotation; settings.BaseSize = context.Image.Size; //the default size is a scaled version of the image based on the default inline size constraints. Size defaultBoundsSize; if (settings.DefaultBoundsSizeName != ImageSizeName.Full) { defaultBoundsSize = settings.DefaultBoundsSize; } else //original size is default, so we aren't going to scale { defaultBoundsSize = context.Image.Size; } //calulate the base image size to scale from. If the image is rotated 90 degrees, then switch the height/width Size baseImageSize = context.Image.Size; if (ImageUtils.IsRotated90(settings.Rotation)) { baseImageSize = new Size(baseImageSize.Height, baseImageSize.Width); } //calculate and set the scaled default size using the defaultSizeBounds //Note: if the image dimensions are smaller than the default, don't scale that dimension (bug 419446) Size defaultSize = ImageUtils.GetScaledImageSize(Math.Min(baseImageSize.Width, defaultBoundsSize.Width), Math.Min(baseImageSize.Height, defaultBoundsSize.Height), baseImageSize); if (defaultSize.Width < defaultBoundsSize.Width && defaultSize.Height < defaultBoundsSize.Height) { settings.SetImageSize(defaultSize, ImageSizeName.Full); } else { settings.SetImageSize(defaultSize, settings.DefaultBoundsSizeName); } } } else if (settings.BaseSizeChanged(context.Image)) { Size newBaseSize = context.Image.Size; settings.SetImageSize(AdjustImageSizeForNewBaseSize(true, settings, newBaseSize, settings.Rotation, context), null); settings.BaseSize = newBaseSize; } //this decorator only applies to embedded images. if (context.ImageEmbedType == ImageEmbedType.Embedded && !ImageHelper2.IsAnimated(context.Image)) { Bitmap imageToResize = null; // To make image insertion faster, we've already created an initial resized image on a background thread. if (context.InvocationSource == ImageDecoratorInvocationSource.InitialInsert && useOriginalImage) { try { string imageSrc = context.ImgElement.getAttribute("src", 2) as string; if (!string.IsNullOrEmpty(imageSrc) && (UrlHelper.IsFileUrl(imageSrc) || File.Exists(new Uri(imageSrc).ToString()))) { Uri imageSrcUri = new Uri(imageSrc); imageToResize = (Bitmap)Image.FromFile(imageSrcUri.LocalPath); } } catch (Exception e) { Debug.Write("Failed to load pre-created initial image: " + e); } } if (imageToResize == null) { imageToResize = context.Image; } // Figure the desired image size by taking the size of the img element // and calculate what borderless image size we'd need to start with // to end up at that size. This is different than simply subtracting // the existing border size, since borders can be relative to the // size of the base image. Size desiredImageSize = settings.BorderMargin.ReverseCalculateImageSize(settings.ImageSizeWithBorder); //resize the image and update the image used by the context. if (desiredImageSize != imageToResize.Size || settings.Rotation != RotateFlipType.RotateNoneFlipNone) { context.Image = ResizeImage(imageToResize, desiredImageSize, settings.Rotation); } else { context.Image = imageToResize; } if (settings.ImageSize != context.Image.Size) { settings.SetImageSize(context.Image.Size, settings.ImageSizeName); } } }