How to get wp7 ppi or physical screen size? - windows-phone-7

I'm creating (yet another) ruler app for wp7.
I know the res. is always 480x800, but devices have different screen sizes.
I tried searching around, but i couldn't find out how to get the ppi, so i can map the pixels to the physical dimension.
so how do i get the ppi of the current device, or the physical screen size ?

There is no way to retrieve the PPI on the device, you best shot would be to maintain a list of devices and their respective PPI. You can use this helper method to access device properties:
Using Microsoft.Phone.Info;
...
private static string GetDeviceProperty(string propertyName)
{
object propertyValue;
if (!DeviceExtendedProperties.TryGetValue(propertyName, out propertyValue))
return String.Empty;
return propertyValue as string ?? String.Empty;
}
Now the relevant properties would be:
string manufacturer = GetDeviceProperty("DeviceManufacturer");
string devicename = GetDeviceProperty("DeviceName");
Hope this helps! More information about DeviceExtendedProperties can be found on MSDN

Related

Koltin low quality images registerForActivityResult

Hi I'm trying to capture a picture using kotlin and registerForActivityResult but I allways get a blur image with no quality I've read several post but I can't understand how to work with my application. I'm using a fragment to call the camera. Any suggestions? Sorry for my bad english I've spent about the full week trying it works. And nothing. Thanks in advance
private var imagenUri: Uri? =null
val startForResult = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
try {
val intent = result.data
intent!!.putExtra(MediaStore.EXTRA_OUTPUT, imagenUri)
val bitMap = intent?.extras?.get("data") as Bitmap
imagenUri= getImageUriFromBitmap(requireContext(),bitMap)
binding.ivImagen.setImageURI(imagenUri)
Toast.makeText(context, "la uri es: $imagenUri", Toast.LENGTH_SHORT).show()
} catch (e: java.lang.Exception){
Toast.makeText(context, "NO SE HA PODIDO ENCONTRAR IMAGEN", Toast.LENGTH_SHORT).show()}
}
}
binding.ibTomarFoto.setOnClickListener(){
startForResult.launch(Intent(MediaStore.ACTION_IMAGE_CAPTURE))
}
From the documentation:
public static final String ACTION_IMAGE_CAPTURE
Standard Intent action that can be sent to have the camera application capture an image and return it.
The caller may pass an extra EXTRA_OUTPUT to control where this image will be written. If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap object in the extra field. This is useful for applications that only need a small image. If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri value of EXTRA_OUTPUT.
So you need to add the EXTRA_OUTPUT extra to get a full-size image stored at a URI you supply. Otherwise you get a small image as a data payload in the result Intent (those bundles can't handle large objects).
It looks like you're already trying to do that, you've just added it to the wrong place - you need to add it to the Intent you call launch with, not the result one. It's a configuration option for the task you're launching!
So this should work:
binding.ibTomarFoto.setOnClickListener(){
startForResult.launch(
Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, imagenUri)
)
}
And then remove the same putExtra line from your result-handler code (it doesn't do anything, but there's no point having it there)

FindAllAsync can't find device in windows store app

The vendor Id and product Id is being passed to FindAllAsync and there is no device returned from FindAllAsync. We've verified that these are the right device IDs and works on other platforms. It's not a plug and play device.
Here is the code below:
UInt32 VendorId = 0x1D1B;
UInt32 ProductId = 0x1202;
string aqs = UsbDevice.GetDeviceSelector(VendorId, ProductId);
var myDevices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(aqs);
if (myDevices.Count == 0)
{
return;
}
There are no devices found. Any ideas?
Clarification
I should clarify. It's not behaving like it's PNP and not appearing in the device manager in win8 and win7. The device works with a native application for driving the device even though it does not appear in the device manager.
if (myDevices.Count == 0) then you AQS filter doesn't match any device interface in the system.
This means that there are not USB interfaces with VendorId = 0x1D1B & ProductId = 0x1202.
You should probably walk thorough the system device interfaces, and see what they actually are. I can show you how to do that if you need.

Geolocator and accuracy in Windows Phone 8

