Inheritance: ImageSource, IBitmapSource
 public ClickToChangePictureViewModel()
 {
     _myImage1 = new BitmapImage(new Uri("ms-appx:///Images/110Banana.png"));
     _myImage2 = new BitmapImage(new Uri("ms-appx:///Images/110Lemon.png"));
     ClickCommand = new RelayCommand(ChangeIamges);
     ChangeIamges();
 }
 private DemoItemData generateDemoItemData(Uri imageUri, Color color, String colorTypeName, BitmapSource bitmapSource = null)
 {
     return new DemoItemData()
     {
         ImageUri = imageUri,
         BackgroundColor = color,
         ColorTypeName = color == Colors.Transparent ? colorTypeName + ", Failed" : colorTypeName,
         BitmapSource = bitmapSource
     };
 }
 public TaskItem(string id, string title, string description, BitmapImage img, DateTime datetime, string filepath, string name, string _comment)
 {
     this.id = id; //生成id
     this.title = title;
     this.description = description;
     this.datetime = datetime;
     completed = false; //默认为未完成
     this.filepath = filepath;
     source = img;
     username = name;
     comments = _comment;
 }
 static async void SetUriSourceAsync(BitmapSource image, Uri uri)
 {
     try
     {
         using (var inputStream = await httpClient.GetInputStreamAsync(uri))
         using (var stream = new InMemoryRandomAccessStream())
         {
             await RandomAccessStream.CopyAsync(inputStream, stream);
             stream.Seek(0);
             await image.SetSourceAsync(stream);
         }
     }
     catch
     {
         store.Value.Remove(uri);
     }
 }
Exemple #5
0
        public void ChangeBGImage(BitmapSource newImg)
        {
            ImageBrush i1 = this.BgImage1;  // 1 在底层 (换成新图片后) 透明度逐渐增加, 2在顶层颜色逐渐变淡, 结束后 2图片改为新图,然后 显示2,隐藏1
            ImageBrush i2 = this.BgImage2;
            if (this.milliSeconds == 0)
            {
                i2.ImageSource = (BitmapSource)(newImg);
                if (this.ImgChangeDone != null)
                {
                    this.ImgChangeDone(this, true);
                }
                return;
            }

            i1.ImageSource = (BitmapSource)(newImg);

            Grid g1 = this.G1;
            Grid g2 = this.G2;
            Storyboard sb1 = AnimationFactory.CreateDoubleSB(g1, "Opacity", this.milliSeconds, 1);
            Storyboard sb2 = AnimationFactory.CreateDoubleSB(g2, "Opacity", this.milliSeconds + 500, 0);

            sb2.Completed += (s, ee) =>
            {
                i2.Stretch = Stretch.UniformToFill;

                i2.ImageSource = i1.ImageSource;
                g2.Opacity = 1;
                g1.Opacity = 0;
                if (this.ImgChangeDone != null)
                {
                    this.ImgChangeDone(this, true);
                }
            };
            sb1.Begin();
            sb2.Begin();
        }
 public void updatetaskitem(string id, string title, string description, DateTime datetime, BitmapSource bitmapimage, string filepath, string username, string comment)
 {
     if (this.selectedItem != null)
     {
         using (var tasklist = App.conn.Prepare("update taskitem set Title = ?, Detail = ?, Datetime = ?, Filepath = ?, Username = ?, Comment = ? where id = ?"))
         {
             tasklist.Bind(1, title);
             tasklist.Bind(2, description);
             tasklist.Bind(3, datetime.Date.ToString("yyyy-MM-dd", DateTimeFormatInfo.InvariantInfo));
             tasklist.Bind(4, filepath);
             tasklist.Bind(5, username);
             tasklist.Bind(6, comment);
             tasklist.Bind(7, id);
             tasklist.Step();
         }
     }
     getItemFromDB();
     this.selectedItem = null;
 }
 //display an image 
 public void setImg(Image i, BitmapSource bms)
 {
     i.Source = bms;
     i.Opacity = 2;
 }
