示例#1
0
 /// <summary>
 /// 销毁对象
 /// </summary>
 public void Dispose()
 {
     if (myImage != null)
     {
         myImage.Dispose();
         myImage = null;
     }
 }
示例#2
0
        /// <summary>
        /// 复制对象
        /// </summary>
        /// <returns>复制后的对象</returns>
        object System.ICloneable.Clone()
        {
            XImageValue obj = new XImageValue();

            if (myValue != null)
            {
                obj.myValue = (System.Drawing.Image)myValue.Clone();
            }
            if (bsImage != null)
            {
                obj.bsImage = new byte[bsImage.Length];
                Array.Copy(bsImage, 0, obj.bsImage, 0, bsImage.Length);
            }
            obj._ContentVersion = this._ContentVersion;
            return(obj);
        }
示例#3
0
        /// <summary>
        /// 将图片转换为指定类型的数据
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="culture">区域信息</param>
        /// <param name="Value">图片数据</param>
        /// <param name="destinationType">指定的类型</param>
        /// <returns>转换结果</returns>
        public override object ConvertTo(
            ITypeDescriptorContext context,
            System.Globalization.CultureInfo culture,
            object Value,
            Type destinationType)
        {
            if (destinationType == null)
            {
                throw new ArgumentNullException("destinationType");
            }

            XImageValue img = ( XImageValue )Value;

            if (img == null)
            {
                return("[NULL]");
            }
            if (destinationType == typeof(string))
            {
                return(img.ToString());
            }

            if (destinationType == typeof(byte[]))
            {
                return(img.ImageData);
            }

            if (destinationType == typeof(InstanceDescriptor))
            {
                byte[] bs = img.ImageData;
                if (bs == null || bs.Length == 0)
                {
                    return(new InstanceDescriptor(typeof(XImageValue).GetConstructor(
                                                      new Type[] {}),
                                                  new object[] {}));
                }
                else
                {
                    System.Reflection.MemberInfo constructor = typeof(XImageValue).GetConstructor(new Type[] { typeof(byte[]) });
                    return(new InstanceDescriptor(constructor, new object[] { img.ImageData }));
                }
            }

            return(base.ConvertTo(context, culture, Value, destinationType));
        }