Beispiel #1
0
        public async Task SetImageAsync(Windows.Storage.Streams.IRandomAccessStream imageStream)
        {
            var bmp = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
            await bmp.SetSourceAsync(imageStream);

            this.canvasImage.Source = bmp;
        }
Beispiel #2
0
        public static async Task LoadPictureAsync(FrameworkElement sender)
        {
            try
            {
                if (sender.Parent is Panel pl)
                {
                    if (pl.FindName("pro") is TextBlock ring)
                    {
                        ring.Visibility = Visibility.Visible;
                        try
                        {
                            var img = sender as Image;
                            if (img.DataContext != null)
                            {
                                var work = (img.DataContext as Work);
                                using (var stream = await Data.TmpData.CurrentAuth.Tokens.SendRequestToGetImageAsync(Pixeez.MethodType.GET, work.ImageUrls.Medium))
                                {
                                    var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                                    await bitmap.SetSourceAsync((await stream.GetResponseStreamAsync()).AsRandomAccessStream());

                                    img.Source = bitmap;
                                }
                            }
                        }
                        finally
                        {
                            ring.Visibility = Visibility.Collapsed;
                        }
                    }
                }
            }
            catch
            {
            }
        }
Beispiel #3
0
        private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
        {
            /*
             * Open camera and capture photos
             * Source: http://windowsapptutorials.com/windows-phone-8-1/media-windows-phone-8-1/using-fileopenpicker-in-windows-phone-8-1-to-choose-picture-from-picture-gallery/
             * */
            FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;

            if (args != null)
            {
                if (args.Files.Count == 0)
                {
                    return;
                }

                view.Activated -= viewActivated;
                storageFile     = args.Files[0];
                var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

                var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                await bitmapImage.SetSourceAsync(stream);

                var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);

                img.Source = bitmapImage;
            }
        }
        public static async Task <Windows.UI.Xaml.Media.Imaging.BitmapImage> GetImageSourceAsync(string ID)
        {
            var result = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
            var file   = (await GetImageFileAsync(ID));

            if (file == null)
            {
                return(null);
            }
            var src = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

            if (src == null)
            {
                return(null);
            }
            try {
                await result.SetSourceAsync(src);

                return(result);
            }
            catch
            {
                return(null);
            }
        }
Beispiel #5
0
        private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var folderPicker = new Windows.Storage.Pickers.FolderPicker();

            folderPicker.FileTypeFilter.Add(".jpg");
            var folder = await folderPicker.PickSingleFolderAsync();

            var filesList =
                await folder.CreateFileQueryWithOptions(new QueryOptions(CommonFileQuery.DefaultQuery,
                                                                         new string[] { ".jpg" })).GetFilesAsync();

            for (int i = 0; i < filesList.Count; i++)
            {
                using (var stream = await filesList[i].OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    Debug.WriteLine(filesList[i].Name);
                    var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    await bitmapImage.SetSourceAsync(stream);

                    Image m = new Image();
                    m.Source = bitmapImage;
                    Stack.Children.Add(m);
                }
            }
        }
