Is there any way to capture an image using the camera, programatically, without the user pressing a button? - windows-phone-7

I wish to take a picture on a timer, and process the image at regular intervals, but cannot find anything.
Any help would be appreciated,
Cheers.

There's no way for 3rd party apps to take a picture without the users interaction in this v1 release of the 3rd Party SDK. AR capability is on the radar for the platform team though, so watch this space.
Picture taking capability is currently provided through CameraCaptureTask.

FYI: In Windows Phone OS 7.1 (a.k.a. "Mango"), you can now programmatically capture an image from the camera using the PhotoCamera class. Fire-off a camera capture using the CaptureImage method. When the capture is available, you can access the image (and a thumbnail) from the arguments in the eventhandlers for CaptureImageAvailable and CaptureThumbnailAvailable.
This process is fully described in the following topic:
How to: Create a Base Camera Application for Windows Phone
In that sample, a button is used to trigger the call to CaptureImage, but in a real-world application a timer, like you suggested, would be much more appropriate. (we recommend using the hardware button for user-triggered photos, rather than a UI button. That is described here: How to: Access the Hardware Camera Shutter Button).
Here's the method that actually programmatically triggers the image capture, where cam is the PhotoCamera object:
private void ShutterButton_Click(object sender, RoutedEventArgs e)
{
// Capture a still image. Events are fired as the thumbnail
// and full resolution images become available.
try
{
cam.CaptureImage();
}
catch (Exception ex)
{
this.Dispatcher.BeginInvoke(delegate()
{
// Cannot capture an image until the previous capture has completed.
txtDebug.Text = ex.Message;
});
}
}
Note: PhotoCamera will throw an exception if you try to capture when another capture is in progress. You probably wouldn't have this problem with a timer-based app, but that is why the try/catch is used here. Also, BeginInvoke is used to access the UI thread and display the message in a textBlock on the corresponding page.
Hope that helps. Cheers

Related

Unity UI not working properly ONLY on Windows

I have been working on figuring out what is going on with my game's UI for at least two days now, and no progress.
Note that this is a mobile game, but I was asked to build for Windows for visualization and presentation purpose.
So the problem is that when I run my game on the Unity Editor, Android, iOS and Mac platforms the UI works just perfect, but then when I run the game on Windows the UI still works fine UNTIL I load a specific scene.
This specific scene is a loading screen (between main menu and a level) when the level finished async loading, a method called MoveObjects is called in a script in the loading screen, to move some objects that where spawned in the loading screen scene into the level scene (this is not the issue though, since I already try without this method and the problem on the UI persist).
Once the logic of this MoveObjects method is done, a start button is enabled in the loading screen, for the player to click and start playing (I did try moving the start button to the level scene, since maybe it not been a child of the currently active scene could be the issue, but the problem still persist). Is at this point that the UI is partially broken, what I mean with this is, that I can see buttons (and some other UI elements like a scrollbar) changing color/state when the mouse moves over them, but I cannot click on them anymore (the button wont even change to the pressed state).
Also note that I tried creating a development build to see if there was any errors in the console, and I notice that this problem is also affecting the old UI system, so I was not able to interact with the development console anymore.
Also also, note that if I grab and drag the scrollbar before this issue appear, and I keep holding down on the scrollbar until this happens, the mouse gets stuck on the scrollbar, meaning that I cannot interact with the UI anymore, but the scrollbar will still move with the mouse.
I already check that this things are not the source of the problem:
Missing EventSystem, GraphicRaycaster or InputModule.
Another UI element blocking the rest of the UI.
Canvas is Screen Space - Overlay so there is no need for a camera reference.
I only have one EventSystem.
Time.timeScale is 1.
I am not sure what else I could try, so if anyone has any suggestions, I would appreciate it. Thanks.
P.S: I am sorry to say that I cannot share any code or visual material or examples due to the confidentiality.
A major source for a non-working UI for me has always been another (invisible) UI object blocking the raycast (a transparent Image, or a large Text object with raycast on).
Here's a snippet I put together based on info found elsewhere, I often use it to track objects that are masking the raycast in complex UI situations. Place the component on a text object, make sure it's at least few lines tall, as the results will be displayed one under another.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
[RequireComponent(typeof(Text))]
public class DebugShowUnderCursor : MonoBehaviour
{
Text text;
EventSystem eventSystem;
List<RaycastResult> list;
void Start()
{
eventSystem = EventSystem.current;
text = GetComponent<Text>();
text.raycastTarget=false;
}
public List<RaycastResult> RaycastMouse(){
PointerEventData pointerData = new PointerEventData (EventSystem.current) { pointerId = -1, };
pointerData.position = Input.mousePosition;
List<RaycastResult> results = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointerData, results);
return results;
}
void Update()
{
list= RaycastMouse();
string objects="";
foreach ( RaycastResult result in list)
objects+=result.gameObject.name+"\n";
text.text = objects;
}
}

