Exemple #1
0
        private void setImageRect(ImageItem Image, ref Rectangle Rectangle)
        {
            if (Image != null)
            {
                Size s;
                if (Image.AspectRatio > this.aspectRatio)
                {
                    // constrained by width
                    s = new Size(this.Width, (int)((float)this.Width / Image.AspectRatio));

                    Rectangle = new Rectangle(new Point(0, (this.ClientRectangle.Height - s.Height) / 2), s);
                }
                else
                {
                    // constrained by height
                    s         = new Size((int)((float)this.Height * Image.AspectRatio), this.Height);
                    Rectangle = new Rectangle(new Point((this.ClientRectangle.Width - s.Width) / 2, 0), s);
                }
            }
            this.Invalidate();
        }
Exemple #2
0
        private void setCoverDownload()
        {
            if (this.cover == null)
            {
                this.cover = ImageItem.ImageFromLastFM(this.Artist,
                                                       this.Album);

                if (cover != null)
                {
                    switch (controller.ArtSaveOption)
                    {
                    case ArtSaveOption.Artist_Album:
                        this.cover.Save(this.ImageFilePath);
                        break;

                    case ArtSaveOption.Folder_JPG:
                        this.cover.Save(this.ImageFilePath2);
                        break;
                    }
                }
            }
        }
Exemple #3
0
 private void setCoverLocal()
 {
     try
     {
         string fileName = ImageFilePath;
         if (File.Exists(fileName))
         {
             cover = ImageItem.ImageItemFromGraphicsFile(fileName);
         }
         else
         {
             fileName = ImageFilePath2;
             if (File.Exists(fileName))
             {
                 cover = ImageItem.ImageItemFromGraphicsFile(fileName);
             }
         }
     }
     catch
     {
     }
 }
Exemple #4
0
        public static ImageItem ImageItemFromAudioFile(string FilePath)
        {
            if (items.ContainsKey(FilePath))
            {
                return(items[FilePath]);
            }

            ImageItem ii = new ImageItem(FilePath);

            ii.Src = Source.Embedded;

            if (ii.Failed)
            {
                addToItems(FilePath, null);
                return(null);
            }
            else
            {
                addToItems(FilePath, ii);
                return(ii);
            }
        }
Exemple #5
0
        public static ImageItem ImageItemFromDrag(IDataObject Data)
        {
            string s = getGraphicFile(Data);

            if (s.Length > 0)
            {
                return(ImageItemFromGraphicsFile(s));
            }
            else if (Data.GetDataPresent(typeof(Metafile)))
            {
                Image     i  = (Image)Data.GetData(typeof(Metafile));
                ImageItem ii = new ImageItem();
                ii.setImage(i, true);
                ii.Src = Source.Drag;
                return(ii);
            }
            else if (Data.GetDataPresent(typeof(Bitmap)))
            {
                Image i = (Image)Data.GetData(typeof(Bitmap));
                return(ImageItemFromImage(i));
            }
            else if (Data.GetDataPresent(DIB_STRING))
            {
                MemoryStream ms = (MemoryStream)Data.GetData(DIB_STRING);

                Bitmap b = bitmapFromDIB(ms);

                ms.Close();
                ms.Dispose();

                ImageItem ii = ImageItemFromImage(b);
                ii.Src = Source.Drag;
                return(ii);
            }
            else
            {
                return(null);
            }
        }
Exemple #6
0
        private void overlay(Graphics e, ImageItem i, Rectangle rr)
        {
            Color cc = Styles.LightText;

            if (i.AspectRatio < 1.15 && i.Image is Bitmap)
            {
                Bitmap bb = i.Image as Bitmap;
                int    r  = 0;
                int    g  = 0;
                int    b  = 0;
                int    y  = Math.Max(0, i.Image.Height - 7);
                int    w  = i.Image.Width;
                for (int x = 0; x < w; x++)
                {
                    Color c = bb.GetPixel(x, y);
                    r += c.R;
                    g += c.G;
                    b += c.B;
                }
                r /= w;
                g /= w;
                b /= w;
                if (r + g + b < 0x180)
                {
                    cc = Color.White;
                }
                else
                {
                    cc = Color.Black;
                }
            }

            string s = String.Format("{0} x {1}", i.Image.Width, i.Image.Height);

            TextRenderer.DrawText(e, s, this.Font, rr, cc, TextFormatFlags.Bottom | TextFormatFlags.Right);
        }
Exemple #7
0
        private void loadArt()
        {
            try
            {
                string path = String.Empty;
                Track  t    = template;

                if (t != null)
                {
                    path = t.FilePath;
                }

                if (path.Length == 0 || !File.Exists(path))
                {
                    path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                }
                else
                {
                    path = Path.GetDirectoryName(path);
                }

                OpenFileDialog ofd = Lib.GetOpenFileDialog(path,
                                                           true,
                                                           "Image Files (*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.tif;*.tiff)|*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.tif;*.tiff|All Files (*.*)|*.*",
                                                           1);

                ofd.Multiselect = false;

                if (ofd.ShowDialog(this) == DialogResult.OK)
                {
                    Image      = ImageItem.ImageItemFromGraphicsFile(ofd.FileName);
                    ImageDirty = true;
                }
            }
            catch { }
        }
Exemple #8
0
        public static ImageItem ImageFromLastFM(string Artist, string Album)
        {
            string key = Artist + Album;

            if (items.ContainsKey(key))
            {
                return(items[key]);
            }

            if (Artist.Length == 0 || Album.Length == 0)
            {
                addToItems(key, null);
                return(null);
            }

            try
            {
                string url = LastFM.GetAlbumImageURL(Artist, Album);

                if (url.Length > 0)
                {
                    System.Net.HttpWebRequest  httpRequest  = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
                    System.Net.HttpWebResponse httpResponse = (System.Net.HttpWebResponse)httpRequest.GetResponse();

                    httpRequest.ServicePoint.Expect100Continue = false;

                    Stream imageStream = httpResponse.GetResponseStream();

                    ImageItem ii = new ImageItem();
                    ii.filePath = key;

                    List <byte[]> bytes  = new List <byte[]>();
                    int           length = 0;
                    int           numRead;
                    byte[]        bb = new byte[100000];

                    while ((numRead = imageStream.Read(bb, 0, 100000)) > 0)
                    {
                        if (numRead < 100000)
                        {
                            byte[] bbbb = new byte[numRead];
                            Array.Copy(bb, bbbb, numRead);
                            bb = bbbb;
                        }
                        bytes.Add(bb);
                        length += numRead;
                        bb      = new byte[100000];
                    }

                    byte[] bbb    = new byte[length];
                    int    cursor = 0;
                    foreach (byte[] b in bytes)
                    {
                        Array.Copy(b, 0, bbb, cursor, Math.Min(length, b.Length));
                        length -= b.Length;
                        cursor += b.Length;
                    }

                    ii.imageData.Data = bbb;
                    ii.Src            = Source.Download;

                    httpResponse.Close();
                    imageStream.Close();

                    ii.it = typeFromExtension(url);

                    addToItems(key, ii);
                    return(ii);
                }
                else
                {
                    addToItems(key, null);
                    return(null);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());

                if (StringUtil.HasParentheticalChars(Album))
                {
                    return(ImageFromLastFM(Artist, StringUtil.RemoveParentheticalChars(Album)));
                }
            }
            addToItems(key, null);
            return(null);
        }