Beispiel #6
0
        public async Task RefreshAsync()
        {
            try
            {
                pivot.Title       = pix_user.Name + (!string.IsNullOrEmpty(pix_user.Email) ? "(" + pix_user.Email + ")" : string.Empty);
                btn_Pin.IsEnabled = false;
                //string imgurl = pix_user.ProfileImageUrls.Px170x170 ?? pix_user.ProfileImageUrls.Px50x50 ?? pix_user.ProfileImageUrls.Px16x16;
                var newuserinfo = await Data.TmpData.CurrentAuth.Tokens.GetUserInfoAsync(pix_user.Id.Value.ToString());

                //if (imgurl==null)
                //{
                //    pix_user = ().Single();
                //    imgurl = pix_user.ProfileImageUrls.Px170x170;
                //}
                using (var res = await PixivUWP.Data.TmpData.CurrentAuth.Tokens.SendRequestToGetImageAsync(Pixeez.MethodType.GET, newuserinfo.user.profile_image_urls.Medium))
                {
                    var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    await bitmap.SetSourceAsync((await res.GetResponseStreamAsync()).AsRandomAccessStream());

                    userpro.ImageSource = bitmap;
                    //contact.Id = "PIXIV!" + pix_user.Id.ToString();
                    contact.RemoteId = "PIXIV!" + pix_user.Id.ToString();
                    contact.Name     = pix_user.Name;
                    //contact.SourceDisplayPicture = RandomAccessStreamReference.CreateFromStream((await res.GetResponseStreamAsync()).AsRandomAccessStream());
                    if (pix_user.Email != null)
                    {
                        ContactEmail contactEmail = new ContactEmail();
                        contactEmail.Address = pix_user.Email;
                        contact.Emails.Add(contactEmail);
                    }
                    btn_Pin.IsChecked = await Data.AppDataHelper.checkContactAsync(contact);

                    pinned = btn_Pin.IsChecked.Value;
                    //btn_Pin.IsEnabled = true;
                }
                if (newuserinfo.profile != null)
                {
                    userinfo.Text = string.Concat(getinfostr(newuserinfo.profile.birth, "BirthDate"),
                                                  getinfostr(newuserinfo.profile.gender, "Gender"), getinfostr(newuserinfo.profile.webpage, "homepage"), getinfostr(newuserinfo.user.comment, "intro"),
                                                  getinfostr(newuserinfo.profile.job, "job"), getinfostr(newuserinfo.profile.region, "loc"));
                }

                //TODO:国际化
                //            if (pix_user.Profile != null)
                //            {
                //                userinfo.Text = string.Concat(getinfostr(pix_user.Profile.BirthDate, "BirthDate"), getinfostr(pix_user.Profile.BloodType, "BloodType"),
                //getinfostr(pix_user.Profile.Gender, "Gender"), getinfostr(pix_user.Profile.Homepage, "homepage"), getinfostr(pix_user.Profile.Introduction, "intro"),
                //getinfostr(pix_user.Profile.Job, "job"), getinfostr(pix_user.Profile.Location, "loc"));
                //            }
                //            else
                //            {

                //            }
            }
            catch { }
        }
Beispiel #7
0
        private async void FileStorage_Click(object sender, RoutedEventArgs e)
        {
            var fileId = "$/series/alteredcarbon.jpg";

            WriteLog("File storage");
            WriteLog("=============");
            WriteLog(" ");
            WriteLog("Importing an image");
            WriteLog("------------------");
            var path     = Path.Combine(Windows.Application­Model.Package.Current.Installed­Location.Path, @"./Assets/AlteredCarbon.jpg");
            var fileInfo = DataLayer.SaveFile(fileId, path, "Altered Carbon");

            WriteLog(fileInfo);
            path     = Path.Combine(Windows.Application­Model.Package.Current.Installed­Location.Path, @"./Assets/RickAndMorty.jpg");
            fileInfo = DataLayer.SaveFile(@"$/series/rickandmorty.jpg", path, "Rick and Morty");
            WriteLog(fileInfo);

            WriteLog(" ");
            WriteLog("Querying a folder");
            WriteLog("-----------------");
            var files = DataLayer.QueryFolder(@"$/series/");

            foreach (var file in files)
            {
                WriteLog($"  * {file}");
            }

            WriteLog(" ");
            WriteLog("Returning an image");
            WriteLog("------------------");
            // var stream = DataLayer.SelectFile(fileId);
            var stream = DataLayer.FindFileByMetadata("Altered Carbon");

            stream.Seek(0, SeekOrigin.Begin);
            var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
            await bitmapImage.SetSourceAsync(stream.AsRandomAccessStream());

            SelectedImage.Source = bitmapImage;
            WriteLog("<--- look");

            WriteLog(" ");
            WriteLog("Deleting an image");
            WriteLog("-----------------");
            if (DataLayer.DeleteFile(fileId))
            {
                WriteLog("file deleted");
            }
            else
            {
                WriteLog("file not deleted");
            }

            WriteLog(" ");
            WriteLog("Done");
            WriteLog(" ");
        }
