示例#1
0
 /// <summary>
 /// Validate the object.
 /// </summary>
 /// <exception cref="Rest.ValidationException">
 /// Thrown if validation fails
 /// </exception>
 public virtual void Validate()
 {
     if (BestRepresentativeQuery != null)
     {
         BestRepresentativeQuery.Validate();
     }
     if (ImageCaption != null)
     {
         ImageCaption.Validate();
     }
     if (ImageTags != null)
     {
         ImageTags.Validate();
     }
 }
示例#2
0
 public TagDTO(ImageCaption caption, List <Category> categories, List <ImageTag> tags)
 {
     Caption    = caption;
     Categories = categories;
     Tags       = tags;
 }
示例#3
0
        /// <summary>
        /// Draws caption header
        /// </summary>
        /// <param name="original"></param>
        /// <param name="loanNumber"></param>
        /// <param name="loanType"></param>
        /// <param name="workOrderNumber"></param>
        /// <param name="bank"></param>
        /// <param name="addressDisplay"></param>
        /// <param name="orderNumber"></param>
        /// <param name="caption"></param>
        /// <param name="date"></param>
        /// <param name="includeTime"></param>
        /// <param name="drawCameraDate">Pass true to draw the camera date at the same time saving resources (image & graphics objects)</param>
        /// <param name="fullSizedCaption">True to keep picture 600px wide (full width of caption header), false to shink photo to original dimensions to save memory</param>
        /// <returns></returns>
        public static Image DrawCaptionHeader(this Image original, ImageCaption caption)
        {
            string photoDetails = string.Format(
                "Property ID: {0}    Loan Type: {1}    W/O #: {2}    Bank: {3}{4}" +
                "Address: {5}{4}" +
                "Date: {6}    Field-Comm.net Order #: {7}{4}",
                caption.LoanNumber, caption.LoanType, caption.WorkOrderNumber, caption.Bank, Environment.NewLine,
                caption.AddressDisplay,
                caption.IncludeTime ? string.Format("{0} {1}", caption.Date.ToShortDateString(), caption.Date.ToShortTimeString()) : caption.Date.ToShortDateString(),
                caption.OrderNumber.ToString());

            string captionText = string.Format("Caption: {0}", caption.Caption.Replace(@"\\n", "//n").Replace(@"\n", Environment.NewLine).Replace("//n", @"\n"));
            string message     = "Image generated by:";
            string fcVersion   = "Field-Comm.net";

            Font fcMessageFont    = new Font("Tahoma", 12, FontStyle.Bold);
            Font fcVerFont        = new Font("Tahoma", 12, FontStyle.Bold | FontStyle.Italic);
            Font photoDetailsFont = new Font("Tahoma", 8, FontStyle.Bold);

            int longestSide = original.Height;

            if (original.Width > original.Height)
            {
                longestSide = original.Width;
            }

            Rectangle scaledDimensions = Orange.Imaging.ImageExtensions.GetScaledDimensions(original.Width, original.Height, longestSide);

            SizeF detailsSize;
            SizeF captionSize;
            SizeF fcSize;

            using (Graphics g = Graphics.FromImage(original))
            {
                detailsSize = g.MeasureString(photoDetails, photoDetailsFont, scaledDimensions.Width - 10, StringFormat.GenericTypographic);
                captionSize = g.MeasureString(captionText, photoDetailsFont, scaledDimensions.Width - 20, StringFormat.GenericTypographic);
                fcSize      = g.MeasureString(message + " " + fcVersion, fcMessageFont, scaledDimensions.Width);
            }

            Rectangle messageRect = new Rectangle(0, 0, scaledDimensions.Width,
                                                  detailsSize.ToSize().Height   //Height of the Details
                                                  + captionSize.ToSize().Height //Height of the caption
                                                  + 10);

            int fcMessageHeight = fcSize.Width + 15 < scaledDimensions.Width ? fcSize.ToSize().Height : 0;

            System.Drawing.Image newPhoto = new Bitmap(scaledDimensions.Width, scaledDimensions.Height + messageRect.Height + fcMessageHeight, original.PixelFormat);

            using (original)
            {
                using (Graphics g = Graphics.FromImage(newPhoto))
                {
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

                    //set text bacground area

                    //draw the image TEXT_RECTANGLE_HEIGHT pixels lower than the top of the new photo
                    //(leaving rectangle to write with)
                    g.DrawImage(original, new Rectangle(0, messageRect.Height + fcMessageHeight, scaledDimensions.Width, scaledDimensions.Height));

                    //draw white background in rectanble so text is visible
                    //g.FillRectangle(new SolidBrush(Color.White), messageRect);
                    //draw blue gradient into background of rectangle:
                    g.FillRectangle(new LinearGradientBrush(messageRect, HeaderDarkColor, HeaderLightColor,
                                                            LinearGradientMode.ForwardDiagonal) /*new SolidBrush(Color.White)*/, messageRect);

                    float fcVersionWidth = g.MeasureString(fcVersion, fcVerFont).Width;
                    float fcMessageWidth = g.MeasureString(message, fcMessageFont).Width;

                    if (fcVersionWidth + fcMessageWidth + 15 < newPhoto.Width)
                    {
                        //Make orange gradient for FC info
                        g.FillRectangle(new LinearGradientBrush(new Point(0, messageRect.Height),
                                                                new Point(newPhoto.Width, messageRect.Height + 20), GroupBarHighLightLightColor,
                                                                GroupBarHighlightDarkColor) /*new SolidBrush(Color.White)*/,
                                        0, messageRect.Height, messageRect.Width, 20);
                        //draw version
                        g.DrawString(fcVersion, fcVerFont, new SolidBrush(Color.Black),
                                     newPhoto.Width - fcVersionWidth - 5, messageRect.Height);
                        //draw message
                        g.DrawString(message, fcMessageFont, new SolidBrush(Color.Black),
                                     newPhoto.Width - fcVersionWidth - fcMessageWidth - 5, messageRect.Height);
                    }
                    else
                    {
                        //Make orange gradient for FC info
                        g.FillRectangle(new LinearGradientBrush(new Point(0, messageRect.Height),
                                                                new Point(newPhoto.Width, messageRect.Height + 10), GroupBarHighLightLightColor,
                                                                GroupBarHighlightDarkColor) /*new SolidBrush(Color.White)*/,
                                        0, messageRect.Height, messageRect.Width, fcSize.Height);

                        //draw message
                        g.DrawString(message + " " + fcVersion, fcMessageFont, new SolidBrush(Color.Black),
                                     new RectangleF(5, messageRect.Height, newPhoto.Width, fcSize.Height));
                    }

                    //draw photo details
                    g.DrawString(photoDetails, photoDetailsFont, new SolidBrush(Color.White),
                                 new RectangleF(5, 5, detailsSize.Width, detailsSize.Height), StringFormat.GenericTypographic);

                    //draw caption
                    g.DrawString(captionText, photoDetailsFont, new SolidBrush(Color.White),
                                 new RectangleF(5, 5 + detailsSize.Height, captionSize.Width + 20, captionSize.Height));

                    if (caption.IncludeCameraDate)
                    {
                        DrawCameraDateInternal(g, caption.Date, caption.IncludeTime, newPhoto.Size);
                    }

                    if (caption.FullSizedCaption)
                    {
                        return(newPhoto);
                    }
                    else //shrink it back down to original size
                    {
                        return(newPhoto.ResizePhoto(longestSide));
                    }
                }
            }
        }