http://windowsphone.com/s?
指定した時間にアラームが鳴る機能と日付の焼きこんだ写真が撮れる機能を合わせたアプリです。
参考にしたページ
高橋 忍のブログ : アプリケーション自身のスクリーンキャプチャ機能の実装ブリリアントなWP7 : カメラで撮影した画像を保存する 画像ファイルを端末内に保存する
CH3COOH(酢酸)の実験室 : 静止画撮影を行う
です。特に高橋忍さんのページはコードをほぼコピーしている箇所があって、シャッターを押した後のメッセージ内容がまったく同じままにしてしまっていました。ごめんなさい。見る人が見れば、コピペしただけだろーと突っ込まれるかもしれないので、ここで白状しておきます
時計の表示を更新する部分も誰かの記述を参考にしましたが、どこだったか思い出せません
時計部分のコードとXAMLをのっけておきます。
時計はタイマーで更新してます。文字の縁取りをするために数ピクセルずらした黒文字を4方向分の4回レンダリングしてます。(こんなんでいいのか?)
カメラの撮影は参考にしたコードをほぼそのままで、普通に撮影します。
撮影完了したら、写真の画像をlayoytrootの背景に描き出して、スクリーンキャプチャします
ほんとにこんなんで良いのか?って気もしますが、以上です。ここまでは数時間でできました。
一番時間がかかったのは、日時設定画面を作る事とアイコン作る事です。アイコンはちょっと画像がデカすぎたようです...
です。特に高橋忍さんのページはコードをほぼコピーしている箇所があって、シャッターを押した後のメッセージ内容がまったく同じままにしてしまっていました。ごめんなさい。見る人が見れば、コピペしただけだろーと突っ込まれるかもしれないので、ここで白状しておきます
時計の表示を更新する部分も誰かの記述を参考にしましたが、どこだったか思い出せません
![]() |
起動画面、アラームの設定と、カメラの撮影ページへの移行ができます |
![]() |
撮影した写真。画像サイズや撮影モードを切り替えたりとかはできません!ただシャッターボタンを押すだけです |
時計部分のコードとXAMLをのっけておきます。
時計はタイマーで更新してます。文字の縁取りをするために数ピクセルずらした黒文字を4方向分の4回レンダリングしてます。(こんなんでいいのか?)
カメラの撮影は参考にしたコードをほぼそのままで、普通に撮影します。
撮影完了したら、写真の画像をlayoytrootの背景に描き出して、スクリーンキャプチャします
ほんとにこんなんで良いのか?って気もしますが、以上です。ここまでは数時間でできました。
一番時間がかかったのは、日時設定画面を作る事とアイコン作る事です。アイコンはちょっと画像がデカすぎたようです...
- public partial class ClockPage : PhoneApplicationPage
- {
- bool nowCapturering = false;
- PhotoCamera camera = null;
- public ClockPage()
- {
- InitializeComponent();
- CameraButtons.ShutterKeyPressed += new EventHandler(CameraButtons_ShutterKeyPressed);
- DispatcherTimer tmr = new DispatcherTimer();
- tmr.Interval = TimeSpan.FromSeconds(1);
- tmr.Tick += new EventHandler(tmr_Tick);
- tmr.Start();
- }
- void camera_CaptureThumbnailAvailable(object sender, ContentReadyEventArgs e)
- {
- System.Diagnostics.Debug.WriteLine("camera_CaptureThumbnailAvailable");
- }
- void camera_CaptureImageAvailable(object sender, ContentReadyEventArgs e)
- {
- System.Diagnostics.Debug.WriteLine("camera_CaptureImageAvailable");
- this.Dispatcher.BeginInvoke(delegate()
- {
- BitmapImage bmp = new BitmapImage();
- bmp.SetSource(e.ImageStream);
- CaptureBrush.ImageSource = bmp;
- TakeCapture();
- nowCapturering = false;
- });
- }
- void camera_CaptureCompleted(object sender, CameraOperationCompletedEventArgs e)
- {
- System.Diagnostics.Debug.WriteLine("camera_CaptureCompleted");
- }
- void CameraButtons_ShutterKeyPressed(object sender, EventArgs e)
- {
- nowCapturering = true;
- camera.CaptureImage();
- }
- protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
- {
- camera = new PhotoCamera(CameraType.Primary);
- //camera.CaptureThumbnailAvailable += new EventHandler<contentreadyeventargs&rt;(camera_CaptureThumbnailAvailable);
- camera.CaptureImageAvailable += new EventHandler<contentreadyeventargs&rt;(camera_CaptureImageAvailable);
- camera.CaptureCompleted += new EventHandler<cameraoperationcompletedeventargs&rt;(camera_CaptureCompleted);
- nowCapturering = false;
- PreviewBrush.SetSource(camera);
- base.OnNavigatedTo(e);
- }
- protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
- {
- if (camera != null)
- {
- camera.Dispose();
- camera.CaptureImageAvailable -= camera_CaptureImageAvailable;
- camera.CaptureCompleted -= camera_CaptureCompleted;
- camera = null;
- }
- base.OnNavigatingFrom(e);
- }
- void tmr_Tick(object sender, EventArgs e)
- {
- if (!nowCapturering)
- {
- textBlock1.Text = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss");
- }
- }
- private void TakeCapture()
- {
- WriteableBitmap bitmap = new WriteableBitmap(this.LayoutRoot, null);
- MemoryStream stream = new MemoryStream();
- bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 80);
- using (MediaLibrary medialib = new MediaLibrary())
- {
- Picture pic = medialib.SavePictureToCameraRoll(DateTime.Now.ToString("yyMMddHHmmss"), stream.ToArray());
- }
- MessageBox.Show("Saved");
- }
xaml
- <phone:PhoneApplicationPage
- x:Class="Serial11.ClockPage"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
- xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- FontFamily="{StaticResource PhoneFontFamilyNormal}"
- FontSize="{StaticResource PhoneFontSizeNormal}"
- Foreground="{StaticResource PhoneForegroundBrush}"
- SupportedOrientations="Landscape" Orientation="Landscape"
- mc:Ignorable="d" d:DesignHeight="480" d:DesignWidth="728"
- Language="ja-JP"
- shell:SystemTray.IsVisible="True">
- <!--LayoutRoot は、すべてのページ コンテンツが配置されるルート グリッドです-->
- <Grid x:Name="LayoutRoot">
- <Grid.Background>
- <ImageBrush x:Name="CaptureBrush"/>
- </Grid.Background>
- <Grid x:Name="ContentPanel">
- <Rectangle x:Name="PreviewRectangle">
- <Rectangle.Fill>
- <VideoBrush x:Name="PreviewBrush"/>
- </Rectangle.Fill>
- </Rectangle>
- <StackPanel HorizontalAlignment="Right" VerticalAlignment="Bottom" Orientation="Horizontal">
- <Grid Margin="0,0,10,0">
- <TextBlock x:Name="textBlock3" Text="{Binding Text, ElementName=textBlock1}" VerticalAlignment="Top" FontFamily="Segoe WP Black" FontSize="48" Margin="0" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5" Foreground="Black">
- <TextBlock.RenderTransform>
- <CompositeTransform TranslateX="3" TranslateY="3"/>
- </TextBlock.RenderTransform>
- </TextBlock>
- <TextBlock x:Name="textBlock4" Text="{Binding Text, ElementName=textBlock1}" VerticalAlignment="Top" FontFamily="Segoe WP Black" FontSize="48" Margin="0" Foreground="Black" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5" >
- <TextBlock.RenderTransform>
- <CompositeTransform TranslateX="-3" TranslateY="3"/>
- </TextBlock.RenderTransform>
- </TextBlock>
- <TextBlock x:Name="textBlock5" Text="{Binding Text, ElementName=textBlock1}" VerticalAlignment="Top" FontFamily="Segoe WP Black" FontSize="48" Margin="0" Foreground="Black" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5" >
- <TextBlock.RenderTransform>
- <CompositeTransform TranslateX="-3" TranslateY="-3"/>
- </TextBlock.RenderTransform>
- </TextBlock>
- <TextBlock x:Name="textBlock6" Text="{Binding Text, ElementName=textBlock1}" VerticalAlignment="Top" FontFamily="Segoe WP Black" FontSize="48" Margin="0" Foreground="Black" HorizontalAlignment="Right" RenderTransformOrigin="0.5,0.5" >
- <TextBlock.RenderTransform>
- <CompositeTransform TranslateX="3" TranslateY="-3"/>
- </TextBlock.RenderTransform>
- </TextBlock>
- <TextBlock x:Name="textBlock1" Text="----/--/-- --:--:--" VerticalAlignment="Top" FontFamily="Segoe WP Black" FontSize="48" Margin="0" Foreground="Yellow" HorizontalAlignment="Right" />
- </Grid>
- </StackPanel>
- </Grid>
- </Grid>
- <!--ApplicationBar の使用法を示すサンプル コード-->
- <!--<phone:PhoneApplicationPage.ApplicationBar>
- <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
- <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
- <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
- <shell:ApplicationBar.MenuItems>
- <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
- <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
- </shell:ApplicationBar.MenuItems>
- </shell:ApplicationBar>
- </phone:PhoneApplicationPage.ApplicationBar>-->
- </phone:PhoneApplicationPage>
0 件のコメント:
コメントを投稿