Beispiel #8
0
        async void LoadImageAsync(Product product)
        {
            ImageSource = new Image();
            using (var stream = new InMemoryRandomAccessStream())
            {
                await stream.WriteAsync(product.Image.AsBuffer());

                stream.Seek(0);
                await ImageSource.SetSourceAsync(stream);
            }
        }
        public async Task RefreshAsync()
        {
            PixivUWP.ProgressBarVisualHelper.SetYFHelperVisibility(pro, true);
            gz.IsEnabled = false;

            try
            {
                title.Text   = Work.Title;
                user.Text    = Work.User.Name;
                siz.Text     = Work.Width?.ToString() + "×" + Work.Height?.ToString();
                tool.Text    = new Converter.TagsToStr().Convert(Work.Tools, null, null, null).ToString();
                fs.IsChecked = Work.IsBookMarked();
                string url = Work is IllustWork ? Work.ImageUrls.Large : Work.ImageUrls.Medium;
                des.Text  = Work.Caption ?? string.Empty;
                time.Text = Work.GetCreatedDate().ToString() /* + "(创建与更新时间:" + Work.CreatedTime.LocalDateTime.ToString() + "," + Work.ReuploadedTime.ToString() + ")"*/;
                tags.Text = new Converter.TagsToStr().Convert(Work.Tags, null, null, null).ToString();
                using (var stream = await Data.TmpData.CurrentAuth.Tokens.SendRequestAsync(Pixeez.MethodType.GET, url))
                {
                    var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    await bitmap.SetSourceAsync((await stream.GetResponseStreamAsync()).AsRandomAccessStream());

                    bigimg.Source = bitmap;
                }
                if (Work.User.is_followed.HasValue)
                {
                    gz.IsChecked = Work.User.is_followed;
                }
                else
                {
                    var user = await Data.TmpData.CurrentAuth.Tokens.GetUsersAsync(Work.User.Id.Value);

                    if (user[0].IsFollowing.HasValue)
                    {
                        gz.IsChecked = user[0].IsFollowing;
                    }
                    else
                    {
                        gz.Visibility = Visibility.Collapsed;
                    }
                }
                gz.IsEnabled = true;
            }
            catch
            {
                await new Windows.UI.Popups.MessageDialog(err1).ShowAsync();
            }
            finally
            {
                PixivUWP.ProgressBarVisualHelper.SetYFHelperVisibility(pro, false);
            }
        }
        /// <summary>
        ///  現在のロック画面に設定されているイメージをアプリの背景に設定する.
        /// </summary>
        /// <remarks>
        ///  このアプリでロック画面を設定していない場合、何も取得できない可能性がある.
        ///  (MSDNのAPI仕様通り)
        /// </remarks>
        public async void LoadCurrentLockscreenImageAsync()
        {
            using (var stream = LockScreen.GetImageStream())
            {
                if (stream == null)
                {
                    return;
                }

                var image = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                await image.SetSourceAsync(stream);

                this.BackgroundBrush.ImageSource = image;
            }
        }
Beispiel #11
0
        public async void ce()
        {
            Windows.Storage.Pickers.FileOpenPicker pick;
            pick = new Windows.Storage.Pickers.FileOpenPicker();
            pick.FileTypeFilter.Add(".jpg");
            Windows.Storage.StorageFile file = await pick.PickSingleFileAsync();

            if (file != null)
            {
                Windows.UI.Xaml.Media.Imaging.BitmapImage temp = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                await temp.SetSourceAsync(await file.OpenAsync(Windows.Storage.FileAccessMode.Read));

                img = temp;
            }
        }
 public static async Task<Windows.UI.Xaml.Media.Imaging.BitmapImage> GetImageSourceAsync(string ID)
 {
     var result= new Windows.UI.Xaml.Media.Imaging.BitmapImage();
     var file = (await GetImageFileAsync(ID));
     if (file == null) return null;
     var src = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
     if (src == null) return null;
     try {
         await result.SetSourceAsync(src);
         return result;
     }
     catch
     {
         return null;
     }
 }
