Пример #1
0
        public static void CreateSmallThumb(PhotosEntity PhotosObj, Thumb thumb, string path, Bitmap image)
        {
            Thumbs.GetMaintainedRatio(PhotosObj, thumb);


            Graphics graph;
            Bitmap   bitmap = new Bitmap(thumb.Width, thumb.Height);

            graph = Graphics.FromImage(bitmap);
            graph.InterpolationMode = InterpolationMode.HighQualityBicubic;
            // pre paint white to the background of transparent images
            graph.Clear(Color.White);
            // Set the brightness
            graph.DrawImage(image, 0, 0, thumb.Width, thumb.Height);
            // specify codec
            ImageCodecInfo codec = GetEncoderInfo("image/jpeg");
            // set image quality
            EncoderParameters eps = new EncoderParameters(1);

            eps          = new EncoderParameters();
            eps.Param[0] = new EncoderParameter(Encoder.Quality, (long)thumb.Quality);
            //
            bitmap.Save(path + "\\" + PhotosObj.PhotoID + "thumb2.jpg", codec, eps);
            //
            bitmap.Dispose();
            graph.Dispose();
            eps.Dispose();
        }
Пример #2
0
        //-----------------------------------------
        public static bool SavePhoto(string path, PhotosEntity PhotosObj, HttpPostedFile postedFile)
        {
            bool result = false;

            try
            {
                if (!CheckIsImage(postedFile))
                {
                    return(false);
                }
                //To Get The Photo Data----------------------------------
                Bitmap image     = (Bitmap)Bitmap.FromStream(postedFile.InputStream, true);
                string extension = Path.GetExtension(postedFile.FileName);
                postedFile.InputStream.Position = 0;
                PhotosObj.Height = image.Height;
                PhotosObj.Width  = image.Width;
                //
                Thumb thumb = new Thumb();
                //
                string phisycalPath = DCServer.MapPath(path);
                postedFile.SaveAs(phisycalPath + PhotosObj.PhotoID + extension);
                Thumbs.CreateThumb(PhotosObj, new Thumb(190, 125), phisycalPath, image);
                image.Dispose();
                postedFile.InputStream.Close();
                result = true;
            }
            catch
            {
                result = false;
            }
            return(result);
        }
Пример #3
0
        public static void SavePhoto(string phisicalpath, string srcPath, int id, HttpPostedFile postedFile, int width, int height)
        {
            //if (!CheckIsImage(postedFile))
            //	return;
            Bitmap       image     = (Bitmap)Bitmap.FromFile(srcPath, true);
            string       extension = Path.GetExtension(srcPath);
            PhotosEntity PhotosObj = new PhotosEntity(id);

            PhotosObj.Height = image.Height;
            PhotosObj.Width  = image.Width;
            Thumb thumb = new Thumb();

            CreateThumb(PhotosObj, new Thumb(width, height), phisicalpath, image);
            image.Dispose();
        }
Пример #4
0
        //----------------------------------------------------------------------------
        public static void GetMaintainedRatio(PhotosEntity PhotosObj, Thumb thumb)
        {
            // See if we want to maintain the image ratio
            if (thumb.MaintainRatio == true)
            {
                //Check to make sure we have a height and width on the attachemnet (if not check the data)
                if (PhotosObj.Height == 0 || PhotosObj.Width == 0)
                {
                    return;
                }

                double heightRatio = (double)PhotosObj.Height / PhotosObj.Width;
                double widthRatio  = (double)PhotosObj.Width / PhotosObj.Height;

                int desiredHeight = thumb.Height;
                int desiredWidth  = thumb.Width;


                thumb.Height = desiredHeight;
                if (widthRatio > 0)
                {
                    thumb.Width = Convert.ToInt32(thumb.Height * widthRatio);
                }

                if (thumb.Width > desiredWidth)
                {
                    thumb.Width  = desiredWidth;
                    thumb.Height = Convert.ToInt32(thumb.Width * heightRatio);
                }
            }

            // In some instances, we might not want to scale it larger
            if ((thumb.UpScale == false) && (thumb.Height > PhotosObj.Height || thumb.Width > PhotosObj.Width))
            {
                // TODO: Not perfect
                thumb.Height       = PhotosObj.Height;
                thumb.Width        = PhotosObj.Width;
                thumb.OriginalSize = true;
                return;
            }
        }