async private void BitmapTransformTest(){ // hard pred image location string filePath = "C:\Users\Public\Pictures\Sample Pictures\fantasy-dragons-wallpaper.jpg"; StorageFile file = await StorageFile.GetFileFromPathAsync(filePath); if (file == null) return; // create a stream from the file and depre the image var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); BitmapDeprer deprer = await BitmapDeprer.CreateAsync(fileStream); // create a new stream and enprer for the new image InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream(); BitmapEnprer enc = await BitmapEnprer.CreateForTranscodingAsync(ras, deprer); // convert the entire bitmap to a 100px by 100px bitmap enc.BitmapTransform.ScaledHeight = 100; enc.BitmapTransform.ScaledWidth = 100; BitmapBounds bounds = new BitmapBounds(); bounds.Height = 50; bounds.Width = 50; bounds.X = 50; bounds.Y = 50; enc.BitmapTransform.Bounds = bounds; // write out to the stream try { await enc.FlushAsync(); } catch (Exception ex) { string s = ex.ToString(); } // render the stream to the screen BitmapImage bImg = new BitmapImage(); bImg.SetSource(ras); img.Source = bImg; // image element in xaml}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)