Beispiel #13
0
        public static async Task LoadPictureAsync(FrameworkElement sender)
        {
            if (loaded.Contains(sender))
            {
                return;
            }
            try
            {
                CoreDispatcher dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;
                await dispatcher.RunAsync(CoreDispatcherPriority.Low,
                                          () =>
                                          { }
                                          );

                if (sender.Parent is Panel pl)
                {
                    if (pl.FindName("pro") is TextBlock ring)
                    {
                        ring.Visibility = Visibility.Visible;
                        try
                        {
                            var img = sender as Image;
                            if (img.DataContext != null)
                            {
                                var work = (img.DataContext as Work);
                                using (var stream = await Data.TmpData.CurrentAuth.Tokens.SendRequestToGetImageAsync(Pixeez.MethodType.GET, geturlbypolicy(work.ImageUrls)))
                                {
                                    var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                                    await bitmap.SetSourceAsync((await stream.GetResponseStreamAsync()).AsRandomAccessStream());

                                    img.Source = bitmap;
                                    loaded.Add(sender);
                                }
                            }
                        }
                        finally
                        {
                            ring.Visibility = Visibility.Collapsed;
                        }
                    }
                }
            }
            catch
            {
            }
        }
        private async void OpenImage_Click(object sender, TappedRoutedEventArgs e)
        {
            FileOpenPicker filePicker = new FileOpenPicker();

            filePicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            filePicker.ViewMode = PickerViewMode.Thumbnail;
            filePicker.FileTypeFilter.Add(".png");
            StorageFile storageFile = await filePicker.PickSingleFileAsync();

            var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

            var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
            await bitmapImage.SetSourceAsync(stream);

            var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);

            img.Source = bitmapImage;
        }
        private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
        {
            FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;

            if (args != null)
            {
                if (args.Files.Count == 0) return;

                view.Activated -= viewActivated;
                StorageFile storageFile = args.Files[0];
                var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
                var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                await bitmapImage.SetSourceAsync(stream);

                var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
                img.Source=bitmapImage;
            }
        }
        private async void DodajSlikuButton_Click(object sender, RoutedEventArgs e)
        {
            var filePicker = new Windows.Storage.Pickers.FileOpenPicker();

            filePicker.FileTypeFilter.Add(".jpg");
            filePicker.FileTypeFilter.Add(".jpeg");
            filePicker.FileTypeFilter.Add(".png");
            Windows.Storage.StorageFile file;

            file = await filePicker.PickSingleFileAsync();

            var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

            var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
            await bitmapImage.SetSourceAsync(stream);

            //slikaLicne.Source = bitmapImage;
        }
        private async void Image_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            var page = args.NewValue as MetaPages;

            if (sender is Panel pl)
            {
                if (pl.FindName("img") is Image img)
                {
                    img.Source = null;
                    if (pl.FindName("pro") is ProgressRing pro)
                    {
                        ProgressBarVisualHelper.SetYFHelperVisibility(pro, true);
                        try
                        {
                            using (var stream = await Data.TmpData.CurrentAuth.Tokens.SendRequestAsync(Pixeez.MethodType.GET, page.ImageUrls.Original ?? page.ImageUrls.Large ?? page.ImageUrls.Medium))
                            {
                                var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                                await bitmap.SetSourceAsync((await stream.GetResponseStreamAsync()).AsRandomAccessStream());

                                img.Source = bitmap;
                            }
                        }
                        catch
                        {
                            new Controls.MyToast("有图片加载失败").Show();
                        }
                        finally
                        {
                            ProgressBarVisualHelper.SetYFHelperVisibility(pro, false);
                        }
                    }
                }
                else
                {
                    //RoutedEventHandler reh= (se, ee) =>
                    //{
                    //    Image_DataContextChanged(sender, args);
                    //};
                    //pl.Loaded += reh;
                }
            }
        }
        public async Task RefreshAsync()
        {
            try
            {
                pivot.Title = pix_user.Name + (!string.IsNullOrEmpty(pix_user.Email) ? "(" + pix_user.Email + ")" : string.Empty);

                //string imgurl = pix_user.ProfileImageUrls.Px170x170 ?? pix_user.ProfileImageUrls.Px50x50 ?? pix_user.ProfileImageUrls.Px16x16;
                var newuserinfo = await Data.TmpData.CurrentAuth.Tokens.GetUserInfoAsync(pix_user.Id.Value.ToString());

                //if (imgurl==null)
                //{
                //    pix_user = ().Single();
                //    imgurl = pix_user.ProfileImageUrls.Px170x170;
                //}
                using (var res = await PixivUWP.Data.TmpData.CurrentAuth.Tokens.SendRequestToGetImageAsync(Pixeez.MethodType.GET, newuserinfo.user.profile_image_urls.Medium))
                {
                    var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    await bitmap.SetSourceAsync((await res.GetResponseStreamAsync()).AsRandomAccessStream());

                    userpro.ImageSource = bitmap;
                }
                if (newuserinfo.profile != null)
                {
                    userinfo.Text = string.Concat(getinfostr(newuserinfo.profile.birth, "BirthDate"),
                                                  getinfostr(newuserinfo.profile.gender, "Gender"), getinfostr(newuserinfo.profile.webpage, "homepage"), getinfostr(newuserinfo.user.comment, "intro"),
                                                  getinfostr(newuserinfo.profile.job, "job"), getinfostr(newuserinfo.profile.region, "loc"));
                }

                //TODO:国际化
                //            if (pix_user.Profile != null)
                //            {
                //                userinfo.Text = string.Concat(getinfostr(pix_user.Profile.BirthDate, "BirthDate"), getinfostr(pix_user.Profile.BloodType, "BloodType"),
                //getinfostr(pix_user.Profile.Gender, "Gender"), getinfostr(pix_user.Profile.Homepage, "homepage"), getinfostr(pix_user.Profile.Introduction, "intro"),
                //getinfostr(pix_user.Profile.Job, "job"), getinfostr(pix_user.Profile.Location, "loc"));
                //            }
                //            else
                //            {

                //            }
            }
            catch { }
        }
        private async void Image_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        {
            try
            {
                var img = sender as Image;
                if (img.DataContext != null)
                {
                    using (var stream = await Data.TmpData.CurrentAuth.Tokens.SendRequestAsync(Pixeez.MethodType.GET, (img.DataContext as Work).ImageUrls.Small))
                    {
                        var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                        await bitmap.SetSourceAsync((await stream.GetResponseStreamAsync()).AsRandomAccessStream());

                        img.Source = bitmap;
                    }
                }
            }
            catch
            {
            }
        }
        public async Task RefreshAsync()
        {
            try
            {
                pivot.Title = pix_user.Name + (!string.IsNullOrEmpty(pix_user.Email) ? "(" + pix_user.Email + ")" : string.Empty);
                string imgurl = pix_user.ProfileImageUrls.Px170x170 ?? pix_user.ProfileImageUrls.Px50x50 ?? pix_user.ProfileImageUrls.Px16x16;
                if (imgurl == null)
                {
                    pix_user = (await Data.TmpData.CurrentAuth.Tokens.GetUsersAsync(pix_user.Id.Value)).Single();
                    imgurl   = pix_user.ProfileImageUrls.Px170x170;
                }
                using (var res = await PixivUWP.Data.TmpData.CurrentAuth.Tokens.SendRequestToGetImageAsync(Pixeez.MethodType.GET, imgurl))
                {
                    var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    await bitmap.SetSourceAsync((await res.GetResponseStreamAsync()).AsRandomAccessStream());

                    userpro.Source = bitmap;
                }
            }
            catch { }
        }
        //Not smart at all...
        public static async void SetToImageSourceNoWait(string ID, Windows.UI.Xaml.Media.Imaging.BitmapImage image)
        {
            var file = (await GetImageFileAsync(ID));

            if (file == null)
            {
                return;
            }
            var src = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

            if (src == null)
            {
                return;
            }
            try {
                await image.SetSourceAsync(src);
            }
            catch
            {
                // ignored
            }
        }