I have a few questions about Geolocator and property DesiredAccuracy.
I have the method GetMyPosition:
public async Task<Geoposition> GetMyPosition()
{
Geoposition myGeoposition = null;
Geolocator myGeolocator = new Geolocator();
myGeolocator.DesiredAccuracy = PositionAccuracy.High;
try
{
myGeoposition = await myGeolocator.GetGeopositionAsync();
return myGeoposition;
}
catch (Exception ex)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("Can't get the position");
});
return null;
}
}
1) Why
Geolocator.DesiredAccuracy = PositionAccuracy.High;
Geolocator.GetGeopositionAsync();
always return Geoposition.Coordinate.PositionSource = Cellular with accuracy 400 - 1600 m (on device Nokia Lumia 520)?
2) Under what settings I can get a high accuracy (50 - 100 m) and PositionSource = Satellite?
3) If I have the loaded maps on my device and I activated the airplane mode on the device, then code
Geolocator myGeolocator = new Geolocator();
myGeolocator.DesiredAccuracy = PositionAccuracy.High;
try
{
myGeoposition = await myGeolocator.GetGeopositionAsync();
return myGeoposition;
}
will work? Without a celluar, only a satellite?
4) How strong is the precision of coordinates depends on the device?
Thanks in advance!
Taken from MSDN
Although the Location Service uses multiple sources of location information, and any of the sources may not be available at any given time (for example, no GPS satellites or cell phone towers may be accessible), the native code layer handles the work of evaluating the available data and choosing the best set of sources. All your application needs to do is to choose between high accuracy or the default, power-optimized setting. You can set this value when you initialize the main Location Service class, GeoCoordinateWatcher.
C#
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default);
So it seems like you can't control which source is used but rather the available source will be used based on the specified position accuracy on GeoCoordinateWatcher. Try initializing a GeoCoordinateWatcher with high accuracy and see what happens
var geoWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
You can use
Geolocator myGeolocator = new Geolocator();
myGeolocator.DesiredAccuracyInMeters = 20;
...
to explicitly state how accurate you want the location to be which would allow the device to manage its power a little better but whether you get close to that accuracy with your result depends on the quality of the location the device can get. If you're inside a building for example you're not going to get something that accurate without connecting to WIFI

Windows Phone 7 GetDistanceTo() returns incorrect distance

I am developing a small Windows Phone application. I am storing the current location of user in the database.
Here is the code to retrieve the current location which is stored in database.
public void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
CurrentLatitude = e.Position.Location.Latitude.ToString();
CurrentLongitude = e.Position.Location.Longitude.ToString();
}
We need to allow user to do some activity if he is under the 400 meters from his saved location.
I am using the following code to calculate the distance.
internal double GetDistanceTo(GeoCoordinate ClientLocation)
{
double distanceInMeter;
GeoCoordinate currentLocation = new GeoCoordinate(Convert.ToDouble(watcher.Position.Location.Latitude.ToString()), Convert.ToDouble(watcher.Position.Location.Longitude.ToString()));
distanceInMeter = currentLocation.GetDistanceTo(ClientLocation);
return distanceInMeter;
}
ClientLocation : is the location saved in the database.
So my problem is that it gives extremly large distance even the user is standing at the same location(under 1 meter) which is saved in the database.
Example cordinates (extracted from device)
Saved in Database
Lat : 29.8752546310425
Long: 73.8865985870361
Current Cordinates
Lat : 29.8734102249146
Long :73.9049253463745
Distance
1780.45
Could anybody suggest me what is wrong here or a better way to get the distance between two coordinates?
According to boulter.com it is 1.11miles from A to B. Thats about 1780m, so I dont see what the problem is. Have a read of the Moveable Type help on lat and long calculations.

raw data from CVImageBuffer without rendering?

I'm getting a CVImageBufferRef from my AVCaptureSession, and I'd like to take that image buffer and upload it over the network. To save space and time, I would like to do this without rendering the image into a CIImage and NSBitmapImage, which is the solution I've seen everywhere (like here: How can I obtain raw data from a CVImageBuffer object).
This is because my impression is that the CVImageBuffer might be compressed, which is awesome for me, and if I render it, I have to uncompress it into a full bitmap and then upload the whole bitmap. I would like to take the compressed data (realizing that a single compressed frame might be unrenderable later by itself) just as it sits within the CVImageBuffer. I think this means I want the CVImageBuffer's base data pointer and its length, but it doesn't appear there's a way to get that within the API. Anybody have any ideas?
CVImageBuffer itself is an abstract type. Your image should be an instance of either CVPixelBuffer, CVOpenGLBuffer, or CVOpenGLTexture. The documentation for those types lists the functions you can use for accessing the data.
To tell which type you have use the GetTypeID methods:
CVImageBufferRef image = …;
CFTypeID imageType = CFGetTypeID(image);
if (imageType == CVPixelBufferGetTypeID()) {
// Pixel Data
}
else if (imageType == CVOpenGLBufferGetTypeID()) {
// OpenGL pbuffer
}
else if (imageType == CVOpenGLTextureGetTypeID()) {
// OpenGL Texture
}

Resources