JavaFX - Printing size - javafx

How can you control the size of the printed node?
Ex. I have a Rectangle width = 10 * DPI and height = 5 * DPI.
I want to print this node to be Exactly 10 x 5 inches.
can anyone tell me how to do it programatically?

you can read out the dpi of the current screen with the following code:
double dotsPerInch = Screen.getPrimary().getDpi();
be aware that this is the dpi value when the screen is set to its native resolution!

Related

how to transform a pixel to xamarin.forms units?

there are 160 units per inch.
2.If I created an Photoshop file that are 72 dpi then there will be 72 points per inch.
3.If the element is 88px height in Photoshop then what I have to set it in xamarin?
If the phone is 360dpi then the height in xamarin should be :88 / 72 * 160 / 2?
but it is not right.
I know the units in each platfform and I only want to know how to get units from pixels
You could use Xamarin.Essentials to get the Screen density as follows:
// Get Metrics
var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
// Screen density
var density = mainDisplayInfo.Density;
If the density is 3 in iOS device and pixels is 88 , then there are 88/3 units in iOS.
If the phone is 360dpi
That means it shoule be a Android device, and screen density also can be calculated by 360/160 = 2.25. Then there are 88/2.25 units to set for HeightRequest.
================================Update==============================
If there is a BoxView in Xaml as follows:
<BoxView x:Name="MyBoxView" BackgroundColor="CadetBlue" HorizontalOptions="Fill"/>
And the effect:
Now I will print the MyBoxView.Width. the result is:
Console.WriteLine("++++MyBoxView++++" + MyBoxView.Width);
++++MyBoxView++++411.428571428571
If you use var density = mainDisplayInfo.Density; to get density, you will get Screen Density::2.625. (My device is Piexl_2_pie_9_0 api 28 emulator)
You know the size of screen width is 1080 pixels, however the width is 411.428571428571. That should means units of WidthRequest.
And if you put 411.428571428571 * 2.625 , you will get 1080 pixels.

Can QFontMetrics account for windows dpi scaling?

I was under the impression that if you do this in your application
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication* app = new QApplication(temp, NULL);
then Fonts gets automatically scaled up on high resolution display. Same if you explicitly increase font scaling in Windows 10 (Settings-->System->Custom Scaling).
However, when running the following code with 100% and then 200% scaling in Windows 10, it does not return doubled size.
QFont font = QFont("arial", 10);
QFontMetrics fm(font);
int width = fm.width("abcdefgABCDEFG");
Strangely there is only 1 pixel difference.
100% --> width = 108 pixels
200% --> width = 109 pixels
Why is that? Can I get QFontMetrics to account for Windows scaling? Or do I need to use Logical / Physical DPI to deduce that font size must be increased by a factor 2?
Thanks
For the proper scaling of custom-drawn items use QScreen::physicalDotPerInch property to realize the scaling coefficient to apply to actual drawings:
qreal myScale = pScreen->physicalDotPerInch() / constStandardPerInch;
P.S. The question still needs to be revised.

Retrieve resolution of an uploaded image using ImageResizer

Does ImageResizer.Net for asp.net have any method by which we can know the resolution of any uploaded Image. I know one method:
ImageResizer.ImageBuilder.LoadImageInfo (object source, IEnumerable< string > requestedInfo )
that gives me Height, Width, Mimetype & extension of image file, but I have a requirement where I need to validate the resolution of an uploaded image.
As far as I know dpi is something what connected to devices where images will be rendered.
So, if it is Desktop dpi can be or 72 (MAC) or 96 (Windows), but if you will print it dpi can be 150 or 300.
So to check if image will be correctly printed (with good quality) on paper with size 200x200 milimeters you can calculate min size if image you need in pixels.
So, we have the following input:
- dpi of printing is 150
- size of paper is 200x200 milimeters
200 mm is 7.9 inch
=> min resolution of image should be 7.9*150 = 1185 pixels
So only images with height and width equal or more than 1185 will be printed with good quality.
So question for you - what for you need resolution(dpi) check?
As far as you have Height and Width you can calculate DPI using this formula:
dp = sqrt(width^2 + height^2) (Pythagorean theorem)
then, you should know size of the screen in inches (di). Simply:
dpi = dp / di

how to draw 2 centimeters long line on screen in adobe air

