Tôi có thể tạo WriteableBitmap từ ảnh trong Nội dung.Làm thế nào để tạo WriteableBitmap từ BitmapImage?
Uri imageUri1 = new Uri("ms-appx:///Assets/sample1.jpg");
WriteableBitmap writeableBmp = await new WriteableBitmap(1, 1).FromContent(imageUri1);
nhưng, tôi không thể tạo WriteableBitmap từ Hình Directory, (Tôi đang sử dụng WinRT XAML Toolkit)
//open image
StorageFolder picturesFolder = KnownFolders.PicturesLibrary;
StorageFile file = await picturesFolder.GetFileAsync("sample2.jpg");
var stream = await file.OpenReadAsync();
//create bitmap
BitmapImage bitmap2 = new BitmapImage();
bitmap2.SetSource();
bitmap2.SetSource(stream);
//create WriteableBitmap, but cannot
WriteableBitmap writeableBmp3 =
await WriteableBitmapFromBitmapImageExtension.FromBitmapImage(bitmap2);
Đây có phải là đúng?
Cảm ơn bạn đã trả lời, nhưng làm thế nào để mở hình ảnh dưới dạng writeablebitmap từ get go ,? Tôi nghĩ rằng [this] (http://stackoverflow.com/questions/4254225/opening-an-image-file-into-writablebitmap) có thể hữu ích, nhưng tôi không thể không vượt qua một bitmap trực tiếp vào một writablebitmap. – a2hiro
Không có liên kết nào dành cho Silverlight. Bạn cần có một StorageFile cho hình ảnh của bạn, ví dụ: bằng cách sử dụng bộ chọn tệp, sau đó chờ OpenReadAsync, sau đó tạo WriteableBitmap 1x1 và chờ SetSourceAsync. Kiểm tra điều này cho mẫu/tiện ích mở rộng: http://winrtxamltoolkit.codeplex.com/SourceControl/changeset/view/4d568d4e4c6a#WinRTXamlToolkit/Imaging/WriteableBitmapLoadExtensions.cs –