Esempio n. 1
0
        private static BitmapImage GetFromUrl(string value)
        {
            String url = FindUrl(value);

            if (url == null)
            {
                return(null);
            }
            String[] url_parts = new Uri(url).DnsSafeHost.Split(new char[] { '.' });
            String   key       = url_parts[url_parts.Length - 2];

            MemoryStream   ms      = new MemoryStream();
            HttpWebRequest request = WebRequest.CreateHttp(url);

            HttpWebResponse response       = request.GetResponse() as HttpWebResponse;
            Stream          responseStream = response.GetResponseStream();

            responseStream.CopyTo(ms);
            responseStream.Close();
            response.Close();

            ms.Position = 0;
            FileStream f = new FileStream(Path.Combine(cachePath, key + url.Substring(url.LastIndexOf('.'))), FileMode.Create, FileAccess.Write);

            ms.CopyTo(f);

            f.Close();
            ms.Position = 0;
            var bmap = CachedBitmap.BitmapImageFromStream(ms);

            _dictCache.Add(key, bmap);
            return(bmap);
        }
Esempio n. 2
0
 static FavIcon()
 {
     Directory.CreateDirectory(cachePath);
     string[] files = Directory.GetFiles(cachePath);
     foreach (var file in files)
     {
         FileStream fs     = new FileStream(file, FileMode.Open, FileAccess.Read);
         var        bitmap = CachedBitmap.BitmapImageFromStream(fs);
         _dictCache.Add(Path.GetFileNameWithoutExtension(file), bitmap);
         fs.Close();
     }
 }
Esempio n. 3
0
        private static BitmapImage GetFromLetters(String value)
        {
            Bitmap     bmp   = new Bitmap(48, 48);
            RectangleF rectf = new RectangleF(0, 0, 48, 48);
            Graphics   g     = Graphics.FromImage(bmp);

            //g.Clear(System.Drawing.Color.Gray);

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
            StringFormat format = new StringFormat();

            format.LineAlignment = StringAlignment.Center;
            format.Alignment     = StringAlignment.Center;
            System.Windows.Media.Color c = ((SolidColorBrush)App.Current.FindResource("LabelTextBrush")).Color; // ye i know, it's hacky but it works
            g.DrawString("" + value.ToUpper().First(), new Font("Tahoma", 40, FontStyle.Bold, GraphicsUnit.Pixel), new SolidBrush(System.Drawing.Color.FromArgb(c.A, c.R, c.G, c.B)), rectf, format);
            g.Flush();
            MemoryStream ms = new MemoryStream();

            bmp.Save(ms, ImageFormat.Png);
            ms.Position = 0;
            return(CachedBitmap.BitmapImageFromStream(ms));
        }