コード例 #1
0
        /// <summary>
        /// When publishing a video, this will create the image that put in the placeholder spot for the video.
        /// </summary>
        /// <param name="message">A message that will be drawn on the image</param>
        /// <returns></returns>
        private Bitmap CreateMockPlayer(string message)
        {
            // Draw the status on the image
            Bitmap img = ImageHelper2.CreateResizedBitmap(ResourceHelper.LoadAssemblyResourceBitmap("Video.Images.MockPlayer.png"),
                                                          HtmlSize.Width,
                                                          HtmlSize.Height,
                                                          ImageFormat.Png);

            try
            {
                using (Graphics g = Graphics.FromImage(img))
                {
                    BidiGraphics bidiGraphics = new BidiGraphics(g, img.Size);
                    if (VideoHasError())
                    {
                        DrawErrorMockPlayer(img, bidiGraphics, message);
                    }
                    else
                    {
                        DrawStatusMockPlayer(img, bidiGraphics, message);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Error while creating a placeholder for a video: " + ex);
                return(null);
            }

            return(img);
        }
コード例 #2
0
        internal static Bitmap ResizeImage(Bitmap image, Size newSize, RotateFlipType rotation)
        {
            if (rotation != RotateFlipType.RotateNoneFlipNone)
            {
                image.RotateFlip(rotation);
                image = new Bitmap(image);
            }

            int newWidth  = Math.Max(newSize.Width, 2);
            int newHeight = Math.Max(newSize.Height, 2);

            //resize the image (if its not already the correct size!)
            Bitmap bitmap;

            if (image.Width != newWidth || image.Height != newHeight)
            {
                bitmap = ImageHelper2.CreateResizedBitmap(image, newWidth, newHeight, image.RawFormat);
            }
            else
            {
                bitmap = image;
            }
            return(bitmap);
        }
コード例 #3
0
        private void SetPreviewPicture(Bitmap image, string filename)
        {
            int    maxWidth      = _previewBox.Width - 2;
            int    maxHeight     = _previewBox.Height - 2;
            bool   scaled        = true;
            int    currentWidth  = image.Width;
            int    currentHeight = image.Height;
            double ratio         = 1.00;

            //if height and width are too big
            if (currentWidth > maxWidth && currentHeight > maxHeight)
            {
                //size according to the one that is more off of the available area
                if ((maxWidth / currentWidth) < (maxHeight / currentHeight))
                {
                    ratio = (double)maxWidth / (double)currentWidth;
                }
                else
                {
                    ratio = (double)maxHeight / (double)currentHeight;
                }
            }
            //if just width
            else if (currentWidth > maxWidth)
            {
                ratio = (double)maxWidth / (double)currentWidth;
            }
            //if just height
            else if (currentHeight > maxHeight)
            {
                ratio = (double)maxHeight / (double)currentHeight;
            }
            //else fine
            else
            {
                scaled = false;
            }

            ImageFormat format;
            string      fileExt;

            ImageHelper2.GetImageFormat(filename, out fileExt, out format);
            int newWidth  = (int)(currentWidth * ratio);
            int newHeight = (int)(currentHeight * ratio);

            Bitmap newImage = ImageHelper2.CreateResizedBitmap(image, newWidth, newHeight, format);

            //if image is small enough, add border
            if (newWidth <= maxWidth && newHeight <= maxHeight)
            {
                Bitmap borderPic = new Bitmap(newWidth + 2, newHeight + 2);
                //Get a graphics object for it
                using (Graphics g = Graphics.FromImage(borderPic))
                {
                    g.TextRenderingHint = TextRenderingHint.AntiAlias;

                    int   R    = SystemColors.Control.R;
                    int   G    = SystemColors.Control.G;
                    int   B    = SystemColors.Control.B;
                    Color dark = Color.FromArgb((int)(R * 0.9), (int)(G * 0.9), (int)(B * 0.9));
                    //draw the border
                    g.FillRectangle(new SolidBrush(dark), new Rectangle(0, 0, borderPic.Width, 1));
                    g.FillRectangle(new SolidBrush(dark), new Rectangle(0, borderPic.Height - 1, borderPic.Width, 1));
                    g.FillRectangle(new SolidBrush(dark), new Rectangle(0, 0, 1, borderPic.Height));
                    g.FillRectangle(new SolidBrush(dark), new Rectangle(borderPic.Width - 1, 0, 1, borderPic.Height));

                    //draw our image back in the middle
                    g.DrawImage(newImage, new Rectangle(1, 1, newWidth, newHeight), 0, 0, newWidth, newHeight, GraphicsUnit.Pixel);
                }
                _previewBox.Image = borderPic;
            }
            else
            {
                _previewBox.Image = newImage;
            }

            string picsize;

            if (!scaled)
            {
                picsize = MakeDimensions(currentWidth, currentHeight);
            }
            else
            {
                picsize = string.Format(CultureInfo.CurrentCulture, Res.Get(StringId.InsertImageDimensionsFormatScaled),
                                        MakeDimensions(currentWidth, currentHeight));
            }
            _fileSize.Text = picsize;
        }
コード例 #4
0
        /// <summary>
        /// Initializes and registers images with the editor.
        /// </summary>
        protected override void DoWork()
        {
            foreach (NewImageInfo newImage in this.newImages)
            {
                // Before starting on the next image, make sure we weren't cancelled.
                if (CancelRequested)
                {
                    AcknowledgeCancel();
                    return;
                }

                try
                {
                    // Register the image file as a BlogPostImageData so that the editor can manage the supporting files
                    ISupportingFile sourceFile = this.fileService.AddLinkedSupportingFileReference(newImage.ImageInfo.ImageSourceUri);
                    newImage.ImageData = new BlogPostImageData(new ImageFileData(sourceFile, newImage.ImageInfo.ImageSourceSize.Width, newImage.ImageInfo.ImageSourceSize.Height, ImageFileRelationship.Source));

                    // Create the shadow file if necessary.
                    if (GlobalEditorOptions.SupportsFeature(ContentEditorFeature.ShadowImageForDrafts))
                    {
                        newImage.ImageData.InitShadowFile(this.fileService);
                    }

                    // Create the initial inline image.
                    Stream inlineImageStream = new MemoryStream();
                    using (Bitmap sourceBitmap = new Bitmap(newImage.ImageInfo.ImageSourceUri.LocalPath))
                    {
                        string      extension;
                        ImageFormat imageFormat;
                        ImageHelper2.GetImageFormat(newImage.ImageInfo.ImageSourceUri.LocalPath, out extension, out imageFormat);

                        using (Bitmap resizedBitmap = ImageHelper2.CreateResizedBitmap(sourceBitmap, newImage.InitialSize.Width, newImage.InitialSize.Height, imageFormat))
                        {
                            // Resizing the bitmap is a time-consuming operation, so its possible we were cancelled during it.
                            if (CancelRequested)
                            {
                                AcknowledgeCancel();
                                return;
                            }

                            ImageHelper2.SaveImage(resizedBitmap, imageFormat, inlineImageStream);
                        }

                        inlineImageStream.Seek(0, SeekOrigin.Begin);
                    }

                    // Saving the bitmap is a time-consuming operation, so its possible we were cancelled during it.
                    if (CancelRequested)
                    {
                        AcknowledgeCancel();
                        return;
                    }

                    // Link up the initial inline image.
                    ISupportingFile imageFilePlaceholderHolder = this.fileService.CreateSupportingFile(Path.GetFileName(newImage.ImageInfo.ImageSourceUri.LocalPath), Guid.NewGuid().ToString(), inlineImageStream);
                    newImage.ImageData.InlineImageFile = new ImageFileData(imageFilePlaceholderHolder, newImage.InitialSize.Width, newImage.InitialSize.Height, ImageFileRelationship.Inline);
                }
                catch (Exception e)
                {
                    // Something failed for this image, flag this for removal
                    Debug.WriteLine("Image file could not be initialized: " + newImage.ImageInfo.ImageSourceUri.LocalPath + " " + e);
                    Trace.WriteLine("Could not initialize image: " + newImage.ImageInfo.ImageSourceUri.LocalPath);
                    Trace.WriteLine(e.ToString());
                    newImage.Remove = true;
                }
            }

            // We've successfully intialized all the images, but make sure we weren't cancelled at the last second.
            if (CancelRequested)
            {
                AcknowledgeCancel();
                return;
            }
        }