示例#1
0
        public static Image ScaleImage(Image ImageToScale, double ScaledToHeight, double ScaleToWidth)
        {
            //Hold the min value. Is it the height or the width - Figure out which is the minimum value...the width or the height. Keeps the ratio
            double ScalingValue = Math.Min((ScaleToWidth / ImageToScale.Width), (ScaledToHeight / ImageToScale.Height));

            //Set the final scaled width
            double ScaledWidth = (ScalingValue * ImageToScale.Width);

            //Set the final scaled height
            double ScaledHeight = (ScalingValue * ImageToScale.Height);

            //set the callback to the private method - ThumbnailCallback
            //just use a lamda since the method doesn't do anything
            Image.GetThumbnailImageAbort CallBackForConversion = new Image.GetThumbnailImageAbort(() =>
            {
                try
                {
                    return false;
                }
                catch (Exception)
                {
                    throw;
                }
            });

            //return the image that is going to be scaled
            return ImageToScale.GetThumbnailImage(Convert.ToInt32(ScaledWidth), Convert.ToInt32(ScaledHeight), CallBackForConversion, IntPtr.Zero);
        }
 public ActionResult Thumbnail(string path)
 {
     var myCallback =
         new Image.GetThumbnailImageAbort(ThumbnailCallback);
     var paths = new List<string>(2);
     BuildPath(path, out folderPath, out resourcePath);
     var folder = session.OpenFolder(folderPath + "/");
     var resource = folder.GetResource(resourcePath + "/");
     var sourceStream = resource.GetReadStream();
     Bitmap bitmap = null;
     try
     {
         bitmap = new Bitmap(sourceStream);
     }
     catch (Exception)
     {
         var fs = new FileStream(Server.MapPath("~/Content/kendo/2014.2.716/Bootstrap/imagebrowser.png"), FileMode.Open);
         var tempBs = new byte[fs.Length];
         fs.Read(tempBs, 0, tempBs.Length);
         return new FileContentResult(tempBs, "image/jpeg");
     }
     var myThumbnail = bitmap.GetThumbnailImage(84, 70, myCallback, IntPtr.Zero);
     var ms = new MemoryStream();
     var myEncoderParameters = new EncoderParameters(1);
     var myEncoderParameter = new EncoderParameter(Encoder.Quality, 25L);
     myEncoderParameters.Param[0] = myEncoderParameter;
     myThumbnail.Save(ms, GetEncoderInfo("image/jpeg"), myEncoderParameters);
     ms.Position = 0;
     var bytes = ms.ToArray();
     return new FileContentResult(bytes, "image/jpeg");
 }
        private Bitmap scaleBitmap(Bitmap bmp, PictureBox picBox)
        {
            float ratio = 1.0f;
            int thumbHeight = 0;
            int thumbWidth = 0;

            if (bmp.Height > picBox.Height || bmp.Width > picBox.Width)
            {
                Image.GetThumbnailImageAbort myCallback =
                    new Image.GetThumbnailImageAbort(ThumbnailCallback);

                if (bmp.Height >= bmp.Width)
                {
                    ratio = (((float)bmp.Width) / ((float)bmp.Height));
                    thumbHeight = picBox.Height;
                    thumbWidth = (int)((thumbHeight) * (ratio));
                }
                else
                {
                    ratio = (((float)bmp.Height) / ((float)bmp.Width));
                    thumbWidth = picBox.Width;
                    thumbHeight = (int)((thumbWidth) * (ratio));
                }

                Image myThumbnail = bmp.GetThumbnailImage(thumbWidth, thumbHeight, myCallback, IntPtr.Zero);
                return new Bitmap(myThumbnail);
            }
            return bmp;
        }
        public void GenerateThumbnail(Stream imgFileStream, Stream thumbStream)
        {
            Image.GetThumbnailImageAbort callback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
            Bitmap bitmap = new Bitmap(imgFileStream);
            int thumbWidth = MaxThumbWidth;
            int thumbHeight = MaxThumbHeight;
            if (bitmap.Width > bitmap.Height)
            {
                thumbHeight = Decimal.ToInt32(((Decimal)bitmap.Height / bitmap.Width) * thumbWidth);
                if (thumbHeight > MaxThumbHeight)
                {
                    thumbHeight = MaxThumbHeight;
                }
            }
            else
            {
                thumbWidth = Decimal.ToInt32(((Decimal)bitmap.Width / bitmap.Height) * thumbHeight);
                if (thumbWidth > MaxThumbWidth)
                {
                    thumbWidth = MaxThumbWidth;
                }
            }

            Image thumbnail = bitmap.GetThumbnailImage(thumbWidth, thumbHeight, callback, IntPtr.Zero);

            thumbnail.Save(thumbStream,ImageFormat.Jpeg);
        }
示例#5
0
 /// <summary>
 /// 生成缩略图,返回缩略图的Image对象
 /// </summary>
 /// <param name="Width">缩略图宽度</param>
 /// <param name="Height">缩略图高度</param>
 /// <returns>缩略图的Image对象</returns>
 public Image GetImage(int Width, int Height)
 {
     Image img;
     Image.GetThumbnailImageAbort callb = new Image.GetThumbnailImageAbort(ThumbnailCallback);
     img = srcImage.GetThumbnailImage(Width, Height, callb, IntPtr.Zero);
     return img;
 }
 private void GetThumbnail(PaintEventArgs e)
 {
     Image.GetThumbnailImageAbort callback =
         new Image.GetThumbnailImageAbort(ThumbnailCallback);
     if (flag == 1)
     {
         for (int j = 0; j < 4; ++j)
         {
             for (int i = 0; i < 4; ++i)
             {
                 Image image = new Bitmap(filePaths[j * 4 + i]);
                 Image pThumbnail = image.GetThumbnailImage(200, 150, callback, new
                    IntPtr());
                 //label1.Text = filePaths[j*2 +i];
                 e.Graphics.DrawImage(
                    pThumbnail,
                    i * 230 + 20,
                    j * 160 + 10,
                    pThumbnail.Width,
                    pThumbnail.Height);
                 image = null;
                 pThumbnail = null;
                 GC.Collect();
             }
         }
     }
 }
