Beispiel #1
0
        ///// <summary>
        ///// ��һ��Ŀ¼����һ��CFC�ļ�����
        ///// </summary>
        ///// <param name="directory">Ŀ¼</param>
        ///// <param name="path">����CFC��·��(�����ļ���)</param>
        //public static void BuildCFCFileFromDirectory(string directory,string path)
        //{
        //    List<byte> bytes = new List<byte>();
        //    foreach (string file in Directory.GetFiles(directory))
        //    {
        //        if (!IsImageFile(file))
        //            continue;

        //        bytes.AddRange(Strcut_CFCBlock.FromImage(file).ToBytes());
        //    }
        //    FileStream fs = File.Create(path);
        //    fs.Write(bytes.ToArray(), 0, bytes.Count);
        //    fs.Close();
        //}

        /// <summary>
        /// ����һ��CFC�ļ�����
        /// </summary>
        /// <param name="emoticons"></param>
        /// <returns></returns>
        public static byte[] BuildCFCFileFromBytes(EmoticonCollection emoticons)
        {
            List <byte> bytes = new List <byte>();

            foreach (Emoticon emoticon in emoticons)
            {
                string path = IOUtil.ResolvePath(emoticon.ImageSrc);
                if (!FileHelper.IsPictureFile(path))
                {
                    continue;
                }
                Strcut_CFCBlock block = Strcut_CFCBlock.FromImage(emoticon);
                if (block != null)
                {
                    bytes.AddRange(block.ToBytes());
                }
            }
            return(bytes.ToArray());
        }
Beispiel #2
0
        internal static Strcut_CFCBlock GetFaceBlockFromImage(Emoticon emoticon)
        {
            string filePath = IOUtil.ResolvePath(emoticon.ImageSrc);
            Strcut_CFCBlock fb = new Strcut_CFCBlock();
            //���ļ���   

            //����ļ��Ƿ�ɾ��
            if (!IOUtil.ExistsFile(filePath))
                return null;


            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);

            byte[] faceData = new byte[fs.Length];

            fs.Read(faceData, 0, (int)fs.Length);
            //��ȡͼ��

            Image img;
            try
            {
                img = Image.FromStream(fs);
            }
            catch
            {
                fs.Close();
                return null;
            }
            
            
            //Image thumbnail = img.GetThumbnailImage(20, 20, null, IntPtr.Zero);
            MemoryStream ms = new MemoryStream();
            //����ͼͼת����byte����
            ImageHelper.CreateThunmbnailImage(img, ms, 20, 20, ImageFormat.Bmp);
            byte[] thumbnailData = ms.ToArray();
            ms.Close();
            ms.Dispose();
            //thumbnail.Dispose();

            //�õ�һ��Ψһ��MD5�ַ���
            string md5 = GetMD5(fs);
            fs.Close();
            //fs.Dispose();


            //�ļ�������ʽΪ:md5 + ��չ��
            string fileName = md5 + Path.GetExtension(emoticon.ImageSrc);
            //����ͼ�ļ�������ʽΪ��md5 + fixed.bmp
            string thumbnailName = string.Format("{0}fixed.bmp", md5);
            //����һ����ݼ�
            string uintcuts = emoticon.Shortcut;


            //ȡ���ܵ�֡��
            System.Drawing.Imaging.FrameDimension fd = System.Drawing.Imaging.FrameDimension.Resolution;
            int frameCount = img.FrameDimensionsList.Length;
            img.Dispose();

            fb.MD5 = md5;
            fb.MD5Length = (uint)md5.Length;
            fb.uintcuts = uintcuts;
            fb.uintcutLength = (uint)uintcuts.Length;
            fb.FaceName = uintcuts;
            fb.FaceNameLength = (uint)uintcuts.Length;
            fb.FaceFileName = fileName;
            fb.FaceFileNameLength = (uint)fileName.Length;
            fb.ThumbnailFileName = thumbnailName;
            fb.ThumbnailFileNameLength = (uint)thumbnailName.Length;
            fb.FaceData = File.ReadAllBytes(IOUtil.ResolvePath(emoticon.ImageSrc));
            fb.FileLength = (uint)fb.FaceData.Length;
            fb.ThumbnailData = thumbnailData;
            fb.ThumbnailFileLength = (uint)thumbnailData.Length;
            fb.FrameLength = (uint)frameCount;
            return fb;
        }
Beispiel #3
0
        internal static Strcut_CFCBlock GetFaceBlockFromImage(Emoticon emoticon)
        {
            string          filePath = IOUtil.ResolvePath(emoticon.ImageSrc);
            Strcut_CFCBlock fb       = new Strcut_CFCBlock();

            //���ļ���

            //����ļ��Ƿ�ɾ��
            if (!IOUtil.ExistsFile(filePath))
            {
                return(null);
            }


            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);

            byte[] faceData = new byte[fs.Length];

            fs.Read(faceData, 0, (int)fs.Length);
            //��ȡͼ��

            Image img;

            try
            {
                img = Image.FromStream(fs);
            }
            catch
            {
                fs.Close();
                return(null);
            }


            //Image thumbnail = img.GetThumbnailImage(20, 20, null, IntPtr.Zero);
            MemoryStream ms = new MemoryStream();

            //����ͼͼת����byte����
            ImageHelper.CreateThunmbnailImage(img, ms, 20, 20, ImageFormat.Bmp);
            byte[] thumbnailData = ms.ToArray();
            ms.Close();
            ms.Dispose();
            //thumbnail.Dispose();

            //�õ�һ��Ψһ��MD5�ַ���
            string md5 = GetMD5(fs);

            fs.Close();
            //fs.Dispose();


            //�ļ�������ʽΪ:md5 + ��չ��
            string fileName = md5 + Path.GetExtension(emoticon.ImageSrc);
            //����ͼ�ļ�������ʽΪ��md5 + fixed.bmp
            string thumbnailName = string.Format("{0}fixed.bmp", md5);
            //����һ����ݼ�
            string uintcuts = emoticon.Shortcut;


            //ȡ���ܵ�֡��
            System.Drawing.Imaging.FrameDimension fd = System.Drawing.Imaging.FrameDimension.Resolution;
            int frameCount = img.FrameDimensionsList.Length;

            img.Dispose();

            fb.MD5                     = md5;
            fb.MD5Length               = (uint)md5.Length;
            fb.uintcuts                = uintcuts;
            fb.uintcutLength           = (uint)uintcuts.Length;
            fb.FaceName                = uintcuts;
            fb.FaceNameLength          = (uint)uintcuts.Length;
            fb.FaceFileName            = fileName;
            fb.FaceFileNameLength      = (uint)fileName.Length;
            fb.ThumbnailFileName       = thumbnailName;
            fb.ThumbnailFileNameLength = (uint)thumbnailName.Length;
            fb.FaceData                = File.ReadAllBytes(IOUtil.ResolvePath(emoticon.ImageSrc));
            fb.FileLength              = (uint)fb.FaceData.Length;
            fb.ThumbnailData           = thumbnailData;
            fb.ThumbnailFileLength     = (uint)thumbnailData.Length;
            fb.FrameLength             = (uint)frameCount;
            return(fb);
        }