How to know 720p or 1080p on windows phone 8? - windows-phone-8

Usually, I used Application.Current.Host.Content.ScaleFactor to checking my device's resolution, but now the value is the same for 720p and 1080p.
So then what differentiates them ? Thank you !

Here is a code snippet that gives the correct scale factor, even for 1080p devices:
public int ScaleFactor
{
get
{
object physicalScreenResolutionObject;
if (DeviceExtendedProperties.TryGetValue("PhysicalScreenResolution", out physicalScreenResolutionObject))
{
var physicalScreenResolution = (Size)physicalScreenResolutionObject;
return (int)(physicalScreenResolution.Width / 4.8);
}
return Application.Current.Host.Content.ScaleFactor;
}
}
Here are the corresponding resolutions for each scale factor values:
100 => WVGA (480*800)
150 => 720p (720*1280)
160 => WXGA (768*1280)
225 => 1080p (1080*1980)
Source: Handle 1080p in Windows Phone like a Pro!

follow the guidance as detailed in this post
http://blogs.windows.com/windows_phone/b/wpdev/archive/2013/11/22/taking-advantage-of-large-screen-windows-phones.aspx

Here is something from the Nokia Developer blog.
public static Size DisplayResolution
{
get
{
if (Environment.OSVersion.Version.Major<8)
return new Size(480,800);
int scaleFactor=(int) GetProperty(System.Windows.Application.Current.Host.Content, "ScaleFactor");
switch (scaleFactor)
{
case 100:
return new Size(480, 800);
case 150:
return new Size(720, 1280);
case 160:
return new Size(768, 1280);
}
return new Size(480, 800);
}
}
private static object GetProperty(object instance, string name)
{
var getMethod= instance.GetType().GetProperty(name).GetGetMethod();
return getMethod.Invoke(instance, null);
}
Hope this helps!

XamlEssentials is a neat set of helpers for building XAML-based applications. Recently, it added some helper utilities to make it easy to deal with large-resolution screens.
The static property DisplayHelper.CurrentResolution returns an enum letting you know if the resolution is DisplayResolutions.WVGA, DisplayResolutions.WXGA, DisplayResolutions.HD720p, or DisplayResolutions.HD1080p.
The static property DisplayHelper.IsPhablet helps to determine if the screen size is greater than 5", which lets you render differently even if you're on a 6" 720p screen, like the Lumia 1320.
The static method ResourceHelper.AddPhabletStyle() lets you add a specific ResourceDictionary only if the screen is greater than 5 inches, so you can easily change the layout of a page depending on the size of the screen.
XamlEssentials also has other helpers that make dealing with the new additions to GDR3 easier. You can read more about those helpers here.
You can easily add XamlEssentials to your project from NuGet, or you can download the source from GitHub.
HTH!

Related

Limit rendered image size in icepdf