Beispiel #22
0
        private async void ImageListView_Drop(object sender, Windows.UI.Xaml.DragEventArgs e)
        {
            ((GridView)sender).Background = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.White);
            if (e.DataView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.StorageItems))
            {
                var storageItems = await e.DataView.GetStorageItemsAsync();

                foreach (Windows.Storage.StorageFile storageItem in storageItems)
                {
                    var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    await bitmapImage.SetSourceAsync(await storageItem.OpenReadAsync());

                    var imageItem = new ImageItem
                    {
                        Id    = Guid.NewGuid(),
                        Image = bitmapImage
                    };

                    ImageItems.Add(imageItem);
                }
            }
        }
Beispiel #23
0
        private async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
        {
            FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;

            if (args != null)
            {
                if (args.Files.Count == 0)
                {
                    return;
                }

                view.Activated -= viewActivated;
                StorageFile storageFile = args.Files[0];
                var         stream      = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

                var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                await bitmapImage.SetSourceAsync(stream);

                //   var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
                img.Source = bitmapImage;
            }
        }
Beispiel #24
0
        private async void Click_SelectPicture(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
            openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");

            ImageFile = await openPicker.PickSingleFileAsync();

            if (ImageFile != null)
            {
                using (Windows.Storage.Streams.IRandomAccessStream fileStream = await ImageFile.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    await bitmapImage.SetSourceAsync(fileStream);

                    image.Source = bitmapImage;
                }
            }
        }