I need to draw 2 centimeters long line on screen on an Adobe Air application. I don't know how to do it!
Explanation:
I am getting parameters from another application say x centimeters, and that parameter is in centimeters.
I need to draw a circle exactly x centimeters from the top of the screen.
best regards
If I remember correctly, you won't be able to do it on desktop since AIR always returns 72DPI for the screen (I may be incorrect on that point, however). It is fairly easy to do on mobile, though, assuming AIR returns the proper DPI (retina iPads did not return the correct DPIs prior to AIR 3.3, I believe).
Basically, you convert inches to pixels simply by multiplying by the DPI.
var dpi:Number = Capabilities.screenDPI; //unnecessary to save local version, just easier to reference
var heightCM:Number = 5;
var widthCM:Number = 5;
var widthPixels:Number, heightPixels:Number;
var heightIn:Number = cmToInches( heightCM );
var widthIn:Number = cmToInches( widthCM );
widthPixels = widthIn * dpi;
heightPixels = heightIn * dpi;
function cmToInches( value:Number ):Number {
return value * .393701;
}
That will take a size (I built it for height and width, but you can adapt it to your needs) in centimeters, convert it to inches, and then convert it to pixels. You'd obviously want to turn that into a neat static Util method, but it would do the trick.
If you want, I created a Flex application last year to try and understand how AIR handles DPI differences. It just draws a red rectangle to a specific size on screen using on-screen sliders to determine the size (in inches). I don't have it here at work, but I could post the code when I get home.
Again, I do not believe this will work in desktop applications due to AIR always reporting 72 DPI. I hope I am wrong, but I do not believe I am.

Scaling issue with mobile flex app

I have a couple of AS3 games that I want to run in a flex mobile app. I put my original games into a single library and then added it to my mobile app. So far so good.
The problem I get is when the game starts it doesn't scale itself to the StageScaleMode.SHOW_ALL I have specified in the games.
I'm starting the games like this:
var game:MyGame = new MyGame();
var container:UIComponent = new UIComponent();
addElement(container);
container.addChild(game);
this.actionBarVisible = false;
I tried setting the same scale option to the stage in my mxml but it doesn't change anything.
Any ideas?
Thanks.
Mobile device screens have varying screen densities, or DPI (dots per inch). You can specify the DPI value as 160, 240, or 320, depending on the screen density of the target device. When you enable automatic scaling, Flex optimizes the way it displays the application for the screen density of each device.
For example, suppose that you specify the target DPI value as 160 and enable automatic scaling. When you run the application on a device with a DPI value of 320, Flex automatically scales the application by a factor of 2. That is, Flex magnifies everything by 200%.
To specify the target DPI value, set it as the applicationDPI property of the tag or tag in the main application file:
<s:ViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
firstView="views.HomeView"
applicationDPI="160">
If you choose to not auto-scale your application, you must handle the density changes for your layout manually, as required.
Devices can have different screen sizes or resolutions and different DPI values, or densities.
Resolution is the number of pixels high by the number of pixels wide: that is, the total number of pixels that a device supports.
DPI is the number of dots per square inch: that is, the density of pixels on a device’s screen. The term DPI is used interchangeably with PPI (pixels per inch).
applicationDPI (if setted) specifies the target DPI of the application. Flex automatically applies a scale factor to fit good on another devices with different DPI value.
Capabilities.screenDPI is the specific DPI value of the current device.
runtimeDPI is similar to Capabilities.screenDPI. This value is the current device DPI rounded to one of the constants defined by the DPIClassification class (160, 240 and 320 DPI).
If you want to know the real dimensions (width and height) of a component on the current screens you need to work with the scale factor as:
var scaleFactor:Number = runtimeDPI / applicationDPI;
var currentComponentSize:int =componentSize.height * scaleFactor;
If you haven’t access to applicationDPI and runtimeDPI values, you can calculate the scaleFactor manually using Capabilities.screenDPI as:
// Copy the applicationDPI setted in your application. ie:
var _applicationDPI:int = 160;
var _runtimeDPI:int;
if(Capabilities.screenDPI < 200)
_runtimeDPI = 160;
else if(Capabilities.screenDPI >=200 && Capabilities.screenDPI < 280)
_runtimeDPI = 240
else if (Capabilities.screenDPI >=280)
_runtimeDPI = 320;
var scaleFactor:Number = _runtimeDPI / _applicationDPI;
var currentComponentSize:int =componentSize.height * scaleFactor;
http://www.francescoflorio.info/?p=234

Resources