While rendering a bunch of PDFs to images, icepdf seemingly randomly bombs out with an OutOfMemoryError. Trying to track this down I find two things:
Close to the OOM it rendered an A0 page or similarly large document pages
With eclipse memory analyzer I find 1/2GB images in memory.
This suggests to limit the output image size to something managable. I wonder what the easiest way is to do this?
I looked at icepdf's Page object but there it is strongly recommended to just always use Page.BOUNDARY_CROPBOX and other uses seem not to be documented in the Javadoc.
How can I limit the output image size of Document.getPageImage or what other measure could I use to prevent the OOM (other than just increasing the Xmx, which I can't). Reduction of image quality is an option. But it should apply only to "oversize" images, not to all.
I tried already to use a predefined image using Document.paintPage(), but this was not sufficient.
Debug finally allowed me to zoom in on a document that is problematic. I get a log like:
2016-12-09T14:23:35Z DEBUG class org.icepdf.core.pobjects.Document 1 MEMFREE: 712484296 of 838860800
2016-12-09T14:23:35Z DEBUG class org.icepdf.core.pobjects.Document 1 LOADING: ..../F1-2.pdf
2016-12-09T14:23:37Z WARN class org.icepdf.core.pobjects.graphics.ScaledImageReference 1 Error loading image: 9 0 R Image stream= {Type=XObject, Length=8 0 R, Filter=FlateDecode, ColorSpace=DeviceGray, Decode=[1, 0], Height=18676, Width=13248, Subtype=Image, BitsPerComponent=1, Name=Im1} 9 0 R
so this would be Height=18676, Width=13248 which is really huge.
I guess that the OOM happens already during loading of the image, so later scaling does not help. Also it seems that the property org.icepdf.core.imageReference=scaled does not hit early enough.
For me it would be fine to just ignore oversized images like this. Any chance?
Image loading is by far the most memory expensive memory task when decoding PDF content. At this time there isn't an esasy way to turn off image loading for really large image however I'll give you a few code hints if you want to implement this your self.
The ImageReferenceFactory.java class is the factory behind the system property org.icepdf.core.imageReference, you'll see that the default for getImageReferenced() is ImageStreamReference. You can create a new ImageReference type like this:
public static org.icepdf.core.pobjects.graphics.ImageReference
getImageReference(ImageStream imageStream, Resources resources, GraphicsState graphicsState,
Integer imageIndex, Page page) {
switch (scaleType) {
case SCALED:
return new ScaledImageReference(imageStream, graphicsState, resources, imageIndex, page);
case SMOOTH_SCALED:
return new SmoothScaledImageReference(imageStream, graphicsState, resources, imageIndex, page);
case MIP_MAP:
return new MipMappedImageReference(imageStream, graphicsState, resources, imageIndex, page);
case SKIP_LARGE:
return new SkipLargeImageReference(imageStream, graphicsState, resources, imageIndex, page);
default:
return new ImageStreamReference(imageStream, graphicsState, resources, imageIndex, page);
}
}
Next you can extend the class ImageStreamReference with your new SkipLargeImageReference class. Then override the call() method as follows and it will skip the loading of any image over the defined MAX_SIZE .
public BufferedImage call() {
BufferedImage image = null;
if (imageStream.getWidth() < MAX_SIZE && imageStream.getHeight() < MAX_SIZE){
long start = System.nanoTime();
try {
image = imageStream.getImage(graphicsState, resources);
} catch (Throwable e) {
logger.log(Level.WARNING, "Error loading image: " + imageStream.getPObjectReference() +
" " + imageStream.toString(), e);
}
long end = System.nanoTime();
notifyImagePageEvents((end - start));
return image;
}
return null;
}
On a side note: To minimize the the amount of memory needed to decode an image make sure you are using org.icepdf.core.imageReference=default as this will decode the image only once. org.icepdf.core.imageReference=scaled will actually decode the image at full size and then do the scale which can create a very large memory spike. We are experimenting with NIO's direct ByteBuffers which looks promising to moving the decode memory usage off the heap, so hopefully this will get better in the future.

Yii2 - Image upload and resizing,ajax upload support extension

Is there any good image uploading and resize extension for yii2; I don't want to use kartik because since I had a problem I've not gotten any help to understand where the problem is, same situation with Illustrated behavior so I am stack in my project.
What I want is multiple image uploading,ajax support(even for old browser if not to turn to normal file input), image resizing keeping good quality,allowing one image to be saved in different sizes and Preview the file when selected from client side(not obliged).
Usually I use image magick direcly.
Check if these two functions can be useful for you:
public static function generateImagesScaledAndCropped($inputFile, $outputFile, $params)
{
$imageMagickConvert = \Yii::$app->params['imagick.convert'];
$cmd = sprintf("%s %s -resize %dx%d^ -gravity Center -crop %dx%d+0+0 %s", $imageMagickConvert, $inputFile, $params['edge'], $params['edge'], $params['edge'], $params['edge'], $outputFile);
exec($cmd);
}
public static function generateImagesScaledByWidth($inputFile, $outputFile, $params)
{
$imageMagickConvert = \Yii::$app->params['imagick.convert'];
$cmd = sprintf("%s %s -resize %d %s", $imageMagickConvert, $inputFile, $params['width'], $outputFile);
exec($cmd);
}
Params are:
<?php
return [
'imagick.convert' => '/usr/bin/convert',
'imagick.composite' => '/usr/bin/composite',
];
I use Imagine as abstract layer on Imagine library which
uses populars php libraries to work with images
http://www.yiiframework.com/doc-2.0/ext-imagine-index.html

How do I set an orientation specific background in a Windows Store Application?

I have a Windows Store Application where I've been supplied a different background image asset depending on whether the app is running in Portrait or Landscape mode.
Other than this background image, there are no other orientation specific differences.
What is the tidiest way to implement this requirement?
You can set it in Window.Current.SizeChanged handler:
Window.Current.SizeChanged += (sender, args) =>
{
if (ApplicationView.Value == ApplicationViewState.FullScreenLandscape)
{
// ...
}
else if (ApplicationView.Value == ApplicationViewState.FullScreenPortrait)
{
// ...
}
};

Can I use two xibs with one viewcontroller - re: porting to iPhone 5

I just submitted my first app to the app store (yay it was just approved!). I now want to update it to work with (look nicer on) the larger iPhone 5 screen. I don't intend to change anything other than to change the layout a bit for the larger screen.
NOTE: I don't want to have my current xib stretched.
Is it possible to create two xib files (ie: copy my current xib file for the main screen) and hook them both into the view controller and have it so that when the app launches, the app detects if there is an iPhone 5 screen or an earlier screen. Then, depending on which device it is, show the user a different screen.
I intend for underlying app to remain the same. All I want is to present a slightly different (taller) screen for iPhone 5 users with a few buttons/items moved around for the new layout. I otherwise won't be adding or removing anything from the interface.
This SO question/answer shows how to switch between an iPhone or iPad view. So to does this one. Both are helpful but I don't know how to modify this for the circumstance where the user is using an iPhone 5 with a larger screen or an iPhone 4S and below. Also, they assume two view controllers. I only want ONE view controller since absolutely NOTHING in the view controller logic changes - only the placement of the objects on the screen change and that is all done in the XIB.
I should think the answer should be that the view controller iteslf assesses what device it is running on then presents the appropriate xib? Yes? No?
If so, how would I go about this?
[Revised with Complete Answer on : Oct 7, 2012]
After significant research I found the answer, partly on this SO page (which shows how to detect which iPhone version your app is running on) and partly this SO page (showing how to have two xib's share the same 'File's Owner'. The final piece of the puzzle (loading separate xib's via the loadNibNamed: method) I found in chapter 10 of The Big Nerd Ranch's excellent iOS Programming text. Here's how:
Create a second xib (File, New..., File, select 'User Interface', select 'Empty' and save it. This creates the new xib. In the example below, my classic xib (for 3.5" iPhones) was named TipMainViewController.xib. I saved the new iPhone 5 xib with the name 'TipMainViewController-5.xib'
Make that new xib's 'File's Owner' the same ViewController as your existing xib. To do this, in the new xib file, select 'File's Owners'. Then in the 'Identity Inspector' select the existing View Controller as the Custom Class. In my case I selected 'TipMainViewController'.
Drag a new UIView onto the new xib's empty canvas. In the new UIView's attribute inspector set the 'Size' attribute to 'Retina 4 Full Screen'
Select all the contents in the existing 'Classic' 3.5" xib - eg: all your controls, buttons, selectors, labels etc. Copy them and paste them into the new iPhone 5 xib. Resize/move etc. them to optimize for the iPhone's 4" display.
Make all the connections to/from File's Owner as you did when you created your original xib.
Finally, in the 'viewDidLoad' method of your 'single' ViewController, insert the following logic (using your nib/xib names of course):
- (void)loadView
{
[super viewDidLoad];
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
// iPhone Classic
[[NSBundle mainBundle] loadNibNamed:#"TipMainViewController" owner:self options:nil];
}
if(result.height == 568)
{
// iPhone 5
[[NSBundle mainBundle] loadNibNamed:#"TipMainViewController-5" owner:self options:nil];
}
}
}
Here is a simple, working code sample for your view controller that shows how to load myXib-5.xib on the iPhone 5 and myXib.xib on iPhones/iPods predating the iPhone 5:
- (void)loadView
{
if([[UIScreen mainScreen] bounds].size.height == 568)
{
// iPhone 5
self.view = [[NSBundle mainBundle] loadNibNamed:#"myXib-5" owner:self options:nil][0];
}
else
{
self.view = [[NSBundle mainBundle] loadNibNamed:#"myXib" owner:self options:nil][0];
}
}
It assumes that you are only targeting the iPhone and not the iPad, to keep it simple.
The XIB's file owner's class property should also be set to the view controller that contains loadView.
Code in answer was helpful, but I needed something that worked better for universal apps (iphone/ipad).
In case someone else needs the same thing, here's something to get you started.
Say you built a universal app using the nib/xib naming standards for ios for view controllers that have xibs with the same name:
The two built-in defaults for autoloading xibs when providing no name is passed to initWithNibName:
ExampleViewController.xib [iphone default when nib named empty for Retina 3.5 Full Screen for classic layouts iphone 4/4s etc...]
ExampleViewController~ipad.xib [ipad/ipad mini default when nib named empty]
Now say you need custom xibs for the iphone 5/5s in IB using Retina 4 Full Screen option, i.e., you don't want the 3.5 xibs displaying for any 568h devices.
Here's the custom naming convention using a category approach:
ExampleViewController-568h.xib [iphone non default/custom naming convention when nib name empty for Retina 4 Full Screen (568h)]
Instead of overriding the built-in naming defaults, use a category to help set the right xib for the controller.
https://gist.github.com/scottvrosenthal/4945884
ExampleViewController.m
#import "UIViewController+AppCategories.h"
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
nibNameOrNil = [UIViewController nibNamedForDevice:#"ExampleViewController"];
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Do any additional customization
}
return self;
}
UIViewController+AppCategories.h
#import <UIKit/UIKit.h>
#interface UIViewController (AppCategories)
+ (NSString*)nibNamedForDevice:(NSString*)name;
#end
UIViewController+AppCategories.m
// ExampleViewController.xib [iphone default when nib named empty for Retina 3.5 Full Screen]
// ExampleViewController-568h.xib [iphone custom naming convention when nib named empty for Retina 4 Full Screen (568h)]
// ExampleViewController~ipad.xib [ipad/ipad mini default when nib named empty]
#import "UIViewController+AppCategories.h"
#implementation UIViewController (AppCategories)
+ (NSString*)nibNamedForDevice:(NSString*)name
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
if ([UIScreen mainScreen].bounds.size.height == 568)
{
//Check if there's a path extension or not
if (name.pathExtension.length) {
name = [name stringByReplacingOccurrencesOfString: [NSString stringWithFormat:#".%#", name.pathExtension] withString: [NSString stringWithFormat:#"-568h.%#", name.pathExtension ]
];
} else {
name = [name stringByAppendingString:#"-568h"];
}
// if 568h nib is found
NSString *nibExists = [[NSBundle mainBundle] pathForResource:name ofType:#"nib"];
if (nibExists) {
return name;
}
}
}
// just default to ios universal app naming convention for xibs
return Nil;
}
#end

saving google map to image from a browser component window inside a c# application

I wanted to save the google map into an image from a webpage.
while i was searching for that i got this program.
http://www.codres.de/downloads/gms.exe[^]
besides other alternatives like print screen i wanted to use a program or map api which can save a specified dimension of google map instead of the screen.
i have used browser component in c# for http access and for displaying certain webpages.
I want to know whether there are options to capture the browser screen to image using any c# functionality or even the browser component would have given such options. just a guess.
i would like to have answers, suggestions on how to capture the map with custom dimension and zoom size to an image.
I used this to get captcha Image from the current page, so you can use similar code just amend the imageID to point to the google map image and use this solution for zooming.
public string newsavefunction(WebBrowser webBrowser1)
{
IHTMLDocument2 doc = (IHTMLDocument2)webBrowser1.Document.DomDocument;
IHTMLControlRange imgRange = (IHTMLControlRange)((HTMLBody)doc.body).createControlRange();
string imagename = string.Empty;
try
{
foreach (IHTMLImgElement img in doc.images)
{
imgRange.add((IHTMLControlElement)img);
imgRange.execCommand("Copy", false, null);
using (Bitmap bmp = (Bitmap)Clipboard.GetDataObject().GetData(DataFormats.Bitmap))
{
bmp.Save(#"F:\captchaimages\captchapic.jpg");
}
imagename = img.nameProp;
break;
}
}
catch (System.Exception exp)
{ }
return imagename;
}