Beispiel #1
0
        public XlsPicture GetByImage(Image image)
        {
            if (image == null)
            {
                return(null);
            }
            XlsPicture pic;

            if (ImageHash.TryGetValue(image, out pic))
            {
                return(pic);
            }
            byte[] data = ByteImageConverter.ToByteArray(image, ImageFormat.Png);
            foreach (XlsPicture picture in this)
            {
                byte[] bytes = picture.GetImageBytes();
                if (bytes.Length == data.Length)
                {
                    int i;
                    for (i = 0; i < data.Length; i++)
                    {
                        if (bytes[i] != data[i])
                        {
                            break;
                        }
                    }
                    if (i == data.Length)
                    {
                        return(picture);
                    }
                }
            }
            return(AddNew(image));
        }
Beispiel #2
0
        public static byte[] GetImageBytes(Image image)
        {
            if (image == null)
            {
                return new byte[] {}
            }
            ;
            HashObj hashObj = HashObj.GetObj(image);

            byte[] bytes = (byte[])imageHT[hashObj];
            if (bytes == null)
            {
                bytes = ByteImageConverter.ToByteArray(image, ImageFormat.Png);

                imageHT[hashObj] = bytes;
            }
            return(bytes);
        }