示例#7
0
        public Image GetThumbNail( Image image, int new_width, int new_height )
        {
            Image.GetThumbnailImageAbort thumbnailCallback = new Image.GetThumbnailImageAbort( DummyThumbnailCallback );

            Image thumbnail = image.GetThumbnailImage( new_width, new_height, thumbnailCallback, IntPtr.Zero );

            return thumbnail;
        }
        public void Example_GetThumb(PaintEventArgs e)
        {
            Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
            Bitmap myBitmap = new Bitmap("Climber.jpg");
            Image myThumbnail = myBitmap.GetThumbnailImage(40, 40, myCallback, IntPtr.Zero);

            e.Graphics.DrawImage(myThumbnail, 150, 75);
        }
示例#9
0
        public Form1()
        {
            InitializeComponent();
            CheckForIllegalCrossThreadCalls = false;
            myCallback = new Image.GetThumbnailImageAbort(CallBack);

            listener = new TcpListener(ipAddress, 8210);
        }
示例#10
0
        public RGBFilter(BQPaint f)
        {
            InitializeComponent();
            this.f = f;
            Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);

            copy = f.main_bitmap.GetThumbnailImage(120, 120, myCallback, IntPtr.Zero);
            thumbnail.Image = copy;
        }
示例#11
0
    public void GenerateThumb(string imageInPath, string thumbOutPath)
    {
        log.Info("GenerateThumb(" + imageInPath + ", " + thumbOutPath + ")");

        try {
            if (Directory.Exists(thumbOutPath.Substring(0,thumbOutPath.LastIndexOf("/"))) == false)
                Directory.CreateDirectory(thumbOutPath.Substring(0,thumbOutPath.LastIndexOf("/")));

            using (Image imageIn = System.Drawing.Image.FromFile(imageInPath)) {

                int width = thumbWidth;
                int height = thumbHeight;

                /* Is the image smaller than our thumbnail size? */

                if (imageIn.Width < thumbWidth)
                    width = imageIn.Width;

                if (imageIn.Height < thumbHeight)
                    height = imageIn.Height;

                /* Is the image tall ? */

                if (imageIn.Height > imageIn.Width) {
                    height = thumbHeight;
                    width = Convert.ToInt32 ((double)height * ((double)imageIn.Width / (double)imageIn.Height));
                }

                /* Is the image wide ? */

                if (imageIn.Height < imageIn.Width) {
                    width = thumbWidth;
                    height = Convert.ToInt32( (double)width * ((double)imageIn.Height / (double)imageIn.Width) );
                }

                /* Center the thumbnail */

                int x = (thumbWidth / 2) - (width /2);
                int y = (thumbHeight / 2) - (height /2);

                Console.WriteLine ("New Thumb: " + x + " " + y + " " + width + " " + height);
                Image.GetThumbnailImageAbort dummyCallback = new Image.GetThumbnailImageAbort (ThumbnailCallback);
                Image thumbImage = imageIn.GetThumbnailImage (width, height, dummyCallback, IntPtr.Zero);
                Bitmap imageOut = new Bitmap (thumbWidth, thumbHeight);
                Graphics graphicsOut = Graphics.FromImage (imageOut);
                graphicsOut.Clear (Color.Gray);
                graphicsOut.DrawImage (thumbImage, x, y);
                imageOut.Save (thumbOutPath, ImageFormat.Jpeg);

            }

        } catch (Exception ex) {
            log.Error("Exception in GenerateThumb!", ex);
            throw ex;
        }
    }
示例#12
0
 /// <summary>  
 /// 生成缩略图,返回缩略图的Image对象  
 /// </summary>  
 /// <param name="path">原图片全路径</param>  
 /// <param name="width">缩略图的宽度</param>  
 /// <param name="height">缩略图的高度</param>  
 /// <returns>缩略图的Image对象</returns>  
 public static Image GetThumbnail(string path,int width, int height)
 {
     try
     {
         Image resourceImage = Image.FromFile(path);//获取原图
         Image.GetThumbnailImageAbort callb = new Image.GetThumbnailImageAbort(ThumbnailCallback);
         return resourceImage.GetThumbnailImage(width, height, callb, IntPtr.Zero);
     }
     catch{return null;}
 }
示例#13
0
 public static Response GetThumbnailImage(Guid id, int page, IResponseFormatter response)
 {
     var bitmap = Image.FromStream(new MemoryStream(GetPageImageBytes(id, page)), false, false);
     double ratio = 200D / (double)bitmap.Height;
     int width = (int)(bitmap.Width * ratio);
     var callback = new Image.GetThumbnailImageAbort(() => true);
     var thumbnail = bitmap.GetThumbnailImage(width, 200, callback, IntPtr.Zero);
     MemoryStream stream = GetBytesFromImage(thumbnail);
     return response.FromStream(stream, MimeTypes.GetMimeType(".jpg"));
 }
