Esempio n. 1
0
        /// <summary>
        /// 创建一个缩略图
        /// </summary>
        /// <param name="photoPath">图片的路径信息</param>
        /// <param name="thumbnailFolder">缩略图所在文件夹的完整路径</param>
        /// <returns></returns>
        public static bool CreateThumbnail(string photoPath, string thumbnailFolder)
        {
            bool  createdThumbnail = false;
            Image thumbnail;

            try
            {
                //  get full path to the thumbnail image
                string thumbnailPath = Path.Combine(thumbnailFolder, GetThumbnailName(photoPath));
                //  see if the thumbnail already exist
                if (!File.Exists(thumbnailPath))
                {
                    //  create the thumbnail image
                    thumbnail = PhotoHelper.GetThumbnail(photoPath, ThumbnailSize.Large);
                    //  save thumbnail to file system
                    thumbnail.Save(thumbnailPath, ImageFormat.Jpeg);
                    createdThumbnail = true;

                    //  clean up
                    if (!(thumbnail == null))
                    {
                        thumbnail.Dispose();
                    }
                }
            }
            catch
            {
                //  an error occurred, return null
            }
            finally
            {
            }
            return(createdThumbnail);
        }
Esempio n. 2
0
        //返回指定图片的缩略图(给定图片的路径)
        public static Image GetThumbnail(string imagePath, int longestSide)
        {
            Image  thumbnail;
            Bitmap image;

            try
            {
                //读取图片
                image     = new Bitmap(imagePath);
                thumbnail = PhotoHelper.GetThumbnail(image, longestSide);
            }
            catch
            {
                return(null);
            }
            finally
            {
                //if (image != null)
                //{
                //    image.Dispose();
                //}
            }

            return(thumbnail);
        }
Esempio n. 3
0
        ////  public methods
        ////  return a list of Photo objects that are initialized from
        ////  metadata xml files if they exist
        //public static Photo[] GetPhotos(string path, string thumbnailFolder)
        //{
        //    string[] files = FileManager.GetPhotoFileList(path);
        //    if ((files == null))
        //    {
        //        return null;
        //    }
        //    Photo[] list = new Photo[files.Length];
        //    string thumbnailPath;
        //    //  go through and create a new instance of each Photo
        //    for (int i = 0; (i
        //                <= (files.Length - 1)); i++)
        //    {
        //        thumbnailPath = Path.Combine(Path.Combine(Path.GetDirectoryName(files[i]), thumbnailFolder), GetThumbnailName(files[i]));
        //        //  ReadXml returns a photo object. The Title, Description,
        //        //  and DateTaken are set if there is an xml file. Otherwise
        //        //  an empty object is returned.
        //        list[i] = Photo.ReadXml(files[i]);
        //        list[i].PhotoName = Path.GetFileNameWithoutExtension(files[i]);
        //        list[i].PhotoPath = files[i];
        //        list[i].ThumbnailCode = GetThumbnailCode(files[i]);
        //        list[i].ThumbnailPath = thumbnailPath;
        //    }
        //    return list;
        //}

        //获取照片对象列表
        public static Photo[] GetPhotos(int FileID)
        {
            Photo[] list = null;
            DataSet ds   = DataAccess.getPhotoData(FileID);

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                list = new Photo[ds.Tables[0].Rows.Count];
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    Photo photo = new Photo();
                    photo.PhotoID     = Convert.ToInt32(ds.Tables[0].Rows[i]["照片ID"]);
                    photo.DocNumber   = Convert.ToInt32(ds.Tables[0].Rows[i]["张号"]);
                    photo.Title       = ds.Tables[0].Rows[i]["题名"].ToString();
                    photo.PhotoNumber = ds.Tables[0].Rows[i]["照片号"].ToString();
                    photo.CJNumber    = ds.Tables[0].Rows[i]["参见号"].ToString();
                    photo.Maker       = ds.Tables[0].Rows[i]["摄影者"].ToString();
                    photo.Description = ds.Tables[0].Rows[i]["文字说明"].ToString();
                    photo.PhotoName   = ds.Tables[0].Rows[i]["Ftp保存名称"].ToString();
                    photo.PhotoPath   = ds.Tables[0].Rows[i]["Ftp目录"].ToString();
                    photo.DateTaken   = getDateTime(ds.Tables[0].Rows[i]["时间"].ToString());
                    object image = ds.Tables[0].Rows[i]["缩略图"];
                    if ((Object.Equals(image, null)) || (Object.Equals(image, System.DBNull.Value)) || (Object.Equals(image, string.Empty)))
                    {
                        Image img = PhotoControl.Properties.Resources.no_photo_s;

                        photo.Thumbnail = PhotoHelper.GetThumbnail(img, ThumbnailSize.Large);
                    }
                    else
                    {
                        MemoryStream ms = new MemoryStream((byte[])image);
                        photo.Thumbnail = Image.FromStream(ms);
                    }
                    list[i] = photo;
                }
            }
            return(list);
        }