private async Task LoadOutputVirtualBitmap() { if (OutputVirtualBitmap != null) { OutputVirtualBitmap.Dispose(); OutputVirtualBitmap = null; } //LoadedImageInfo = ""; OutputVirtualBitmap = await CanvasVirtualBitmap.LoadAsync(OutputImageCanvas.Device, OutputImageStream, CanvasVirtualBitmapOptions.None); if (OutputImageCanvas == null) { // This can happen if the page is unloaded while LoadAsync is running return; } ImageResolution.Text = InputVirtualBitmap.Bounds.Width + " x " + InputVirtualBitmap.Bounds.Height + " | " + OutputVirtualBitmap.Bounds.Width + " x " + OutputVirtualBitmap.Bounds.Height; var size = OutputVirtualBitmap.Size; OutputImageCanvas.Width = size.Width * (Zoom + 1); OutputImageCanvas.Height = size.Height * (Zoom + 1); OutputImageCanvas.Invalidate(); //LoadedImageInfo = string.Format("{0}x{1} image, is {2}CachedOnDemand", size.Width, size.Height, virtualBitmap.IsCachedOnDemand ? "" : "not "); }
private async Task LoadVirtualBitmap() { if (virtualBitmap != null) { virtualBitmap.Dispose(); virtualBitmap = null; } LoadedImageInfo = ""; NotifyBitmapChanged(); virtualBitmap = await CanvasVirtualBitmap.LoadAsync(ImageVirtualControl.Device, imageStream, virtualBitmapOptions); if (ImageVirtualControl == null) { // This can happen if the page is unloaded while LoadAsync is running return; } var size = virtualBitmap.Size; ImageVirtualControl.Width = size.Width; ImageVirtualControl.Height = size.Height; ImageVirtualControl.Invalidate(); LoadedImageInfo = string.Format("{0}x{1} image, is {2}CachedOnDemand", size.Width, size.Height, virtualBitmap.IsCachedOnDemand ? "" : "not "); NotifyBitmapChanged(); }
private async void Pictures(StorageFile file) { using (IRandomAccessStream stream = await file.OpenReadAsync()) { App.Model.Name = file.DisplayName;//Name:名称 //图片 App.Model.SecondCanvasBitmap = await CanvasVirtualBitmap.LoadAsync(App.Model.VirtualControl, stream); //宽高 App.Model.Width = (int)App.Model.SecondCanvasBitmap.SizeInPixels.Width; App.Model.Height = (int)App.Model.SecondCanvasBitmap.SizeInPixels.Height; if (App.Model.Width > 16384) { App.Model.Width = 16384; } if (App.Model.Height > 16384) { App.Model.Height = 16384; } MainCenter(App.Model.SecondCanvasBitmap); App.Model.StartVisibility = Visibility.Collapsed; } }
private async Task LoadInputVirtualBitmap() { ContentFrame_Reset(); ContentFrameCollapse(); if (InputVirtualBitmap != null) { InputVirtualBitmap.Dispose(); InputVirtualBitmap = null; } //LoadedImageInfo = ""; InputVirtualBitmap = await CanvasVirtualBitmap.LoadAsync(InputImageCanvas.Device, InputImageStream, CanvasVirtualBitmapOptions.None); if (InputImageCanvas == null) { // This can happen if the page is unloaded while LoadAsync is running return; } var size = InputVirtualBitmap.Size; InputImageCanvas.Width = size.Width * (Zoom + 1); InputImageCanvas.Height = size.Height * (Zoom + 1); InputImageCanvas.Invalidate(); //LoadedImageInfo = string.Format("{0}x{1} image, is {2}CachedOnDemand", size.Width, size.Height, virtualBitmap.IsCachedOnDemand ? "" : "not "); }
//图片图层 private async void LayerImageButton_Click(object sender, RoutedEventArgs e) { //文件选择器 FileOpenPicker openPicker = new FileOpenPicker(); //选择视图模式 openPicker.ViewMode = PickerViewMode.Thumbnail; //初始位置 openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; //添加文件类型 openPicker.FileTypeFilter.Add(".jpg"); openPicker.FileTypeFilter.Add(".jpeg"); openPicker.FileTypeFilter.Add(".png"); openPicker.FileTypeFilter.Add(".bmp"); StorageFile file = await openPicker.PickSingleFileAsync();//打开选择器 if (file != null) { using (IRandomAccessStream stream = await file.OpenReadAsync()) { //图片 App.Model.SecondCanvasBitmap = await CanvasVirtualBitmap.LoadAsync(App.Model.VirtualControl, stream); App.InitializeOther(); Layers(); App.Model.isReRender = true; //重新渲染 App.Model.Refresh++; //画布刷新 App.Model.LayersCount = App.Model.Layers.Count; //Undo:撤销 } } }
static async Task <CanvasVirtualBitmap> CreateTestVirtualBitmap(ICanvasResourceCreatorWithDpi resourceCreator) { var canvasBitmap = CreateTestBitmap(resourceCreator, 96); var stream = new InMemoryRandomAccessStream(); await canvasBitmap.SaveAsync(stream, CanvasBitmapFileFormat.Png); return(await CanvasVirtualBitmap.LoadAsync(resourceCreator, stream)); }
static async Task <CanvasVirtualBitmap> CreateTestVirtualBitmap(ICanvasResourceCreatorWithDpi resourceCreator) { #if WINDOWS_UWP var canvasBitmap = CreateTestBitmap(resourceCreator, 96); var stream = new InMemoryRandomAccessStream(); await canvasBitmap.SaveAsync(stream, CanvasBitmapFileFormat.Png); return(await CanvasVirtualBitmap.LoadAsync(resourceCreator, stream)); #else await Task.Yield(); // prevent warning about no await in async method return(new CanvasVirtualBitmap()); #endif }
async Task LoadBitmaps(CanvasControl sender) { var bitmapType = CurrentBitmapType; var bitmapSource = CurrentBitmapSource; var newTestBitmaps = new ICanvasImage[fileNames.Length]; for (int i = 0; i < fileNames.Length; i++) { Package package = Package.Current; StorageFolder installedLocation = package.InstalledLocation; string pathName = installedLocation.Path + "\\" + "BitmapOrientation" + "\\" + fileNames[i]; if (bitmapSource == BitmapSourceOption.FromStream) { StorageFile storageFile = await StorageFile.GetFileFromPathAsync(pathName); using (IRandomAccessStreamWithContentType stream = await storageFile.OpenReadAsync()) { if (bitmapType == BitmapType.CanvasBitmap) { newTestBitmaps[i] = await CanvasBitmap.LoadAsync(sender, stream); } #if WINDOWS_UWP else { newTestBitmaps[i] = await CanvasVirtualBitmap.LoadAsync(sender, stream); } #endif } } else { if (bitmapType == BitmapType.CanvasBitmap) { newTestBitmaps[i] = await CanvasBitmap.LoadAsync(sender, pathName); } #if WINDOWS_UWP else { newTestBitmaps[i] = await CanvasVirtualBitmap.LoadAsync(sender, pathName); } #endif } } testBitmaps = newTestBitmaps; }
private async Task LoadVirtualBitmap() { try { ShowBusyIndicator("loading image..."); if (virtualBitmap != null) { virtualBitmap.Dispose(); virtualBitmap = null; } if (!string.IsNullOrEmpty(imageFilePath)) { var storageFile = await StorageFile.GetFileFromPathAsync(imageFilePath); using (var stream = await storageFile.OpenReadAsync()) { virtualBitmap = await CanvasVirtualBitmap.LoadAsync(MyCanvas.Device, stream); } } // This can happen if the page is unloaded while this method is running if (MyCanvas == null || virtualBitmap == null) { return; } MyCanvas.Width = virtualBitmap.Size.Width; MyCanvas.Height = virtualBitmap.Size.Height; MyCanvas.Invalidate(); } catch (Exception ex) { await new MessageDialog($"Something went wrong loading the image: {ex}", "Exception").ShowAsync(); } finally { HideBusyIndicator(); } }
private async void MenuOpen_Click(object sender, RoutedEventArgs e) { var picker = new FileOpenPicker(); picker.FileTypeFilter.Add(".png"); StorageFile file = await picker.PickSingleFileAsync(); if (file != null) { using (var stream = await file.OpenReadAsync()) { _bitmap = await CanvasVirtualBitmap.LoadAsync( ImageCanvas, stream, CanvasVirtualBitmapOptions.CacheOnDemand); } _scaleEffect.Source = _bitmap; _scaleEffect.Scale = new Vector2(1, 1); ImageCanvas.Width = _bitmap.Size.Width; ImageCanvas.Height = _bitmap.Size.Height; ImageCanvas.Invalidate(); } }
private async void GGGGG_Drop(object sender, DragEventArgs e) { if (e.DataView.Contains(StandardDataFormats.StorageItems) == true) { var def = e.GetDeferral(); var items = await e.DataView.GetStorageItemsAsync(); foreach (var item in items) { var file = item as StorageFile; if (file.FileType == ".jpg" | file.FileType == ".png") { using (IRandomAccessStream stream = await file.OpenReadAsync()) { App.Model.SecondCanvasBitmap = await CanvasVirtualBitmap.LoadAsync(App.Model.VirtualControl, stream); App.InitializeOther(); LayerControl_Layers(); } } } } }
//康戳键 private void KeyCtrl(VirtualKey value) { switch (value) { //Undo:撤销 case VirtualKey.Z: if (App.Model.isUndo) { Undo(); } break; case VirtualKey.Y: if (App.Model.isRedo) { Redo(); } break; case VirtualKey.S: HomeContentDialog.ShowAsync(); break; //Mask:选区 case VirtualKey.X: 修图.Control.MaskButton.Cut(); break; case VirtualKey.C: 修图.Control.MaskButton.Copy(); break; case VirtualKey.V: DataPackageView dataPackageView = Clipboard.GetContent(); if (dataPackageView.Contains(StandardDataFormats.Bitmap)) { IRandomAccessStreamReference imageReceived = null; imageReceived = dataPackageView.GetBitmapAsync().AsTask().Result; if (imageReceived != null) { using (IRandomAccessStream stream = imageReceived.OpenReadAsync().AsTask().Result) { App.Model.SecondCanvasBitmap = CanvasVirtualBitmap.LoadAsync(App.Model.VirtualControl, stream).AsTask().Result; App.InitializeOther(); LayerControl_Layers(); } } } else if (App.Model.isClipboard == true) { App.InitializeEffect(); MaskButton_Mask(102); } break; case VirtualKey.Delete: 修图.Control.MaskButton.Clear(); break; case VirtualKey.E: 修图.Control.MaskButton.Extract(); break; case VirtualKey.M: 修图.Control.MaskButton.Merge(); break; case VirtualKey.A: 修图.Control.MaskButton.All(); break; case VirtualKey.D: 修图.Control.MaskButton.Deselect(); break; case VirtualKey.P: 修图.Control.MaskButton.Pixel(); break; case VirtualKey.I: 修图.Control.MaskButton.Invert(); break; case VirtualKey.F: MaskButton_Mask(110); break; case VirtualKey.T: MaskButton_Mask(111); break; } }