Пример #1
0
        public Bitmap GetBackgroundImage()
        {
            Bitmap    image = null;
            Graphics  graphics;
            Rectangle bounds = this._homeScreen.Bounds;

            if (Settings.Default.UseBackgroundColor)
            {
                image = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
                using (graphics = Graphics.FromImage(image))
                {
                    graphics.Clear(Settings.Default.BackgroundColor);
                }
                return(image);
            }
            if (Settings.Default.UseBackgroundImage)
            {
                return(PhotoInfo.ConstrainSize((Bitmap)Image.FromFile(Settings.Default.BackgroundImage), bounds.Width, bounds.Height, false));
            }
            image = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb);
            using (graphics = Graphics.FromImage(image))
            {
                graphics.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy);
            }
            return(image);
        }
        private void RenderCaption(PhotoInfo originalPhoto, int trueImageWidth, Graphics g)
        {
            Font         captionFont = Settings.Default.CaptionFont;
            Rectangle    layoutRect  = new Rectangle(2, this.imageHeight + (this.imageBuffer * 2), trueImageWidth - 4, (int)(this.imageBuffer * 2.5));
            GraphicsPath path        = new GraphicsPath();

            path.AddString(originalPhoto.Caption, captionFont.FontFamily, (int)captionFont.Style, (float)captionFont.Height, layoutRect, this.captionFormat);
            g.FillPath(Brushes.Black, path);
        }
