Beispiel #1
0
        string ConvertObjectToString(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            if (!Context.DeserializeResources)
            {
                return(obj.ToString());
            }

            return(SerializationUtilities.ConvertObjectToString(obj));
        }
Beispiel #2
0
        /// <summary>
        /// Serialize an image list
        /// </summary>
        /// <param name="opts">Options</param>
        /// <returns></returns>
        public static ResourceElement Serialize(ImageListOptions opts)
        {
            var imgList = new ImageList();

            imgList.ColorDepth       = opts.ColorDepth;
            imgList.ImageSize        = opts.ImageSize;
            imgList.TransparentColor = opts.TransparentColor;

            foreach (var imageSource in opts.ImageSources)
            {
                var bitmapSource = imageSource as BitmapSource;
                if (bitmapSource == null)
                {
                    throw new InvalidOperationException("Only BitmapSources can be used");
                }
                var encoder = new BmpBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
                var outStream = new MemoryStream();
                encoder.Save(outStream);
                outStream.Position = 0;
                var wfBmp = new System.Drawing.Bitmap(outStream);
                imgList.Images.Add(wfBmp);
            }

            var obj = imgList.ImageStream;

            return(new ResourceElement {
                Name = opts.Name,
                ResourceData = new BinaryResourceData(new UserResourceType(obj.GetType().AssemblyQualifiedName, ResourceTypeCode.UserTypes), SerializationUtilities.Serialize(obj)),
            });
        }
Beispiel #3
0
        /// <summary>
        /// Serializes the image
        /// </summary>
        /// <param name="resElem">Resource element</param>
        /// <returns></returns>
        public static ResourceElement Serialize(ResourceElement resElem)
        {
            var  data   = (byte[])((BuiltInResourceData)resElem.ResourceData).Data;
            bool isIcon = BitConverter.ToUInt32(data, 0) == 0x00010000;

            object obj;

            if (isIcon)
            {
                obj = new System.Drawing.Icon(new MemoryStream(data));
            }
            else
            {
                obj = new System.Drawing.Bitmap(new MemoryStream(data));
            }

            return(new ResourceElement {
                Name = resElem.Name,
                ResourceData = new BinaryResourceData(new UserResourceType(obj.GetType().AssemblyQualifiedName, ResourceTypeCode.UserTypes), SerializationUtilities.Serialize(obj)),
            });
        }