Exemple #8
0
 public Thumbnail(string name, BitmapSource bitmap)
 {
     this.Name = name;
     this.Bitmap = bitmap;
 }
Exemple #9
0
		private async void LoadData()
		{
			TunesUser user = this.m_accountService.User;
			if (user != null && !string.IsNullOrEmpty(user.UserName))
			{
				this.Playlist = await this.m_dataService.GetPlaylistByIdWithNumberOfEntries(this.PlaylistId, user.UserName);
                if (this.Playlist != null)
                {
                    this.FormatNumberOfEntriesString();

                    System.Collections.ObjectModel.ObservableCollection<Guid> albumIds = await this.m_dataService.GetPlaylistImageIdsById(this.Playlist.Id, user.UserName, 4);
                    if (albumIds != null)
                    {
                        try
                        {
                            this.ImageSource = await this.m_cacheableBitmapService.GetBitmapSource(
                                new ObservableCollection<Uri>(albumIds.Select(id => this.m_dataService.GetImage(id, true))),
                                this.Playlist.Guid.ToString(),
                                160, true);
                        }
                        catch { };
                    }
                }
			}
		}
 private void SendImage(BitmapSource image, SenderSide side = SenderSide.Local)
 {
     var chatImage = new ChatImageViewModel()
     {
         Image = image,
         SentDateTime = DateTime.Now,
         SenderSide = side
     };
     ChatItems.Add(chatImage);
 }
 public PendingTile(Tile tile, Uri uri)
 {
     Tile = tile;
     Uri = uri;
     Image = new BitmapImage();
 }
        private async Task<bool> LoadImageFromStream(Tile tile, BitmapSource image, IRandomAccessStream stream)
        {
            var completion = new TaskCompletionSource<bool>();

            var action = image.Dispatcher.RunAsync(
                CoreDispatcherPriority.Normal,
                async () =>
                {
                    try
                    {
                        await image.SetSourceAsync(stream);
                        tile.SetImage(image, true, false);

                        completion.SetResult(true);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                        tile.SetImage(null);

                        completion.SetResult(false);
                    }
                });

            return await completion.Task;
        }
        private async Task<bool> LoadImageFromHttpResponse(HttpResponseMessage response, Tile tile, BitmapSource image, string cacheKey)
        {
            using (var stream = new InMemoryRandomAccessStream())
            {
                using (var content = response.Content)
                {
                    await content.WriteToStreamAsync(stream);
                }

                await stream.FlushAsync();
                stream.Seek(0);

                var loaded = await LoadImageFromStream(tile, image, stream);

                if (loaded && cacheKey != null)
                {
                    var buffer = new Windows.Storage.Streams.Buffer((uint)stream.Size);

                    stream.Seek(0);
                    await stream.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.None);

                    var maxAge = DefaultCacheExpiration;

                    if (response.Headers.CacheControl.MaxAge.HasValue &&
                        response.Headers.CacheControl.MaxAge.Value < maxAge)
                    {
                        maxAge = response.Headers.CacheControl.MaxAge.Value;
                    }

                    await Cache.SetAsync(cacheKey, buffer, DateTime.UtcNow.Add(maxAge));
                }

                return loaded;
            }
        }
        private async Task<bool> DownloadImage(Tile tile, BitmapSource image, Uri uri, string cacheKey)
        {
            try
            {
                using (var httpClient = new HttpClient(new HttpBaseProtocolFilter { AllowAutoRedirect = false }))
                using (var response = await httpClient.GetAsync(uri))
                {
                    if (response.IsSuccessStatusCode)
                    {
                        return await LoadImageFromHttpResponse(response, tile, image, cacheKey);
                    }

                    Debug.WriteLine("{0}: ({1}) {2}", uri, (int)response.StatusCode, response.ReasonPhrase);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("{0}: {1}", uri, ex.Message);
            }

            return false;
        }