Пример #3
0
 private void ShuffleFiles()
 {
     lock (this.photos)
     {
         int num = 0;
         for (int i = 0; i < (this.photos.Count - 1); i++)
         {
             while (num == i)
             {
                 num = this.rnd.Next(0, this.photos.Count);
             }
             PhotoInfo info = this.photos[i];
             this.photos[i]   = this.photos[num];
             this.photos[num] = info;
             num = i + 1;
         }
     }
 }
        public void ImageUpdater()
        {
            if (this.CurrentImageUpdated != null)
            {
                this.CurrentImageUpdated(this, null);
            }

            while (true)
            {
                using (Graphics graphics = Graphics.FromImage(this._desktopPhotoPile))
                {
                    if ((Environment.TickCount - this.lastResetTime) > this.resetInterval)
                    {
                        this._desktopPhotoPile = new Bitmap(this._desktopImage);
                        this.lastResetTime     = Environment.TickCount;
                    }
                    PhotoInfo nextImage = this._photoSource.GetNextImage();
                    if (nextImage != null)
                    {
                        try
                        {
                            if (nextImage.WorkingBitmap == null)
                            {
                                this.CreateSnapshotImage(nextImage);
                            }
                            if (nextImage.WorkingBitmap != null)
                            {
                                this.DrawImageRotated(nextImage);
                                if (this.CurrentImageUpdated != null)
                                {
                                    this.CurrentImageUpdated(this, null);
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                }
                Thread.Sleep(this.delayInterval);
            }
        }
        private void CreateSnapshotImage(PhotoInfo originalPhoto)
        {
            int height = (this.imageBuffer + this.imageHeight) + this.imageBuffer;
            int width  = (this.imageBuffer + this.imageWidth) + this.imageBuffer;

            if (Settings.Default.RenderCaption)
            {
                height += this.imageBuffer * 3;
            }
            Bitmap bitmap = new Bitmap(width, height);
            Image  image  = PhotoInfo.ConstrainSize(originalPhoto.SourceBitmap, this.imageWidth, this.imageHeight, true);

            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                PhotoInfo.SetDrawingQuality(graphics);
                graphics.Clear(Color.FromArgb(240, 240, 240));
                graphics.DrawRectangle(new Pen(Brushes.Gray, 3f), 0, 0, bitmap.Width - 1, bitmap.Height - 1);
                switch (ExifSupport.GetExifShort(originalPhoto.SourceBitmap, 0x112, 1))
                {
                case 3:
                    image.RotateFlip(RotateFlipType.Rotate180FlipNone);
                    break;

                case 6:
                    image.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    break;

                case 8:
                    image.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    break;
                }
                graphics.DrawImage(image, this.imageBuffer, this.imageBuffer);
                graphics.DrawRectangle(Pens.LightGray, this.imageBuffer, this.imageBuffer, this.imageWidth - 1, this.imageHeight - 1);
                if (Settings.Default.RenderCaption)
                {
                    this.RenderCaption(originalPhoto, width, graphics);
                }
            }
            originalPhoto.SourceBitmap  = null;
            originalPhoto.WorkingBitmap = bitmap;
        }
Пример #6
0
        private void InitFileListWDS()
        {
            StringBuilder builder = new StringBuilder();

            if (!string.IsNullOrEmpty(Settings.Default.WDSQuery))
            {
                string[] strArray = Settings.Default.WDSQuery.Split(new char[] { ' ', ',', '|', ';' });
                foreach (string str in strArray)
                {
                    if (builder.Length > 0)
                    {
                        builder.Append(" OR ");
                    }
                    builder.AppendFormat(" CONTAINS(*, '\"{0}\"') ", str);
                }
            }
            string str2 = "select TOP 100 System.ItemUrl, System.Title  from systemindex where CONTAINS(System.Kind, 'picture') AND System.Size > 5000 AND System.Size < 2500000";

            if (builder.Length > 0)
            {
                str2 = string.Format("{0} AND ({1})", str2, builder.ToString());
            }
            OleDbCommand command = new OleDbCommand();

            command.Connection  = wdsConn;
            command.CommandText = str2;
            OleDbDataReader reader = command.ExecuteReader();

            this.photos = new List <PhotoInfo>();
            while (reader.Read())
            {
                PhotoInfo item = new PhotoInfo(ConvertUrlToPath(reader.GetString(0)));
                if (!reader.IsDBNull(1))
                {
                    item.Caption = reader.GetString(1).Trim();
                }
                this.photos.Add(item);
            }
            reader.Close();
            this.ShuffleFiles();
        }
        private void DrawImageRotated(PhotoInfo photo)
        {
            int   x     = this.rnd.Next(this._desktopPhotoPile.Width - this.imageWidth);
            int   y     = this.rnd.Next(this._desktopPhotoPile.Height - this.imageHeight);
            float angle = this.rnd.Next(60) - 30;

            using (Graphics graphics = Graphics.FromImage(this._desktopPhotoPile))
            {
                PhotoInfo.SetDrawingQuality(graphics);
                graphics.RotateTransform(angle);
                CompositingMode compositingMode = graphics.CompositingMode;
                graphics.CompositingMode = CompositingMode.SourceOver;
                using (SolidBrush brush = new SolidBrush(Color.FromArgb(70, 30, 30, 30)))
                {
                    int i = 8;
                    //for (int i = 8; i > 0; i--)
                    {
                        graphics.FillRectangle(brush, (int)(x + i), (int)(y + i), (int)(photo.WorkingBitmap.Width - 1), (int)(photo.WorkingBitmap.Height - 1));
                    }
                }
                graphics.CompositingMode = compositingMode;
                graphics.DrawImageUnscaled(photo.WorkingBitmap, x, y);
            }
        }
Пример #8
0
        private void watcher_Triggered(object sender, FileSystemEventArgs e)
        {
            FileInfo info = new FileInfo(e.FullPath);

            if (this.imageExtensions.IndexOf(info.Extension.ToLower()) != -1)
            {
                List <PhotoInfo> list;
                if (e.ChangeType == WatcherChangeTypes.Created)
                {
                    PhotoInfo item = new PhotoInfo(e.FullPath);
                    lock ((list = this.photos))
                    {
                        this.photos.Insert(this.photos.Count, item);
                    }
                }
                else if (e.ChangeType == WatcherChangeTypes.Deleted)
                {
                    lock ((list = this.photos))
                    {
                        PhotoInfo info3 = null;
                        foreach (PhotoInfo info2 in this.photos)
                        {
                            if (info2.Filename == e.FullPath)
                            {
                                info3 = info2;
                                break;
                            }
                        }
                        if (info3 != null)
                        {
                            this.photos.Remove(info3);
                        }
                    }
                }
            }
        }