コード例 #1
0
        public void Write(BitmapSource i, Stream s)
        {
            BitmapEncoder encoder = null;

            if (MimeType.Equals("image/jpeg"))
            {
                encoder = new JpegBitmapEncoder();
                ((JpegBitmapEncoder)encoder).QualityLevel = localSettings.Quality;
            }
            else if (MimeType.Equals("image/png"))
            {
                encoder = new PngBitmapEncoder();
            }
            else if (MimeType.Equals("image/gif"))
            {
                encoder         = new GifBitmapEncoder();
                encoder.Palette = new BitmapPalette(i, 256);
            }

            encoder.Frames.Add(BitmapFrame.Create(i));

            using (MemoryStream outputStream = new MemoryStream())
            {
                encoder.Save(outputStream);
                outputStream.WriteTo(s);
            }
        }
コード例 #2
0
ファイル: FormatBase.cs プロジェクト: zyltntking/Lenneth
        /// <summary>
        /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            var format = obj as ISupportedImageFormat;

            if (format == null)
            {
                return(false);
            }

            return(MimeType.Equals(format.MimeType) && IsIndexed.Equals(format.IsIndexed));
        }
コード例 #3
0
ファイル: WicEncoder.cs プロジェクト: stukalin/ImageResizer
        public Guid GetOutputFormatWicGuid()
        {
            Guid guidEncoder = Consts.GUID_ContainerFormatJpeg;

            if (MimeType.Equals("image/jpeg"))
            {
                guidEncoder = Consts.GUID_ContainerFormatJpeg;
            }
            if (MimeType.Equals("image/png"))
            {
                guidEncoder = Consts.GUID_ContainerFormatPng;
            }
            if (MimeType.Equals("image/gif"))
            {
                guidEncoder = Consts.GUID_ContainerFormatGif;
            }
            return(guidEncoder);
        }
コード例 #4
0
        /// <summary>
        /// Returns true if Attachment instances are equal
        /// </summary>
        /// <param name="other">Instance of Attachment to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(Attachment other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id.Equals(other.Id)
                     ) &&
                 (
                     FileName == other.FileName ||
                     FileName != null &&
                     FileName.Equals(other.FileName)
                 ) &&
                 (
                     FileContents == other.FileContents ||
                     FileContents != null &&
                     FileContents.Equals(other.FileContents)
                 ) &&
                 (
                     Description == other.Description ||
                     Description != null &&
                     Description.Equals(other.Description)
                 ) &&
                 (
                     MimeType == other.MimeType ||
                     MimeType != null &&
                     MimeType.Equals(other.MimeType)
                 ) &&
                 (
                     Type == other.Type ||
                     Type != null &&
                     Type.Equals(other.Type)
                 ));
        }
コード例 #5
0
        public Base64Image(string data, long?fileSize = null)
        {
            if (!string.IsNullOrEmpty(data))
            {
                if (Regex.IsMatch(data, @"data:[a-z0-9]+/[a-z0-9]+;base64,\s*.+", RegexOptions.IgnoreCase))
                {
                    Data     = data.Substring(data.IndexOf("base64,") + 7).Trim();
                    MimeType = data.Substring(5, data.IndexOf(";") - 5);

                    //"image/jpeg"
                    //"image/png"

                    ImageType = MimeType.Equals("image/png") ? ImageType.png : ImageType.jpg;
                }
                else
                {
                    Data      = data.Trim();
                    MimeType  = FileUtility.GetMimeType(".jpg");
                    ImageType = ImageType.jpg;
                }

                Size = fileSize ?? data.Length;
            }
        }