내 응용 프로그램에 기본 페이지와 카메라 페이지가 있습니다. 기본 페이지에는 원본 세트 및 버튼이없는 이미지가 있습니다. 버튼을 클릭하면 카메라 페이지로 이동합니다. 카메라 페이지에서 이미지를 캡처하여 태블릿의 그림 라이브러리에 저장 한 다음 기본 이미지 페이지로 돌아가서 방금 촬영 한 이미지를 내 그림 라이브러리에 저장하고 싶습니다 . 여기에 관련 코드가 있습니다.메트로 앱에서 프로그래밍 방식으로 이미지 소스를 설정하면 이미지가 나타나지 않습니다.
에서 MainPage.xaml
<Image x:Name="imgResume" HorizontalAlignment="Left" Height="303" Margin="975,60,0,0" Grid.Row="1" VerticalAlignment="Top" Width="360" Stretch="UniformToFill" Loaded="img_OnLoaded"/>
<Button x:Name="btnCamera" Content="Camera" HorizontalAlignment="Left" Margin="1128,372,0,0" Grid.Row="1" VerticalAlignment="Top" RenderTransformOrigin="2.05800008773804,0.184000000357628" Height="59" Width="108" Click="Camera_Click" IsEnabled="False"/>
MainPage.xaml.cs를
private void img_OnLoaded(object sender, RoutedEventArgs e)
{
if (txtFirstName.Text != "" && txtLastName.Text != "")
{
try
{
imgResume.Source = ImageFromRelativePath(this, Windows.Storage.KnownFolders.PicturesLibrary.Path + ((App)Application.Current).candidate.FirstName + ((App)Application.Current).candidate.FirstName + "Resume.jpg");
imgResume.UpdateLayout();
}
catch
{
imgResume.Source = ImageFromRelativePath(this, @"Assets/logo.png");
imgResume.UpdateLayout();
}
btnCamera.IsEnabled = true;
}
}
public static BitmapImage ImageFromRelativePath(FrameworkElement parent, string path)
{
var uri = new Uri(parent.BaseUri, path);
BitmapImage result = new BitmapImage();
result.UriSource = uri;
return result;
}
Camera.xaml.cs에서 MainPage.xaml 파일의 img_OnLoaded 방법을 시도
private async void Capture_Click(object sender, RoutedEventArgs e)
{
if (mediaCaptureMgr != null)
{
string firstName = ((App)Application.Current).candidate.FirstName;
string lastName = ((App)Application.Current).candidate.LastName;
string fileName = firstName + lastName + "Resume.jpg";
Windows.Storage.IStorageFile photo = await Windows.Storage.KnownFolders.PicturesLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.ReplaceExisting);
await mediaCaptureMgr.CapturePhotoToStorageFileAsync(Windows.Media.MediaProperties.ImageEncodingProperties.CreateJpeg(), photo);
this.Frame.Navigate(typeof(BasicPersonalInfo));
}
}
Camera.xaml.cs의 Capture_click 메서드에서 이미지 라이브러리에 저장 한 이미지로 이미지 소스를 설정합니다.
제 문제는 그림이 첫 페이지의 이미지에 나타나지 않는다는 것입니다. 도와주세요!
두 답변을 모두 시도했지만 나에게 도움이되지 않습니다. 이 페이지에서 어떤 해결책을 찾았지만 완전히 작동합니다. [http://www.c-sharpcorner.com/UploadFile/99bb20/load-image-dynamically-from-application-uri-in-windows-store/](http://www.c-sharpcorner.com/UploadFile)/99bb20/load-image-dynamic-from-application-uri-in-windows-store /) –