Beispiel #25
0
        /// <summary>
        ///  アイテムのサムネイル画像を取得する.
        /// </summary>
        async void GetThumbnailAsync()
        {
            if (this.Item == null)
            {
                return;
            }

            using (var thumbnail = await this.Item.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.SingleItem))
            {
                var bmpImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                await bmpImage.SetSourceAsync(thumbnail);

                if (this.m_thumbnail == null)
                {
                    this.m_thumbnail = new WeakReference <Windows.UI.Xaml.Media.Imaging.BitmapImage>(bmpImage);
                }
                else
                {
                    this.m_thumbnail.SetTarget(bmpImage);
                }
                OnPropertyChanged("Image");
            }
        }
Beispiel #26
0
        private async void Showpicker()
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker
            {
                ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
                SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary
            };

            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                Windows.Storage.Streams.IRandomAccessStream randomAccessStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                Windows.UI.Xaml.Media.Imaging.BitmapImage bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                await bitmap.SetSourceAsync(randomAccessStream);

                Personpictures.ProfilePicture = bitmap;
            }
        }
Beispiel #27
0
        public async Task RefreshAsync()
        {
            PixivUWP.ProgressBarVisualHelper.SetYFHelperVisibility(pro, true);
            gz.IsEnabled = false;
            try
            {
                title.Text = Work.Title;
                user.Text  = Work.User.Name;
                siz.Text   = Work.Width?.ToString() + "×" + Work.Height?.ToString();
                try
                {
                    tool.Text = new Converter.TagsToStr().Convert(Work.Tools, null, null, null).ToString();
                }
                catch { }
                fs.IsChecked = Work.IsBookMarked();
                string url;
                var    profile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
                bool   wwanok;
                if (profile.IsWwanConnectionProfile)
                {
                    switch (profile.WwanConnectionProfileDetails.GetCurrentDataClass())
                    {
                    case Windows.Networking.Connectivity.WwanDataClass.Cdma1xRtt:
                    case Windows.Networking.Connectivity.WwanDataClass.None:
                    case Windows.Networking.Connectivity.WwanDataClass.Gprs:
                    case Windows.Networking.Connectivity.WwanDataClass.Edge:
                        wwanok = false;
                        break;

                    default:
                    case Windows.Networking.Connectivity.WwanDataClass.Cdma1xEvdo:
                    case Windows.Networking.Connectivity.WwanDataClass.Cdma1xEvdoRevA:
                    case Windows.Networking.Connectivity.WwanDataClass.Cdma1xEvdv:
                    case Windows.Networking.Connectivity.WwanDataClass.Custom:
                    case Windows.Networking.Connectivity.WwanDataClass.CdmaUmb:
                    case Windows.Networking.Connectivity.WwanDataClass.Umts:
                    case Windows.Networking.Connectivity.WwanDataClass.Hsdpa:
                    case Windows.Networking.Connectivity.WwanDataClass.Hsupa:
                    case Windows.Networking.Connectivity.WwanDataClass.LteAdvanced:
                    case Windows.Networking.Connectivity.WwanDataClass.Cdma3xRtt:
                        wwanok = true;
                        break;
                    }
                }
                else
                {
                    wwanok = true;
                }
                var connectioncost = profile.GetConnectionCost();
                if (connectioncost.ApproachingDataLimit == false && connectioncost.OverDataLimit == false &&
                    (connectioncost.NetworkCostType == Windows.Networking.Connectivity.NetworkCostType.Unrestricted || connectioncost.NetworkCostType == Windows.Networking.Connectivity.NetworkCostType.Unknown) &&
                    wwanok)
                {
                    url = Work.ImageUrls.Original ?? Work.ImageUrls.Large ?? Work.ImageUrls.Medium;
                }
                else
                {
                    url = Work is IllustWork ? Work.ImageUrls.Large : Work.ImageUrls.Medium;
                }
                string htmldoc = "<html><body><div style=\"word-wrap: break-word\">" + (Work.Caption ?? string.Empty) + "</div></body></html>";
                des.NavigationCompleted += async(sender, args) => await sender.ResizeToContentAsync();

                //des.SizeChanged += async (sender, args) => await ((WebView)sender).ResizeToContentAsync();(暂时撤销改修改以防止出现更为严重的界面显示问题)
                des.NavigateToString(htmldoc);
                time.Text = Work.GetCreatedDate().ToString() /* + "(创建与更新时间:" + Work.CreatedTime.LocalDateTime.ToString() + "," + Work.ReuploadedTime.ToString() + ")"*/;
                //tags.Text = new Converter.TagsToStr().Convert(Work.Tags, null, null, null).ToString();
                Tags.ItemsSource = new Converter.TagsToTagList().Convert(Work.Tags, null, null, null);
                using (var stream = await Data.TmpData.CurrentAuth.Tokens.SendRequestAsync(Pixeez.MethodType.GET, url))
                {
                    var bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                    await bitmap.SetSourceAsync((await stream.GetResponseStreamAsync()).AsRandomAccessStream());

                    bigimg.Source = bitmap;
                }
                string avimg = Work.User.GetAvatarUrl();
                if (Work.User.is_followed.HasValue && avimg != null)
                {
                    gz.IsChecked = Work.User.is_followed;
                }
                else
                {
                    var user = await Data.TmpData.CurrentAuth.Tokens.GetUsersAsync(Work.User.Id.Value);

                    avimg = user[0].GetAvatarUrl() ?? avimg;
                    if (user[0].IsFollowing.HasValue)
                    {
                        gz.IsChecked = user[0].IsFollowing;
                    }
                    else
                    {
                        gz.Visibility = Visibility.Collapsed;
                    }
                }
                #region 获取头像
                loadAvatar();
                async void loadAvatar()
                {
                    try
                    {
                        var asyncres = await Data.TmpData.CurrentAuth.Tokens.SendRequestAsync(Pixeez.MethodType.GET, avimg, null);

                        var img = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                        await img.SetSourceAsync((await asyncres.GetResponseStreamAsync()).AsInputStream() as Windows.Storage.Streams.IRandomAccessStream);

                        userpro.ImageSource = img;
                    }
                    catch { }
                    var rescomm = loadComment();
                }
                #endregion
                if (Work is Pixeez.Objects.IllustWork newwork)
                {
                    userviewnum.Text = newwork.total_view.ToString();
                    userlikenum.Text = newwork.total_bookmarks.ToString();
                }
                gz.IsEnabled = true;
            }
            catch
            {
                await new Windows.UI.Popups.MessageDialog(err1).ShowAsync();
            }
            finally
            {
                PixivUWP.ProgressBarVisualHelper.SetYFHelperVisibility(pro, false);
            }
        }
