На моем приложении Windows Phone 8.1 у меня есть функция камеры, но я не могу показать показ изображения в полноэкранном режиме. Кто-нибудь может понять, что нужно сделать?Приложение Windows Phone 8.1, отображающее изображение в полноэкранном режиме
ButtonCapture_Click
инициализирует изображение, а previewElement_Tapped
фактически принимает моментальный снимок.
Xaml:
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="0,18,0,18">
<TextBlock Text="StudyToolMobile" Style="{StaticResource TitleTextBlockStyle}" Margin="18,0"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="18,0,18,0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.ColumnSpan="2" Style="{StaticResource BodyTextBlockStyle}" Text="Enter some text below and click Save to insert a new TodoItem item into your database" TextWrapping="Wrap"/>
<TextBox Grid.Row="1" Grid.Column="0" Name="TextInput" Text="" />
<StackPanel Grid.Row ="1" Grid.Column="1" Orientation="Horizontal">
<AppBarButton Label="Photo" Icon="Camera" Name="ButtonCapture"
Click="ButtonCapture_Click" Height="78" Width="62" />
<AppBarButton Label="Upload" Icon="Upload" Name="ButtonSave"
Click="ButtonSave_Click"/>
</StackPanel>
<Grid Grid.Row="2" Name="captureGrid" Grid.RowSpan="3" Grid.ColumnSpan="2"
Canvas.ZIndex="99" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
Visibility="Collapsed">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<CaptureElement Grid.Row="0" x:Name="previewElement" Tapped="previewElement_Tapped" />
<Image Grid.Row="0" Name="imagePreview" Visibility="Collapsed" Margin="0,262,0,115" />
<StackPanel Grid.Row="1" Name="captureButtons"
Orientation="Horizontal" Visibility="Collapsed">
<TextBlock Name="TextCapture" VerticalAlignment="Bottom" />
<AppBarButton Label="Retake" Icon="Redo" Name="ButtonRetake"
Click="ButtonRetake_Click" />
<AppBarButton Label="Cancel" Icon="Cancel" Name="ButtonCancel"
Click="ButtonCancel_Click" />
</StackPanel>
</Grid>
<TextBlock Grid.Row="2" Grid.ColumnSpan="2" Style="{StaticResource BodyTextBlockStyle}" Text="Click refresh below to load the unfinished TodoItems from your database. Use the checkbox to complete and update your TodoItems" TextWrapping="Wrap"/>
<Button Grid.Row="3" Grid.ColumnSpan="2" Name="ButtonRefresh" Click="ButtonRefresh_Click" HorizontalAlignment="Stretch">Refresh</Button>
<ListView Grid.Row="4" Grid.ColumnSpan="2" Name="ListItems">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<CheckBox Name="CheckBoxComplete" IsChecked="{Binding Complete, Mode=TwoWay}"
Checked="CheckBoxComplete_Checked" Content="{Binding Text}"
Margin="10,5" VerticalAlignment="Center"/>
<Image Name="ImageUpload" Source="{Binding ImageUri, Mode=OneWay}"
MaxHeight="150"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Grid>
Код:
// Use a StorageFile to hold the captured image for upload.
StorageFile media = null;
MediaCapture cameraCapture;
bool IsCaptureInProgress;
private async Task CaptureImage()
{
// Capture a new photo or video from the device.
cameraCapture = new MediaCapture();
cameraCapture.Failed += cameraCapture_Failed;
// Initialize the camera for capture.
await cameraCapture.InitializeAsync();
cameraCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
cameraCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);
captureGrid.Visibility = Windows.UI.Xaml.Visibility.Visible;
previewElement.Visibility = Windows.UI.Xaml.Visibility.Visible;
previewElement.Source = cameraCapture;
await cameraCapture.StartPreviewAsync();
}
private async void previewElement_Tapped(object sender, TappedRoutedEventArgs e)
{
// Block multiple taps.
if (!IsCaptureInProgress)
{
IsCaptureInProgress = true;
Random rnd = new Random();
int number = rnd.Next(1, 20);
string numberString = number.ToString();
string jpgName = numberString + ".jpg";
// Create the temporary storage file.
media = await ApplicationData.Current.LocalFolder
.CreateFileAsync(jpgName, CreationCollisionOption.ReplaceExisting);
// Take the picture and store it locally as a JPEG.
await cameraCapture.CapturePhotoToStorageFileAsync(
ImageEncodingProperties.CreateJpeg(), media);
captureButtons.Visibility = Visibility.Visible;
// Use the stored image as the preview source.
BitmapImage tempBitmap = new BitmapImage(new Uri(media.Path));
imagePreview.Source = tempBitmap;
imagePreview.Visibility = Visibility.Visible;
previewElement.Visibility = Visibility.Collapsed;
IsCaptureInProgress = false;
}
}
private async void cameraCapture_Failed(MediaCapture sender, MediaCaptureFailedEventArgs errorEventArgs)
{
// It's safest to return this back onto the UI thread to show the message dialog.
MessageDialog dialog = new MessageDialog(errorEventArgs.Message);
await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
async() => { await dialog.ShowAsync(); });
}
private async void ButtonCapture_Click(object sender, RoutedEventArgs e)
{
// Prevent multiple initializations.
ButtonCapture.IsEnabled = false;
await CaptureImage();
}
@Vigs у вас Изображение полноэкранное, когда вы удалили поля? –
Нет, это не сработало :( – Vigs
Ok. Когда вы удалили поля, какими были размеры изображения? –