示例#14
0
        /// <summary>
        /// Converts any bitmap down to a 96x96 square with linear x/y scaling and border whitespace if needed
        /// </summary>
        /// <param name="masterImage">Full size Bitmap of any dimension</param>
        /// <returns>96x96 Bitmap</returns>
        internal static Bitmap GenerateThumbnail(Bitmap masterImage)
        {
            Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);

            // Calculate the thumbnail size
            double newWidth = 0.0;
            double newHeight = 0.0;

            if (masterImage.Width > 96 || masterImage.Height > 96)
            {
                bool portrait = false;

                if (masterImage.Width > masterImage.Height)
                    portrait = true;

                if (portrait)
                {
                    double pct = (double)masterImage.Width / 96;
                    newWidth = (double)masterImage.Width / pct;
                    newHeight = (double)masterImage.Height / pct;
                }
                else
                {
                    double pct = (double)masterImage.Height / 96;
                    newWidth = (double)masterImage.Width / pct;
                    newHeight = (double)masterImage.Height / pct;
                }
            }
            else
            {
                newWidth = masterImage.Width;
                newHeight = masterImage.Height;
            }

            Image myThumbnail = masterImage.GetThumbnailImage((int)newWidth,(int)newHeight,myCallback,IntPtr.Zero);

            // Put the thumbnail on a square background
            Bitmap squareThumb = new Bitmap(96,96);
            Graphics g = Graphics.FromImage(squareThumb);

            int x = 0;
            int y = 0;

            x = (96 - myThumbnail.Width) / 2;
            y = (96 - myThumbnail.Height) / 2;

            g.DrawImage(myThumbnail, new Rectangle(new Point(x,y), new Size(myThumbnail.Width, myThumbnail.Height)));


            // Write out the new bitmap
            MemoryStream ms = new MemoryStream();
            squareThumb.Save(ms, ImageFormat.Png);
            return new Bitmap(ms);
        }
    public void ProcessRequest(HttpContext context)
    {
        string ImageUrl = context.Request.QueryString["url"];
        //get image width to be resized from querystring
        string ImageWidth = context.Request.QueryString["width"];
        //get image height to be resized from querystring
        string ImageHeight = context.Request.QueryString["height"];
        if (ImageUrl != string.Empty && ImageHeight != string.Empty && ImageWidth != string.Empty && (ImageWidth != null && ImageHeight != null))
        {
            if (!System.Web.UI.WebControls.Unit.Parse(ImageWidth).IsEmpty && !System.Web.UI.WebControls.Unit.Parse(ImageHeight).IsEmpty)
            {
                Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
                //creat BitMap object from image path passed in querystring
                Bitmap BitmapForImage = new Bitmap(context.Server.MapPath(ImageUrl));
                //create unit object for height and width. This is to convert parameter passed in differen unit like pixel, inch into generic unit.
                System.Web.UI.WebControls.Unit WidthUnit = System.Web.UI.WebControls.Unit.Parse(ImageWidth);
                System.Web.UI.WebControls.Unit HeightUnit = System.Web.UI.WebControls.Unit.Parse(ImageHeight);
                //Resize actual image using width and height paramters passed in querystring
                Image CurrentThumbnail = BitmapForImage.GetThumbnailImage(Convert.ToInt16(WidthUnit.Value), Convert.ToInt16(HeightUnit.Value), myCallback, IntPtr.Zero);
                //Create memory stream and save resized image into memory stream
                MemoryStream objMemoryStream = new MemoryStream();
                if (ImageUrl.EndsWith(".png"))
                {
                    context.Response.ContentType = "image/png";
                    CurrentThumbnail.Save(objMemoryStream, System.Drawing.Imaging.ImageFormat.Png);
                }
                else if (ImageUrl.EndsWith(".jpg"))
                {
                    context.Response.ContentType = "image/jpeg";
                    CurrentThumbnail.Save(objMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                }
                else if (ImageUrl.EndsWith(".gif"))
                {
                    context.Response.ContentType = "image/gif";
                    CurrentThumbnail.Save(objMemoryStream, System.Drawing.Imaging.ImageFormat.Gif);
                }

                //Declare byte array of size memory stream and read memory stream data into array
                byte[] imageData = new byte[objMemoryStream.Length];
                objMemoryStream.Position = 0;
                objMemoryStream.Read(imageData, 0, (int)objMemoryStream.Length);

                //send contents of byte array as response to client (browser)
                context.Response.BinaryWrite(imageData);
            }
        }
        else
        {
            //if width and height was not passed as querystring, then send image as it is from path provided.
            context.Response.WriteFile(context.Server.MapPath(ImageUrl));
        }
    }
示例#16
0
 /// <summary>
 /// Generate a thumbnail image, for uploaded files
 /// </summary>
 /// <param name="SourceImagePath">The path of the source image</param>
 /// <param name="TargetImagePath">The path of the target thumbnail image</param>
 /// <remarks></remarks>
 public static void GenerateThumbnail(string SourceImagePath, string TargetImagePath)
 {
     using (Image image1 = Image.FromFile(SourceImagePath))
     {
       short num1 = (short) Math.Round((double) (image1.Height * 0.25));
       short num2 = (short) Math.Round((double) (image1.Width * 0.25));
       Image.GetThumbnailImageAbort abort1 = new Image.GetThumbnailImageAbort(ImageHandling.ThumbnailCallback);
       using (Image image2 = image1.GetThumbnailImage(num2, num1, abort1, IntPtr.Zero))
       {
     image2.Save(TargetImagePath, ImageFormat.Gif);
       }
     }
 }
        /// <summary>
        /// Creates a thumbnail from the image provided, scaled down to the
        /// new height specified while keeping the aspect ratio
        /// </summary>
        /// <param name="fullImage">The image to replicate</param>
        /// <param name="newHeight">The new height to scale to</param>
        /// <returns>Returns a thumbnail Image</returns>
        public Image CreateThumbnail(Image fullImage, int newHeight)
        {
            Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
            int newWidth;
            if (fullImage.Height > fullImage.Width)
            {
                newWidth = Convert.ToInt32(Math.Round((double) ((fullImage.Height/fullImage.Width)*newHeight)));
            }
            else
            {
                newWidth = Convert.ToInt32(Math.Round((double) ((fullImage.Width/fullImage.Height)*newHeight)));
            }

            return fullImage.GetThumbnailImage(newWidth, newHeight, myCallback, IntPtr.Zero);
        }
示例#18
0
 /// <summary>  
 /// 生成缩略图,返回缩略图的Image对象  
 /// </summary>  
 /// <param name="path">原图片全路径</param> 
 /// <param name="percent">缩略图的宽度百分比 如:需要百分之80,就填0.8</param>    
 /// <returns>缩略图的Image对象</returns>  
 public static Image GetThumbnail(string path,double percent)
 {
     try
     {
         Image resourceImage = Image.FromFile(path);//获取原图
         Image.GetThumbnailImageAbort callb = new Image.GetThumbnailImageAbort(ThumbnailCallback);
         int width = Convert.ToInt32(resourceImage.Width * percent);
         int height = Convert.ToInt32(resourceImage.Width * percent);
         return resourceImage.GetThumbnailImage(width, height, callb, IntPtr.Zero);
     }
     catch
     {
         return null;
     }
 }
示例#19
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "Jpeg Files (*.jpg)|*.jpg|All Files (*.*)|*.*";
            if (dlg.ShowDialog(this) == DialogResult.OK)
            {
                try
                {

                    Bitmap myBmp = new Bitmap(dlg.FileName);

                    Image.GetThumbnailImageAbort myCallBack = new Image.GetThumbnailImageAbort(ThumbnailCallBack);
                    Image imgPreview = myBmp.GetThumbnailImage(200, 200, myCallBack, IntPtr.Zero);

                    MemoryStream ms = new MemoryStream();
                    imgPreview.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

                    ms.Flush();
                    ms.Seek(0, SeekOrigin.Begin);

                    BinaryReader br=new BinaryReader(ms);

                    byte[] image = br.ReadBytes((int)ms.Length);

                    SqlCommand comm = new SqlCommand();
                    comm.Connection = conn;
                    comm.CommandText = @"INSERT INTO tbImages (Path, ImgPreView) VALUES (@Path, @Image)";
                    comm.Parameters.Add("@Path", SqlDbType.NChar, 260).Value = dlg.FileName;
                    comm.Parameters.Add("@Image", SqlDbType.Image, image.Length).Value = image;

                    comm.ExecuteNonQuery();

                    ms.Close();             

                   
                }
                catch (SqlException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally 
                {
                   

                }
            }
        }
示例#20
0
        /// <summary>
        /// 生成缩略图重载方法1,返回缩略图的Image对象
        /// </summary>
        /// <param name="Width">缩略图的宽度</param>
        /// <param name="Height">缩略图的高度</param>
        /// <returns>缩略图的Image对象</returns>
        public Image GetReducedImage(int Width, int Height)
        {
            try
            {
                Image ReducedImage;

                Image.GetThumbnailImageAbort callb = new Image.GetThumbnailImageAbort(ThumbnailCallback);

                ReducedImage = ResourceImage.GetThumbnailImage(Width, Height, callb, IntPtr.Zero);

                return ReducedImage;
            }
            catch (Exception e)
            {
                ErrMessage = e.Message;
                return null;
            }
        }
        public static void SaveImage(Image image, string savedName, int width = 0, int height = 0)
        {
            Image originalImage = image;
            string filePath = AppDomain.CurrentDomain.BaseDirectory + savedName;

            if (width > 0 && height > 0)
            {
                var myCallback =
                new Image.GetThumbnailImageAbort(ThumbnailCallback);
                Image imageToSave = originalImage.GetThumbnailImage
                    (width, height, myCallback, IntPtr.Zero);
                imageToSave.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            else
            {
                originalImage.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        }
示例#22
0
        public static void SaveImage(string imagePath, string savedName,ImageFormat format, Size size)
        {
            Image originalImage = Image.FromFile(imagePath);
            string filePath = AppDomain.CurrentDomain.BaseDirectory + savedName;

            if (size.Width > 0 && size.Height > 0)
            {
                var myCallback =
                new Image.GetThumbnailImageAbort(ThumbnailCallback);
                var imageToSave = originalImage.GetThumbnailImage
                    (size.Width, size.Height, myCallback, IntPtr.Zero);
                imageToSave.Save(filePath, format);
            }
            else
            {
                originalImage.Save(filePath, ImageFormat.Jpeg);
            }
        }
示例#23
0
        public static Image CreateThumbnails(string inputFile)
        {
            Image pThumbnail = null;

            try
            {
                Image.GetThumbnailImageAbort callback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
                Image image = new Bitmap(inputFile);

                //TODO Resize function
                pThumbnail = image.GetThumbnailImage(100, 150, callback, new IntPtr());
            }
            catch (Exception e)
            {
                return pThumbnail;
            }

            return pThumbnail;
        }
示例#24
0
        public Image getReducedImage(int width, int height)
        {
            Image ReducedImage = null;
            try
            {
                Image.GetThumbnailImageAbort call = new Image.GetThumbnailImageAbort(ThumbnailCallback);

                ReducedImage = ResourceImage.GetThumbnailImage(width, height, call, IntPtr.Zero);

                return ReducedImage;
            }
            catch
            {
                return null;
            }
            finally
            {
                ReducedImage.Dispose();
                ResourceImage.Dispose();
            }
        }
示例#25
0
        /// <summary>
        /// 生成缩略图重载方法2,将缩略图文件保存到指定的路径
        /// </summary>
        /// <param name="Width">缩略图的宽度</param>
        /// <param name="Height">缩略图的高度</param>
        /// <param name="targetFilePath">缩略图保存的全文件名,(带路径),参数格式:D:Imagesfilename.jpg</param>
        /// <returns>成功返回true,否则返回false</returns>
        public bool GetReducedImage(int Width, int Height, string targetFilePath)
        {
            try
            {
                Image ReducedImage;

                Image.GetThumbnailImageAbort callb = new Image.GetThumbnailImageAbort(ThumbnailCallback);

                ReducedImage = ResourceImage.GetThumbnailImage(Width, Height, callb, IntPtr.Zero);
                ReducedImage.Save(@targetFilePath, ImageFormat.Jpeg);

                ReducedImage.Dispose();

                return true;
            }
            catch (Exception e)
            {
                ErrMessage = e.Message;
                return false;
            }
        }
        public ActionResult Upload(HttpPostedFileBase[] file1)
        {
            foreach (var file in file1)
            {
                if (file.ContentLength < 0)
                    continue;

                string appPath = HttpContext.Request.PhysicalApplicationPath;
                string savaFolder = @"\Images\" + 1 + @"\" + 1 + @"\Temp\";
                string saveDir = appPath + savaFolder;

                string ext = file.FileName.Substring(file.FileName.LastIndexOf("."));
                string newFileName = string.Format("{0}-{1}-{2}-{3}-{4}{5}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Minute, DateTime.Now.Millisecond, ext);

                string fileUrl = saveDir + newFileName;

                Directory.CreateDirectory(saveDir);
                file.SaveAs(fileUrl);

                Image.GetThumbnailImageAbort callBack =new Image.GetThumbnailImageAbort(ThumbnailCallback);

                Bitmap image = new Bitmap(fileUrl);
                int[] thumbnailScale = getThumbnailImageScale(1280, 1280, image.Width, image.Height);
                Image smallImage = image.GetThumbnailImage(thumbnailScale[0], thumbnailScale[1], callBack, IntPtr.Zero);

                string savaFolder2 = @"\Images2\" + 1 + @"\" + 1 + @"\Temp\";
                string saveDir2 = appPath + savaFolder2;

                string newFileName2 = string.Format("{0}-{1}-{2}-{3}-{4}{5}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Minute, DateTime.Now.Millisecond, ext);

                string fileUrl2 = saveDir2 + newFileName2;

                Directory.CreateDirectory(saveDir2);
                smallImage.Save(fileUrl2);

            }

            return View();
        }
示例#27
0
        public Image GetRectangleImage(List<Image> images)
        {
            Bitmap bitMap = new Bitmap(
                ColumnCount * SingleImage.Width + ColumnCount * Padding,
                images.Count % ColumnCount == 0 ?
                (images.Count / ColumnCount * SingleImage.Height + ColumnCount * Padding) :
                (images.Count / ColumnCount * SingleImage.Height + SingleImage.Height + ColumnCount * Padding));

            Graphics grp = Graphics.FromImage(bitMap);
            Pen pen = new Pen(BackGroundColor);
            pen.Width = bitMap.Height;
            grp.DrawRectangle(pen,
                new Rectangle(new Point(0, 0),
                new Size(bitMap.Width, bitMap.Height)));

            for (int i = 0; i < images.Count; i++)
            {
                Image.GetThumbnailImageAbort call = new Image.GetThumbnailImageAbort(GetThumbnailImageAbort);

                var thumbnailImage = images[i].GetThumbnailImage(SingleImage.Width,
                    SingleImage.Height,
                    call,
                    IntPtr.Zero);

                var point = new Point(
                    (i % ColumnCount * SingleImage.Width),
                    (i / ColumnCount * SingleImage.Height));

                point.Offset(new Point(i % ColumnCount * this.Padding, i / ColumnCount * this.Padding));

                grp.DrawImage(thumbnailImage, point);
            }

            grp.Dispose();

            return bitMap;
        }
        private static void AddThumbnail(string blobUri, string fileName)
        {
            try
            {
                var stream = Storage.Blob.GetBlob(blobUri);

                if (blobUri.EndsWith(".jpg"))
                {
                    var image = Image.FromStream(stream);
                    var myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
                    var thumbnailImage = image.GetThumbnailImage(42, 32, myCallback, IntPtr.Zero);
                    thumbnailImage.Save(stream, ImageFormat.Jpeg);
                    Storage.Blob.PutBlob(stream, "thumbnail-" + fileName);
                }
                else
                {
                    Storage.Blob.PutBlob(stream, fileName);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Error", ex.ToString());
            }
        }
示例#29
0
        public Image GetFullScreenImage(VideoParameters v)
        {
            try
            {
                System.Drawing.Image MyImage = new Bitmap((int)SystemParameters.VirtualScreenWidth, (int)SystemParameters.VirtualScreenHeight);
                CURSORINFO pci;
                pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
                GetCursorInfo(out pci);
                Graphics g = Graphics.FromImage(MyImage);
                g.CopyFromScreen(new System.Drawing.Point(0, 0), new System.Drawing.Point(0, 0), new System.Drawing.Size((int)SystemParameters.VirtualScreenWidth, (int)SystemParameters.VirtualScreenHeight));

                System.Windows.Forms.Cursor cur = new System.Windows.Forms.Cursor(pci.hCursor);
                cur.Draw(g, new System.Drawing.Rectangle(pci.ptScreenPos.x - 10, pci.ptScreenPos.y - 10, cur.Size.Width, cur.Size.Height));

                Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
                MyImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
                Image img = MyImage.GetThumbnailImage(v.Height, v.Width, myCallback, IntPtr.Zero);
                return img;
            }
            catch
            {
                throw;
            }
        }
 public static Image ToThumbnail(this Image image)
 {
     Image.GetThumbnailImageAbort callback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
     return(image.GetThumbnailImage(100, 100, callback, new IntPtr()));
 }
示例#31
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="grad"></param>
        /// <param name="registracija"></param>
        /// <param name="filter">
        /// bit 0 -> opažanja kojima NIJE prošao "grace period"
        /// bit 1 -> opažanja kojima JE prošao "grace period"
        /// bit 2 -> izdane parkirne karte
        /// </param>
        /// <param name="idDjelatnika"></param>
        /// <param name="idSektora"></param>
        /// <param name="index"></param>
        /// <param name="count"></param>
        /// <param name="idAplikacije"></param>
        /// <returns></returns>
        public static __Opazanje[] TraziOpazanje(string grad, string registracija, int filter, int?idDjelatnika, int?idSektora, int index, int count, int idAplikacije)
        {
            int  zastaraOpazanja = 4; // broj sati nakon kojih ne prikazuje opažanje
            bool op1, op2, kaznjeni;

            op1      = (filter & 0x01) != 0;
            op2      = (filter & 0x02) != 0;
            kaznjeni = (filter & 0x04) != 0;
            if (count <= 0)
            {
                count = int.MaxValue;
            }

            try
            {
                List <_2DLista> statusi = Parking.Statusi(false, idAplikacije);

                bool contains = false;
                if (registracija != null && registracija.StartsWith("~"))
                {
                    contains     = true;
                    registracija = registracija.Replace("~", "");
                }
                if (registracija == null)
                {
                    registracija = "";
                }
                else
                {
                    registracija = registracija.Replace("-", "").Replace(" ", "").ToUpper().Replace("Č", "C").Replace("Ć", "C").Replace("Ž", "Z").Replace("Š", "S").Replace("Đ", "D");
                }

                using (PazigradDataContext db = new PazigradDataContext(Sistem.ConnectionString(grad, idAplikacije)))
                {
                    var op = from o in db.PARKING_OPAZANJAs
                             join d in db.Djelatniks on o.IDDjelatnika equals d.IDDjelatnika into djelatnik
                             from dd in djelatnik.DefaultIfEmpty()
                             join s in db.PARKING_SEKTORIs on o.IDSektora equals s.IDSektora into sektori
                             from ss in sektori.DefaultIfEmpty()
                             join z in db.PARKING_ZONEs on ss.IDZone equals z.IDZone into zone
                             from zz in zone.DefaultIfEmpty()
                             where (!string.IsNullOrEmpty(registracija) ? ((!contains) ? o.Registracija.Replace("-", "").Replace(" ", "").ToUpper().Replace("Č", "C").Replace("Ć", "C").Replace("Ž", "Z").Replace("Š", "S").Replace("Đ", "D") == registracija
                             : o.Registracija.Replace("-", "").Replace(" ", "").ToUpper().Replace("Č", "C").Replace("Ć", "C").Replace("Ž", "Z").Replace("Š", "S").Replace("Đ", "D").Contains(registracija)) : registracija == "") &&
                             ((DateTime.Now - o.Vrijeme.Value).TotalHours <= zastaraOpazanja || (o.PlacenoDo != null && o.PlacenoDo.Value > DateTime.Now)) &&
                             (o.Otisao == null || o.Otisao.Value != true) &&
                             //(o.PlacenoDo == null || DateTime.Now < o.PlacenoDo) &&
                             (
                        (kaznjeni && o.Kaznjen == true) ||
                        (op1 && o.Kaznjen != true && (DateTime.Now - o.Vrijeme.Value).TotalMinutes < zz.GracePeriod) ||
                        (op2 && o.Kaznjen != true && (DateTime.Now - o.Vrijeme.Value).TotalMinutes >= zz.GracePeriod)
                             ) &&
                             (idDjelatnika != null && idDjelatnika > 0 ? o.IDDjelatnika == idDjelatnika : true) &&
                             (idSektora == null || idSektora <= 0 ? true : o.IDSektora == idSektora)
                             orderby o.Vrijeme descending
                             select new __Opazanje(o.IDOpazanja, o.IDLokacije, o.IDSektora, ss.IDZone, o.IDDjelatnika, 0, o.IDStatusa, o.IDRacuna, ss.NazivSektora, dd.ImePrezime, zz.NazivZone,
                                                   Parking.Status(o.IDStatusa, statusi), o.Registracija, o.Drzava, (DateTime)o.Vrijeme, o.PlacenoDo, o.Latitude, o.Longitude, o.Iznos, o.Kaznjen.Value, (o.Otisao == null) ? false : o.Otisao.Value, "", "");



                    __Opazanje[] opazanja;
                    __Opazanje[] ops = op.ToArray();



                    int len = (count > 0) ? Math.Min(count, ops.Length - index) : Math.Max(0, ops.Length - index);
                    opazanja = new __Opazanje[len];
                    Array.Copy(ops, index, opazanja, 0, len);

                    for (int i = 0; i < opazanja.Length; i++)
                    {
                        __Opazanje o = opazanja[i];
                        o.Index = i + index;
                        o.Total = ops.Length;
                    }

                    foreach (var opazanje in opazanja)
                    {
                        List <string> slike64 = new List <string>();
                        var           slika   = (from s in db.SlikaPrekrsajas
                                                 where s.IDLokacije == opazanje.IDLokacije
                                                 select s.Slika).FirstOrDefault();
                        if (slika != null && slika.Length > 0)
                        {
                            try
                            {
                                //Bitmap b = new Bitmap(new MemoryStream(slika.ToArray()));
                                //Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
                                //Image myThumbnail = b.GetThumbnailImage(64, 64, myCallback, IntPtr.Zero);
                                //var bytes = new MemoryStream();
                                //myThumbnail.Save(bytes, ImageFormat.Jpeg);
                                //slike64.Add(Convert.ToBase64String(bytes.ToArray()));
                                //break;
                                Bitmap b = new Bitmap(new MemoryStream(slika.ToArray()));
                                int    maxPixelDimension = 240;
                                int    w = b.Width, h = b.Height;

                                if (w > h)
                                {
                                    h = h * maxPixelDimension / w;
                                    w = maxPixelDimension;
                                }
                                else
                                {
                                    w = w * maxPixelDimension / h;
                                    h = maxPixelDimension;
                                }
                                Image.GetThumbnailImageAbort myCallback = ThumbnailCallback;
                                Image myThumbnail = b.GetThumbnailImage(w, h, myCallback, IntPtr.Zero);
                                var   bytes = new MemoryStream();
                                myThumbnail.Save(bytes, ImageFormat.Jpeg);
                                slike64.Add(Convert.ToBase64String(bytes.ToArray()));
                                //break;
                            }
                            catch (Exception ex)
                            {
                                Sustav.SpremiGresku(grad, ex, idAplikacije, "Thumbnail slikice...");
                            }
                        }

                        opazanje.Slike = slike64;
                    }
                    return(opazanja);
                }
            }
            catch (Exception ex)
            {
                Sustav.SpremiGresku(grad, ex, idAplikacije, "PRETRAGA OPAZANJA");
                return(new __Opazanje[0]);
            }
        }
示例#32
0
        public Boolean addSpot(String json)
        {
            try
            {
                SpotRootObject rootObj = JsonConvert.DeserializeObject <SpotRootObject>(json);
                SpotModel      key     = rootObj.key;

                //Add spot into spot.xml
                String      spotXml = HttpContext.Current.Server.MapPath("~/App_Data/Spot.xml");
                XmlDocument xmlDoc  = new XmlDocument();
                xmlDoc.Load(spotXml);

                //create a new spot element and set value or attribute
                XmlElement spot = xmlDoc.CreateElement("Spot");
                spot.SetAttribute("Name", Security.Encryption(key.name));
                xmlDoc.SelectSingleNode("/Spots").AppendChild(spot);

                // location
                XmlElement location = xmlDoc.CreateElement("Location");
                spot.AppendChild(location);

                XmlElement state = xmlDoc.CreateElement("State");
                state.InnerText = Security.Encryption(key.location.state);
                location.AppendChild(state);

                XmlElement city = xmlDoc.CreateElement("City");
                city.InnerText = Security.Encryption(key.location.city);
                location.AppendChild(city);

                XmlElement zipcode = xmlDoc.CreateElement("ZipCode");
                zipcode.InnerText = Security.Encryption(key.location.zipcode);
                location.AppendChild(zipcode);

                // image stream save as jpg file
                Image img       = Image.FromStream(new MemoryStream(key.imgBytes));
                var   ratio     = (double)225 / img.Height;
                int   imgHeight = (int)(img.Height * ratio);
                int   imgWidth  = (int)(img.Width * ratio);

                Image.GetThumbnailImageAbort dCallBack = new Image.GetThumbnailImageAbort(ThumbnailCallback);
                Image  thumbnailImg = img.GetThumbnailImage(imgWidth, imgHeight, dCallBack, IntPtr.Zero);
                String imgFile      = key.name + ".jpg";
                thumbnailImg.Save(Path.Combine(HttpContext.Current.Server.MapPath("~/Thumbnail"), imgFile), ImageFormat.Jpeg);
                thumbnailImg.Dispose();

                // introduction
                XmlElement intro = xmlDoc.CreateElement("Introduction");
                intro.InnerText = Security.Encryption(key.introduction);
                spot.AppendChild(intro);

                // price
                XmlElement price = xmlDoc.CreateElement("Price");
                price.InnerText = Security.Encryption(key.price);
                spot.AppendChild(price);

                xmlDoc.Save(spotXml);

                return(true);
            }
            catch { return(false); }
        }
        protected void ShowThumbnail(string path, int width, int height)
        {
            CheckPath(path);
            FileStream fs  = new FileStream(FixPath(path), FileMode.Open);
            Bitmap     img = new Bitmap(Bitmap.FromStream(fs));

            fs.Close();
            fs.Dispose();
            int cropWidth = img.Width, cropHeight = img.Height;
            int cropX = 0, cropY = 0;

            double imgRatio = (double)img.Width / (double)img.Height;

            if (height == 0)
            {
                height = Convert.ToInt32(Math.Floor((double)width / imgRatio));
            }

            if (width > img.Width)
            {
                width = img.Width;
            }
            if (height > img.Height)
            {
                height = img.Height;
            }

            double cropRatio = (double)width / (double)height;

            cropWidth  = Convert.ToInt32(Math.Floor((double)img.Height * cropRatio));
            cropHeight = Convert.ToInt32(Math.Floor((double)cropWidth / cropRatio));
            if (cropWidth > img.Width)
            {
                cropWidth  = img.Width;
                cropHeight = Convert.ToInt32(Math.Floor((double)cropWidth / cropRatio));
            }
            if (cropHeight > img.Height)
            {
                cropHeight = img.Height;
                cropWidth  = Convert.ToInt32(Math.Floor((double)cropHeight * cropRatio));
            }
            if (cropWidth < img.Width)
            {
                cropX = Convert.ToInt32(Math.Floor((double)(img.Width - cropWidth) / 2));
            }
            if (cropHeight < img.Height)
            {
                cropY = Convert.ToInt32(Math.Floor((double)(img.Height - cropHeight) / 2));
            }

            Rectangle area    = new Rectangle(cropX, cropY, cropWidth, cropHeight);
            Bitmap    cropImg = img.Clone(area, System.Drawing.Imaging.PixelFormat.DontCare);

            img.Dispose();
            Image.GetThumbnailImageAbort imgCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);

            _r.AddHeader("Content-Type", "image/png");
            cropImg.GetThumbnailImage(width, height, imgCallback, IntPtr.Zero).Save(_r.OutputStream, ImageFormat.Png);
            _r.OutputStream.Close();
            cropImg.Dispose();
        }
示例#34
0
 internal static extern int GdipGetImageThumbnail(HandleRef image, int thumbWidth, int thumbHeight, out IntPtr thumbImage, Image.GetThumbnailImageAbort callback, IntPtr callbackdata);
示例#35
0
        /// <summary>
        /// This event occurs when the selected item is changed
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstItems_SelectedValueChanged(object sender, EventArgs e)
        {
            // check if we wish to save?

            // load data -- panel 1
            listMusicItem sel = (listMusicItem)lstItems.SelectedItem;

            txtAlbum.Text  = sel.album;
            txtArtist.Text = sel.artist;
            txtTitle.Text  = sel.title;

            if (sel.ytCat != "")
            {
                cmbYTCat.SelectedItem = sel.ytCat;
            }
            else
            {
                cmbYTCat.SelectedItem = null;
            }

            sel.ytTags = txtYTTags.Text;
            sel.wpTags = txtWPTags.Text;

            // load data -- panel 2
            System.Drawing.Image.GetThumbnailImageAbort d = new Image.GetThumbnailImageAbort(ImageAborted);
            if (sel.bg != "")
            {
                Image img = Image.FromFile(sel.bg, true);
                btnVideoBG.Image = img.GetThumbnailImage(195, 162, d, System.IntPtr.Zero);
                btnVideoBG.Text  = "";
                txtBGpath.Text   = sel.bg;
            }
            else
            {
                btnVideoBG.Image = null;
                btnVideoBG.Text  = "n/a";
                txtBGpath.Text   = "";
            }

            if (sel.images.Length > 0 && sel.images[0] != null)
            {
                // we'll just load the first image...
                Image img = sel.images[0];
                btnAlbumArt.Image = img.GetThumbnailImage(195, 162, d, System.IntPtr.Zero);
                btnAlbumArt.Text  = "";
                txtBGpath.Text    = "";
            }
            else if (sel.customAlbumArt)
            {
                // see if there is an image path specified
                Image img = Image.FromFile(sel.albumArt);
                btnAlbumArt.Image = img.GetThumbnailImage(195, 162, d, System.IntPtr.Zero);
                btnAlbumArt.Text  = "";
                txtAlbumPath.Text = sel.albumArt;
            }
            else
            {
                btnAlbumArt.Image = null;
                btnAlbumArt.Text  = "n/a";
                txtAlbumPath.Text = "";
            }

            // load data -- panel 3+4
            if (sel.WPPost == "")
            {
                txtWPPost.Text = Properties.Settings.Default.wpPost;
            }
            else
            {
                txtYTDesc.Text = sel.WPPost;
            }

            if (sel.YTDesc == "")
            {
                txtYTDesc.Text = Properties.Settings.Default.ytDesc;
            }
            else
            {
                txtYTDesc.Text = sel.YTDesc;
            }
        }
示例#36
0
        /// <summary>
        /// Creates a thumbnail of the specified image
        /// </summary>
        /// <param name="aDrawingImage">The source System.Drawing.Image</param>
        /// <param name="aThumbTargetPath">Filename of the thumbnail to create</param>
        /// <param name="aThumbWidth">Maximum width of the thumbnail</param>
        /// <param name="aThumbHeight">Maximum height of the thumbnail</param>
        /// <param name="aRotation">
        /// 0 = no rotate
        /// 1 = rotate 90 degrees
        /// 2 = rotate 180 degrees
        /// 3 = rotate 270 degrees
        /// </param>
        /// <param name="aFastMode">Use low quality resizing without interpolation suitable for small thumbnails</param>
        /// <returns>Whether the thumb has been successfully created</returns>
        private static bool CreateThumbnail(Image aDrawingImage, string aThumbTargetPath, int aThumbWidth, int aThumbHeight,
                                            int aRotation, bool aFastMode)
        {
            if (string.IsNullOrEmpty(aThumbTargetPath) || aThumbHeight <= 0 || aThumbHeight <= 0)
            {
                return(false);
            }

            Bitmap myBitmap      = null;
            Image  myTargetThumb = null;

            try
            {
                switch (aRotation)
                {
                case 1:
                    aDrawingImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    break;

                case 2:
                    aDrawingImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    break;

                case 3:
                    aDrawingImage.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    break;

                default:
                    break;
                }

                int   iWidth  = aThumbWidth;
                int   iHeight = aThumbHeight;
                float fAR     = (aDrawingImage.Width) / ((float)aDrawingImage.Height);

                if (aDrawingImage.Width > aDrawingImage.Height)
                {
                    iHeight = (int)Math.Floor((((float)iWidth) / fAR));
                }
                else
                {
                    iWidth = (int)Math.Floor((fAR * ((float)iHeight)));
                }

                /*try
                 * {
                 * Utils.FileDelete(aThumbTargetPath);
                 * }
                 * catch (Exception ex)
                 * {
                 * Log.Error("Picture: Error deleting old thumbnail - {0}", ex.Message);
                 * }*/

                if (aFastMode)
                {
                    Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
                    myBitmap      = new Bitmap(aDrawingImage, iWidth, iHeight);
                    myTargetThumb = myBitmap.GetThumbnailImage(iWidth, iHeight, myCallback, IntPtr.Zero);
                }
                else
                {
                    myBitmap = new Bitmap(iWidth, iHeight, aDrawingImage.PixelFormat);
                    //myBitmap.SetResolution(aDrawingImage.HorizontalResolution, aDrawingImage.VerticalResolution);
                    using (Graphics g = Graphics.FromImage(myBitmap))
                    {
                        g.CompositingQuality = Thumbs.Compositing;
                        g.InterpolationMode  = Thumbs.Interpolation;
                        g.SmoothingMode      = Thumbs.Smoothing;
                        g.DrawImage(aDrawingImage, new Rectangle(0, 0, iWidth, iHeight));
                        myTargetThumb = myBitmap;
                    }
                }

                return(SaveThumbnail(aThumbTargetPath, myTargetThumb));
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                if (myTargetThumb != null)
                {
                    myTargetThumb.Dispose();
                }
                if (myBitmap != null)
                {
                    myBitmap.Dispose();
                }
            }
        }
示例#37
0
    /// <summary>
    /// Creates a thumbnail of the specified image
    /// </summary>
    /// <param name="aDrawingImage">The source System.Drawing.Image</param>
    /// <param name="aThumbTargetPath">Filename of the thumbnail to create</param>
    /// <param name="aThumbWidth">Maximum width of the thumbnail</param>
    /// <param name="aThumbHeight">Maximum height of the thumbnail</param>
    /// <param name="aRotation">
    /// 0 = no rotate
    /// 1 = rotate 90 degrees
    /// 2 = rotate 180 degrees
    /// 3 = rotate 270 degrees
    /// </param>
    /// <param name="aFastMode">Use low quality resizing without interpolation suitable for small thumbnails</param>
    /// <returns>Whether the thumb has been successfully created</returns>
    public static bool CreateThumbnail(Image aDrawingImage, string aThumbTargetPath, int aThumbWidth, int aThumbHeight,
                                       int aRotation, bool aFastMode)
    {
      bool result = false;
      if (string.IsNullOrEmpty(aThumbTargetPath) || aThumbHeight <= 0 || aThumbHeight <= 0) return false;

      Bitmap myBitmap = null;
      Image myTargetThumb = null;

      try
      {
        switch (aRotation)
        {
          case 1:
            aDrawingImage.RotateFlip(RotateFlipType.Rotate90FlipNone);
            break;
          case 2:
            aDrawingImage.RotateFlip(RotateFlipType.Rotate180FlipNone);
            break;
          case 3:
            aDrawingImage.RotateFlip(RotateFlipType.Rotate270FlipNone);
            break;
          default:
            break;
        }

        int iWidth = aThumbWidth;
        int iHeight = aThumbHeight;
        float fAR = (aDrawingImage.Width) / ((float)aDrawingImage.Height);

        if (aDrawingImage.Width > aDrawingImage.Height)
          iHeight = (int)Math.Floor((((float)iWidth) / fAR));
        else
          iWidth = (int)Math.Floor((fAR * ((float)iHeight)));

        try
        {
          Utils.FileDelete(aThumbTargetPath);
        }
        catch (Exception ex)
        {
          Log.Error("Picture: Error deleting old thumbnail - {0}", ex.Message);
        }

        if (aFastMode)
        {
          Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
          myBitmap = new Bitmap(aDrawingImage, iWidth, iHeight);
          myTargetThumb = myBitmap.GetThumbnailImage(iWidth, iHeight, myCallback, IntPtr.Zero);
        }
        else
        {
          PixelFormat format = aDrawingImage.PixelFormat;
          switch (format)
          {
            case PixelFormat.Format1bppIndexed:
            case PixelFormat.Format4bppIndexed:
            case PixelFormat.Format8bppIndexed:
            case PixelFormat.Undefined:
            case PixelFormat.Format16bppArgb1555:
            case PixelFormat.Format16bppGrayScale:
              format = PixelFormat.Format32bppRgb;
              break;
          }
          myBitmap = new Bitmap(iWidth, iHeight, format);
          //myBitmap.SetResolution(aDrawingImage.HorizontalResolution, aDrawingImage.VerticalResolution);
          using (Graphics g = Graphics.FromImage(myBitmap))
          {
            g.CompositingQuality = Thumbs.Compositing;
            g.InterpolationMode = Thumbs.Interpolation;
            g.SmoothingMode = Thumbs.Smoothing;
            g.DrawImage(aDrawingImage, new Rectangle(0, 0, iWidth, iHeight));
            myTargetThumb = myBitmap;
          }
        }

        if (MediaPortal.Player.g_Player.Playing)
          Thread.Sleep(30);

        result = SaveThumbnail(aThumbTargetPath, myTargetThumb);
      }
      catch (Exception)
      {
        result = false;
      }
      finally
      {
        if (myTargetThumb != null)
          myTargetThumb.SafeDispose();
        if (myBitmap != null)
          myBitmap.SafeDispose();
      }

      if (result && Utils.IsFileExistsCacheEnabled())
      {
        Log.Debug("CreateThumbnail : FileExistsInCache updated with new file: {0}", aThumbTargetPath);
        Utils.DoInsertExistingFileIntoCache(aThumbTargetPath);
      }
      return result;
    }
示例#38
0
 /// <summary>
 /// The resize image.
 /// </summary>
 /// <param name="img">
 /// The img.
 /// </param>
 /// <param name="width">
 /// The width.
 /// </param>
 /// <param name="height">
 /// The height.
 /// </param>
 /// <returns>
 /// Returns the Resized Bitmap
 /// </returns>
 private Bitmap ResizeImage(Image img, int width, int height)
 {
     Image.GetThumbnailImageAbort callback = GetThumbAbort;
     return((Bitmap)img.GetThumbnailImage(width, height, callback, IntPtr.Zero));
 }