Beispiel #28
0
        /// <summary>
        /// This method set the poster source for the MediaElement 
        /// </summary>
        private async System.Threading.Tasks.Task<bool> SetPosterUrl(string PosterUrl)
        {
            if (IsPicture(PosterUrl))
            {
                if (IsLocalFile(PosterUrl))
                {
                    try
                    {
                        Windows.Storage.StorageFile file = await GetFileFromLocalPathUrl(PosterUrl);
                        if (file != null)
                        {
                            using (var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                            {
                                if (fileStream != null)
                                {
                                    Windows.UI.Xaml.Media.Imaging.BitmapImage b = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                                    if (b != null)
                                    {
                                        b.SetSource(fileStream);
                                        SetPictureSource(b);
                                        SetPictureElementSize();
                                        return true;
                                    }
                                }
                            }
                        }
                        else
                            LogMessage("Failed to load poster: " + PosterUrl);

                    }
                    catch (Exception e)
                    {
                        LogMessage("Exception while loading poster: " + PosterUrl + " - " + e.Message);
                    }
                }
                else
                {
                    try
                    {

                        // Load the bitmap image over http
                        Windows.Web.Http.HttpClient httpClient = new Windows.Web.Http.HttpClient();
                        Windows.Storage.Streams.InMemoryRandomAccessStream ras = new Windows.Storage.Streams.InMemoryRandomAccessStream();
                        using (var stream = await httpClient.GetInputStreamAsync(new Uri(PosterUrl)))
                        {
                            if (stream != null)
                            {
                                await stream.AsStreamForRead().CopyToAsync(ras.AsStreamForWrite());
                                ras.Seek(0);
                                var b = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                                if (b != null)
                                {
                                    await b.SetSourceAsync(ras);
                                    SetPictureSource(b);
                                    SetPictureElementSize();
                                    return true;
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine("Exception: " + e.Message);
                    }
                }
            }

            return false;
        }
        private  async void viewActivated(CoreApplicationView sender, IActivatedEventArgs args1)
        {
            FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;

            if (args != null)
            {
                if (args.Files.Count == 0) return;

                view.Activated -= viewActivated;
                StorageFile storageFile = args.Files[0];
                var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
                var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                await bitmapImage.SetSourceAsync(stream);
                var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
                img.Source = bitmapImage;

                //PictureTags.Text = storageFile.Name;
                //PassPictureData.picture_view_source2 = storageFile.Name;
                var obj = App.Current as App;
                obj.exam2 = storageFile.Name;

                //getting data from DB 
                ReadClothesList db_clothes = new ReadClothesList();
                SeasonTxtBlck.Text = db_clothes.GetSeasonData();
                CategoryTxtBlck.Text = db_clothes.GetCategoryData();
                KindTxtBlck.Text = db_clothes.GetKindData();               

            }
        }
 public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
 {
     try
     {
         Util.debugLog("Hello");
         if (args.Files.Count > 0)
         {
             Util.debugLog("Hello");
             textAddImage.Label = "Replace Image";
             var stream = await args.Files[0].OpenAsync(Windows.Storage.FileAccessMode.Read);
             var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
             await bitmapImage.SetSourceAsync(stream);
             CameraPreview.Source = bitmapImage;
             RandomAccessStreamReference rasr = RandomAccessStreamReference.CreateFromStream(stream);
             var streamWithContent = await rasr.OpenReadAsync();
             byte[] buffer = new byte[streamWithContent.Size];
             //showProcessRing();
             await streamWithContent.ReadAsync(buffer.AsBuffer(), (uint)streamWithContent.Size, InputStreamOptions.None);
             //hideProcessRing();
             str = Convert.ToBase64String(buffer);
             int S1Length = str.Length;
             Util.debugLog(str);
         }
     }
     catch
     {
         Util.debugLog("s2");
     }
 }
        public async Task PrintAsync(string file)
        {
            #region 印刷の準備

            _printDocument                 = new PrintDocument();
            _printDocumentSource           = _printDocument.DocumentSource;
            _printDocument.Paginate       += CreatePrintPreviewPages;
            _printDocument.GetPreviewPage += GetPreviewPage;
            _printDocument.AddPages       += AddPages;

            var printManager = PrintManager.GetForCurrentView();
            printManager.PrintTaskRequested += PrintTaskRequested;

            #endregion

            try
            {
                #region PDF情報 取得

                var storage = ApplicationData.Current.LocalFolder;
                var path    = await storage.GetFileAsync(file);

                var pdfDocument = await PdfDocument.LoadFromFileAsync(path);

                #endregion

                _imageList = new UListView();

                #region 印刷情報 取得

                try
                {
                    for (int i = 0; i < pdfDocument.PageCount; i++)
                    {
                        using (var page = pdfDocument.GetPage((uint)i))
                        {
                            var stream = new Windows.Storage.Streams.InMemoryRandomAccessStream();
                            await page.RenderToStreamAsync(stream);

                            // BitmapImage 作成
                            var src = new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                            var image = new UImage();
                            image.Source = src;

                            // BitmapImageをsrcにセット
                            await src.SetSourceAsync(stream);

                            _imageList.Items.Add(image);
                        }
                    }
                }
                finally
                {
                    pdfDocument = null;
                }

                #endregion

                if (PrintManager.IsSupported())
                {
                    // 印刷ダイアログ表示
                    await PrintManager.ShowPrintUIAsync();
                }
            }
            finally
            {
                // プリンターとの接続切断
                printManager.PrintTaskRequested -= PrintTaskRequested;
            }
        }
Beispiel #32
0
        private async void viewActivated(CoreApplicationView sender, Windows.ApplicationModel.Activation.IActivatedEventArgs args1)
        {
            FileOpenPickerContinuationEventArgs args = args1 as FileOpenPickerContinuationEventArgs;

            if (args != null)
            {
                if (args.Files.Count == 0) return;

                view.Activated -= viewActivated;
                StorageFile storageFile = args.Files[0];

                fileBytes = null;
                var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

                

                var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                
                await bitmapImage.SetSourceAsync(stream);

                fileBytes = new byte[stream.Size];

                await stream.ReadAsync(fileBytes.AsBuffer(), (uint)stream.Size, Windows.Storage.Streams.InputStreamOptions.None);

                var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
                imageDp.Source = bitmapImage;

                
               
                imageDp.Height = CoreApplication.GetCurrentView().CoreWindow.Bounds.Height;
                imageDp.Width = CoreApplication.GetCurrentView().CoreWindow.Bounds.Width;
                buttonAddImage.Content = "change image";
            }
        }