Exemplo n.º 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();
        }
Exemplo n.º 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);
        }