Answered by:
Code for opening a file in an metro app

Question
-
Hello guys
Can you please tell me the code for opening a file in xaml (metro) so the user can open a image and load it in the picturebox.
Thank You.
pratik
Thursday, December 6, 2012 3:49 PM
Answers
-
in xaml define a image:
<Image x:Name="imageElement" />
and in code
FileOpenPicker picker = new FileOpenPicker(); picker.FileTypeFilter.Add(".png"); var file = await picker.PickSingleFileAsync(); BitmapImage image = new BitmapImage(); IRandomAccessStream ram = await file.OpenAsync(FileAccessMode.Read); await image.SetSourceAsync(ram); imageElement.Source = image;
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
- Proposed as answer by Jesse Jiang Thursday, December 13, 2012 7:14 AM
- Marked as answer by Jesse Jiang Thursday, December 20, 2012 6:31 AM
Thursday, December 6, 2012 4:00 PM -
Hi,
I think you can begin with the XAML images sample
http://code.msdn.microsoft.com/windowsapps/0f5d56ae-5e57-48e1-9cd9-993115b027b9
Scenario4You can try the PixelDataProvider Class
http://msdn.microsoft.com/en-us/library/windows/apps/windows.graphics.imaging.pixeldataprovider
To operator the Pixel in Image.Best regards,
JesseJesse Jiang
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Proposed as answer by Jesse Jiang Thursday, December 13, 2012 7:14 AM
- Marked as answer by Jesse Jiang Thursday, December 20, 2012 6:31 AM
Thursday, December 13, 2012 7:13 AM
All replies
-
in xaml define a image:
<Image x:Name="imageElement" />
and in code
FileOpenPicker picker = new FileOpenPicker(); picker.FileTypeFilter.Add(".png"); var file = await picker.PickSingleFileAsync(); BitmapImage image = new BitmapImage(); IRandomAccessStream ram = await file.OpenAsync(FileAccessMode.Read); await image.SetSourceAsync(ram); imageElement.Source = image;
Microsoft Certified Solutions Developer - Windows Store Apps Using C#
- Proposed as answer by Jesse Jiang Thursday, December 13, 2012 7:14 AM
- Marked as answer by Jesse Jiang Thursday, December 20, 2012 6:31 AM
Thursday, December 6, 2012 4:00 PM -
Sir thank you sir can u please explain in detail should i put this under a command button? Moreover this is my app sir
http://www.codeproject.com/Articles/479896/A-Powerful-Photo-Editing-App-and-Effects
moreover i am new to xaml coding i knwo c# 2010 so sir if u could please elaborate and tell me.
Thank You.
pratik
Thursday, December 6, 2012 4:38 PM -
Hi,
I think you can begin with the XAML images sample
http://code.msdn.microsoft.com/windowsapps/0f5d56ae-5e57-48e1-9cd9-993115b027b9
Scenario4You can try the PixelDataProvider Class
http://msdn.microsoft.com/en-us/library/windows/apps/windows.graphics.imaging.pixeldataprovider
To operator the Pixel in Image.Best regards,
JesseJesse Jiang
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Proposed as answer by Jesse Jiang Thursday, December 13, 2012 7:14 AM
- Marked as answer by Jesse Jiang Thursday, December 20, 2012 6:31 AM
Thursday, December 13, 2012 7:13 AM