i creating image editing application. want give option user can capture image @ run time , apply editing effects on captured. @ moment following instructions advanced photo capture windows phone 8.
there 2 problems first facing when hit capture button image captured inverted image. if put phone in landscape mode take right picture.
when app starts there nothing on screen in other words totally black. want screen show camera view user knows going capture.
below code mainpage.xaml.cs file , mainpage.xaml file.
namespace capturingphoto { public partial class mainpage : phoneapplicationpage { private memorystream imagestream; private photocapturedevice capturedevice; private cameracapturesequence seq; // constructor public mainpage() { initializecomponent(); imagestream = new memorystream(); // sample code localize applicationbar //buildlocalizedapplicationbar(); prepareresoucetocapture(); } private async void prepareresoucetocapture() { if((!photocapturedevice.availablesensorlocations.contains(camerasensorlocation.back)) && (!photocapturedevice.availablesensorlocations.contains(camerasensorlocation.front))){ return; } windows.foundation.size size; if(photocapturedevice.availablesensorlocations.contains(camerasensorlocation.back)){ ireadonlylist <windows.foundation.size> avalaiblesizelist = photocapturedevice.getavailablecaptureresolutions(camerasensorlocation.back); size = avalaiblesizelist[0]; this.capturedevice = await photocapturedevice.openasync(camerasensorlocation.back, size); } else{ ireadonlylist<windows.foundation.size> avalaiblesizelist = photocapturedevice.getavailablecaptureresolutions(camerasensorlocation.front); size = avalaiblesizelist[0]; this.capturedevice = await photocapturedevice.openasync(camerasensorlocation.front, size); } // await this.capturedevice.setcaptureresolutionasync(size); // await this.capturedevice.setpreviewresolutionasync(size); // backgroundvideobrush.setsource(this.capturedevice); } private async void oncaptureimage(object sender, routedeventargs e) { seq = capturedevice.createcapturesequence(1); capturedevice.setproperty(knowncameraphotoproperties.flashmode, flashstate.on); capturedevice.setproperty(knowncamerageneralproperties.playshuttersoundoncapture, false); capturedevice.setproperty(knowncamerageneralproperties.autofocusrange, autofocusrange.normal); seq.frames[0].capturestream = imagestream.asoutputstream(); await capturedevice.preparecapturesequenceasync(seq); captureimage(); } public async void captureimage() { await seq.startcaptureasync(); // set stream position beginning. imagestream.seek(0, seekorigin.begin); medialibrary library = new medialibrary(); picture picture1 = library.savepicturetocameraroll("image1", imagestream); } }
}
code xaml file
<phone:phoneapplicationpage x:class="capturingphoto.mainpage" 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" mc:ignorable="d" fontfamily="{staticresource phonefontfamilynormal}" fontsize="{staticresource phonefontsizenormal}" foreground="{staticresource phoneforegroundbrush}" supportedorientations="portrait" orientation="portrait" shell:systemtray.isvisible="true"> <!--layoutroot root grid page content placed--> <grid x:name="layoutroot" background="transparent" height="768" verticalalignment="bottom"> <grid.rowdefinitions> <rowdefinition height="auto"/> <rowdefinition height="*"/> </grid.rowdefinitions> <!-- localization note: localize displayed strings copy values appropriately named keys in app's neutral language resource file (appresources.resx) replace hard-coded text value between attributes' quotation marks binding clause path points string name. example: text="{binding path=localizedresources.applicationtitle, source={staticresource localizedstrings}}" binding points template's string resource named "applicationtitle". adding supported languages in project properties tab create new resx file per language can carry translated values of ui strings. binding in these examples cause value of attributes drawn .resx file matches currentuiculture of app @ run time. --> <!--contentpanel - place additional content here--> <canvas x:name="videocanvas" rendertransformorigin="0.5,0.5" canvas.zindex="0"> <canvas.rendertransform> <compositetransform/> </canvas.rendertransform> <canvas.background> <!-- background contains camera view finder encapsulated in videobrush. --> <videobrush x:name="backgroundvideobrush" > <videobrush.relativetransform> <compositetransform x:name="videobrushtransform" centery="0.5" centerx="0.5"/> </videobrush.relativetransform> </videobrush> </canvas.background> </canvas> <button x:name="btn_edit" content="capture" horizontalalignment="left" margin="23,691,0,0" verticalalignment="top" width="400" click="oncaptureimage"/> <!--uncomment see alignment grid ensure controls aligned on common boundaries. image has top margin of -32px account system tray. set 0 (or remove margin altogether) if system tray hidden. before shipping remove xaml , image itself.--> <!--<image source="/assets/alignmentgrid.png" verticalalignment="top" height="800" width="480" margin="0,-32,0,0" grid.row="0" grid.rowspan="2" ishittestvisible="false" />--> </grid>
i see string:
backgroundvideobrush.setsource(this.capturedevice);
is comment. can't see camera view, if videobrush empty.
Comments
Post a Comment