Okay so I'm using the below code to display the camera in my app and it works great! the problem is when i navigate away and come back to the app using the back stack the camera is not showing until i call the code manually.
how can i get it to show automatically ?
Thank Youuu in advance
Dim cam As New Microsoft.Devices.PhotoCamera()
Public Sub New()
InitializeComponent()
SupportedOrientations = SupportedPageOrientation.Portrait
End Sub
Private Sub opening() Handles Me.Loaded
cam = New Microsoft.Devices.PhotoCamera()
viewfinderBrush.RelativeTransform = New CompositeTransform() With {.CenterX = 0.5, .CenterY = 0.5, .Rotation = 90}
viewfinderBrush.SetSource(cam)
End Sub
Private Sub Closing() Handles Me.Unloaded
cam.Dispose()
End Sub
Fixed my Own Problem, just used protected overide subs :)
Like So
Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
MyBase.OnNavigatedTo(e)
cam = New Microsoft.Devices.PhotoCamera()
viewfinderBrush.RelativeTransform = New CompositeTransform() With {.CenterX = 0.5, .CenterY = 0.5, .Rotation = 90}
viewfinderBrush.SetSource(cam)
End Sub
Protected Overrides Sub OnNavigatedFrom(e As NavigationEventArgs)
MyBase.OnNavigatedFrom(e)
If cam IsNot Nothing Then
cam.Dispose()
cam = Nothing
End If
End Sub
Related
I am totally lost at the moment. What is wrong with my animation? Why is it not running? Any help would be highly appreciated! I want to develop sort of an circular progress bar which is "rolling in" as if the bar was filled up.
The following code runs inside an empty UWP app in the MainPage's Loaded Handler. Nothing else...
ArcSegment myArcSegment = new ArcSegment();
myArcSegment.Size = new Size(90, 80);
myArcSegment.SweepDirection = SweepDirection.Clockwise;
PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
myPathSegmentCollection.Add(myArcSegment);
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = new Point(100, 200);
myPathFigure.Segments = myPathSegmentCollection;
PathFigureCollection myPathFigureCollection = new PathFigureCollection();
myPathFigureCollection.Add(myPathFigure);
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures = myPathFigureCollection;
Path myPath = new Path();
myPath.Stroke = new SolidColorBrush(Colors.Aqua);
myPath.StrokeThickness = 1;
myPath.Data = myPathGeometry;
PointAnimation mySizeAnimation = new PointAnimation();
mySizeAnimation.Duration = TimeSpan.FromSeconds(2);
mySizeAnimation.From = new Point(90, 80);
mySizeAnimation.To = new Point(500, 200);
Storyboard.SetTarget(mySizeAnimation, myArcSegment);
Storyboard.SetTargetProperty(mySizeAnimation, nameof(ArcSegment.Point));
Storyboard ellipseStoryboard = new Storyboard();
ellipseStoryboard.Children.Add(mySizeAnimation);
myPath.Loaded += delegate (object o, RoutedEventArgs e)
{
ellipseStoryboard.Begin();
};
Canvas containerCanvas = new Canvas();
containerCanvas.Children.Add(myPath);
Content = containerCanvas;
Thank you for your help!
Oh my... I just read this post: http://blog.jerrynixon.com/2012/06/windows-8-animated-pie-slice.html
By accident I read about the EnableDependendAnimation Property... never heared of it, but Setting it to true just made the Animation run. I will read up on that now. Thanks anyways!
I am using WebCamTexture class to open camera from device. I want to switch camera from front to back and vice versa in between the game play. Can anybody help?
WebCamDevice[] devices = WebCamTexture.devices;
WebCamTexture webCamTexture = new WebCamTexture(devices[1].name);
renderer.material.mainTexture = webCamTexture;
webCamTexture.filterMode = FilterMode.Trilinear;
webCamTexture.Play();
This opens my front camera. But I can't switch the camera.
I got the solution. You just need to set the name of the device. By default back camera is "Camera 0" and "Camera 1" front camera. First Stop your camera , change the set device.
if (devices.Length > 1) {
webCamTexture.Stop();
if (frontCamera == true)
{
webCamTexture.deviceName = devices[0].name;
frontCamera = false;
}
else
{
webCamTexture.deviceName = devices[1].name;
frontCamera = true;
}
webCamTexture.Play ();
}
I have used the following code for switching the front and back camera of the iPhone Device using C# script
WebCamDevice[] devices;
public WebCamTexture mCamera = null;
public GameObject plane; // this is the object where i am going to show the camera
// Use this for initialization
void Start ()
{
devices = WebCamTexture.devices;
plane = GameObject.FindWithTag ("Player");
mCamera = new WebCamTexture (Screen.width,Screen.height);
mCamera.deviceName = devices[0].name; // Front camera is at Index 1 and Back Camera is at Index 0
plane.renderer.material.mainTexture = mCamera;
mCamera.Play ();
}
the above code will show the back Camera when the Scene is loaded ,for accessing the front camera on the click of front button defined below
if (GUI.Button (new Rect (100, 1000, 120, 40), "Front"))
{
if(devices.Length>1)
{
mCamera.Stop();
mCamera.deviceName = (mCamera.deviceName == devices[0].name) ? devices[1].name : devices[0].name;
mCamera.Play();
}
}
This is button, by clicking it will redirect to front camera and again clicking it will redirect to back camera alternatively
if (devices.Length > 1) {
webCamTexture.Stop();
if (frontCamera == true)
{
webCamTexture.deviceName = devices[0].name;
frontCamera = WebCamTexture.devices[0].isFrontFacing;
}
else
{
webCamTexture.deviceName = devices[1].name;
frontCamera = WebCamTexture.devices[1].isFrontFacing;
}
webCamTexture.Play ();
}
We've used Camera Capture Kit for a social image sharing game/app to do a similar functionality to what you are describing, The other solution presented here is not 100% solid, since there might potentially be devices with different order of front and back-facing devices.
Basically, I'm almost finished making this note app which the users save notes etc. Basic note app function. The reason I'm not fully done is that i just need help with adding tiles to my app for the notes. Basically the user clicks the "Pin to start" from the menu item and for the selected note, pins that to the start. I've done this through:
Private Sub PinToStart_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
Dim Storage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
Dim data As SampleData = TryCast(TryCast(sender, MenuItem).DataContext, SampleData)
Dim selectedItem As ListBoxItem = TryCast(Me.SavedNotesList.ItemContainerGenerator.ContainerFromItem(data), ListBoxItem)
Dim directory As String = "./MyNote/SavedNotes/*.*"
Dim filenames As String() = Storage.GetFileNames(directory)
Dim dataSource As New List(Of SampleData)()
For Each filename As String In filenames
Dim ISF As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
Dim FS As IsolatedStorageFileStream = ISF.OpenFile("MyNote/SavedNotes/" & filename, FileMode.Open, FileAccess.Read)
Dim FETime As String = Storage.GetCreationTime("MyNote/SavedNotes/" & data.FileNameX).ToString("dd/mm/yyyy h:mmtt")
Dim tileData As New StandardTileData() With { _
.Title = data.FileNameX, _
.BackgroundImage = New Uri("/Assets/202.png", UriKind.Relative), _
.BackTitle = data.FileNameX, _
.BackContent = data.Description}
ShellTile.Create(New Uri("/ViewPage.xaml?Title=" & data.FileNameX & "&Body=" & data.Description, UriKind.Relative), tileData)
Next
End Sub
Currently this is the code which creates the tile. Although there is one problem, once the tile is created it throws an exception and says "Tiles can only be created when the application is in the foreground" but it still proceeds and creates the tile with no problem. Second error i have is that I need a way to update the tile. I just don't know how.
Can anyone help me?
use HubTile control from Microsoft.Phone.Controls.Toolkit to created tile
you can try this code:
var shellTileData = new StandardTileData
{
BackgroundImage = new Uri("Path for image", UriKind.RelativeOrAbsolute),
BackContent = "xyz"
};
var tile = ShellTile.ActiveTiles.First();
tile.Update(shellTileData);
i am showing images from server. In server image is changing in every second. I want that in my application image should be change automatically after one second.M new in windows 7 programming. Kindly suggest me where i am lacking in concept. M using this code.
This process will start when i will tab on my image.
private void image1_Tap(object sender, GestureEventArgs e)
{
System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();
dt.Interval = new TimeSpan(0, 0, 0, 0, 1000); // 500 Milliseconds
dt.Tick += new EventHandler(dt_Tick);
dt.Start();
}
This is calling this method .
void dt_Tick(object sender, EventArgs e)
{
status.Text = "chking" + counter++;
// Do Stuff here.
image1.Source = null;
Uri imgUri = new Uri(base_url,UriKind.Absolute);
BitmapImage BI = new BitmapImage(imgUri);
int H = BI.PixelHeight;
int w = BI.PixelWidth;
image1.Source = BI;
}
In this code my Counter is working fine and status.Text is sucessfully change in every second. But image is changing once after that its not changing.
Kinldy suggest me where i am commiting mistake.
Thanks in advance
Gaurav Gupta
I think you should declare System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer(); as a member variable instead of declaring it in the images tap event.
I do the same thing when grabbing images from a camera in my wp8 app. I hold the URL including the current datetime-value as a url-param in my viewmodel. When i want to refresh, i just reset my URL-property.
Here's my sample:
this.MyUrlProperty = string.Format("{0}?timestamp={1:yyyy-MM-dd HH:mm:ss:fff}", _originalCameraUrl, DateTime.Now);
Works great for me...
In my app I want to display a simple string within a popup when the user clicks on an image. For this I added a Tap gesture listener to the image and within the handler I have the following code:
private void GestureListener_Tap( object sender, GestureEventArgs e )
{
var img = sender as Image;
if( img == null ) {
return;
}
Point pos = e.GetPosition( img );
string text = "I'm a popup!";
var popup = new Popup() {
Child = new Border() {
BorderBrush = new SolidColorBrush( Colors.LightGray ),
Child = new TextBlock() {
Text = text,
TextWrapping = TextWrapping.Wrap,
},
},
HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalOffset = pos.X,
VerticalOffset = pos.Y,
Visibility = Visibility.Visible,
};
popup.IsOpen = true;
Debug.WriteLine( "GestureListener_Tap: " + text );
}
The call to WriteLine prints in the debugger output window but the popup doesn't get displayed. What am I doing wrong here?
Thanks for your help!
I tried your code and the Popup is displayed. I think the problem for you is the Position for the Image relative to the Mouse. Try to set another Background for the Parent Container and I think you'll see the Popup. You can also try to play around with
Point pos = e.GetPosition(null);
until you get the Position you require