WriteableBitmap's PixelWidth and PixelHeight propery does not change after a new SetSource
-
Friday, August 10, 2012 12:23 PM
I am not able to retrieve the width and the height of an image after I load it from a StorageFile object. Here is the code...
FileOpenPicker^ openPicker = ref new FileOpenPicker(); openPicker->ViewMode = PickerViewMode::Thumbnail; openPicker->SuggestedStartLocation = PickerLocationId::PicturesLibrary; openPicker->FileTypeFilter->Append(".jpg"); openPicker->FileTypeFilter->Append(".jpeg"); openPicker->FileTypeFilter->Append(".png"); auto getStreamTask = create_task(openPicker->PickSingleFileAsync()).then([this](StorageFile^ file) { return file->OpenReadAsync(); }); getStreamTask.then( [this] (Windows::Storage::Streams::IRandomAccessStreamWithContentType^ stream) { WriteableBitmap^ bmp = ref new WriteabeBitmap(1, 1); bmp->SetSource(stream); displayImage->Source = bmp; // Displays correctly int Witdh = bmp->PixelWidth; // Remains 1 int Height = bmp->PixelHeight; // Remains 1 });The PixelHeight and PixelWidth propery remains (1,1) for the bitmap. I tried displaying it in an image object in XAML and the image is displayed correctly though.
All Replies
-
Monday, August 13, 2012 11:21 AMModerator
Hi,
Yes, writeableBitmap cannot calculate the height and width of that image, you can use BitmapImage class to get it.
BitmapImage^ bmp=ref new BitmapImage(); bmp->SetSource(stream); //bm->PixelHeight //WriteableBitmap^ bmp = ref new WriteabeBitmap(1, 1); //bmp->SetSource(stream); //displayImage->Source = bmp; // Displays correctly int Witdh = bmp->PixelWidth; // Remains 1 int Height = bmp->PixelHeight; // Remains 1
Best regards,
Jesse
Jesse Jiang [MSFT]
MSDN Community Support | Feedback to us
- Marked As Answer by pragos Monday, August 13, 2012 5:19 PM
-
Monday, August 13, 2012 5:19 PMThanks Jesse!