Coded UI - How to Capture Image After a Mouse Click Event

What is the best option of capturing image after each mouse click in recorded session of Coded UI?
For example, in UIMap.Designer.Cs file I have entered image capturing lines:
Mouse.Click(uIOutagesandSafetyHyperlink, new Point(62, 2));
Image MSOPic1 = UITestControl.Desktop.CaptureImage();
MSOPic1.Save(#"C:\Automation\TestAutomation\web\Recordings\FullSite1\Screenshots\MSO\HomePage_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + ".png");
The above code takes a screenshot but it does not take the current browser's screenshot, just captures another screen where the current browser window does not exist. How can I capture screenshot of the active browser where the test is taking place?
One more question: Does Visual Studio provide an alternative way to capture images during playback? Like through configuration?
One more question: Does Visual Studio provide an alternative way to capture images during playback? Like through configuration?
By default coded ui test should take a screenshot with each action it does.
You can find these screenshots in the html outputs for your tests.
See: https://msdn.microsoft.com/en-us/library/jj159363.aspx
If in any case it is not enabled for your tests you have to set:
Playback.PlaybackSettings.LoggerOverrideState = HtmlLoggerState.AllActionSnapshot;
If you want to have this setting in all tests and for all actions call it in the [TestInitialize()] method of each test you want to apply it to.
Like so:
[TestInitialize()]
public void MyTestInitialize()
{
Playback.PlaybackSettings.LoggerOverrideState = HtmlLoggerState.AllActionSnapshot;
}
The UITestControl class has a CaptureImage method. To get an image of the current browser, find its UITestControl object (which may be derived from that) and call its CaptureImage method.
Please do not edit the uimap.designer.cs file as it is an auto-generated file and your edits may be lost. See this answer.

How to get the position of touch in a simple windows phone 8 app?

I am making an app for windows phone 8.
On one of the pages of the app, I want to get the co-ordinates of the touch.
I tried searching on net but I got results related to games.
I want to know is it possible to get the position of touch on canvas/or any other component in a simple app.
If yes, plz guide me through it.
Hook up to Tap event of the Control, and use GetPosition of event args.
<Canvas Tap="HandleTap/>
private void HandleTap(object sender, GestureEventArgs e)
{
Point point = e.GetPosition(null);
}

Showing message without any buttons in Windows Phone

I would like to create an info message box in Windows Phone.
It should look like a single text message, that's shown on screen for X seconds, and I doesn't have any confirmation buttons
as MessageBox.Show() does. It would be used to show user some messages about the app progress, like "file download started",
or "preferences saved".
I've tried to create something like that, using Popup element, but it seems a bit different of what I want to
make.
With the popup I can create something like that
canvas.MouseLeftButtonUp += new MouseButtonEventHandler(popupCloseEvent);
For example, which closes this popup when user taps it.
or something similar. (Maybe can implement a timer there to close it after a few secs)
Are there better ways to create such thing?
You could use the either the Message Dialog or Overlay controls in the Coding4Fun toolkit.
Found here: http://coding4fun.codeplex.com/
They are really simple and easy to use controls.
Try this
In Xaml:
<Popup Tap="Popup_Tap"></Popup>
In code behind:
private void Popup_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
(sender as Popup).IsOpen = false;
}
I hope it helps.

GeoCoordinateWatcher location not returning speed. NaN instead

I've been experimenting with getting readings from the GPS with my wp7.
I'm using very similar code to the sample found here:
Getting GPS coordinates on Windows phone 7
I've got 2 textblocks on the page. One showing the speed from Position.Location.Speed and one showing the timestamp from Position.Location.TimeStamp. This is triggered from the watcher_PositionChanged event.
I notice the event being triggered every second or so, as the timestamp updates to reflect this. I'm also reading the GPS status as "ready" (the first couple of readings are "No Data") However, the speed value continues to display NaN.
I loaded this code onto a physical device (LG Optimus 7), and drove down the street with the phone on the dashboard to test.
OK, I realized that GeoCoordinateWatcher runs on the UI thread and it was acting a bit.. strange. Moving this off into a separate thread fixed the problem.
Try to do it with that way:
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
// you cannot change the UI in this function -> you have to call the UI Thread
Deployment.Current.Dispatcher.BeginInvoke(() => ChangeUI(e));
}
void ChangeUI(GeoPositionChangedEventArgs<GeoCoordinate> e)
{
// do magic
}

Resources