Changing this to a set pixel width - iphone

This is probably super easy, but I can't get it to work right. I am trying to do a simple update to my iOS app by changing an image resize option to a set pixel size. the code below is what i'm working with and how it is currently functioning:
selectedWidth = (30 * selectedWidth)/100;
selectedHeight = (30 * selectedHeight)/100;
I assume this is 30% of 100%? I just need the selected width to be 200px, and height to be automatic. Can somebody please help me? I'm a newb with this type of coding, my developer is away and i thought this would be an easy change haha.

So if I understand you right, I think this might help
selectedHeight = (selectedHeight / selectedWidth) * 200;
selectedWidth = newWidth;
This should calculate the correct height to your 200px width.
If you want to change your fixed-width from time to time, you can define a constant variable in the m.file below the imports:
#define kWidth 200
and use it instead of the hard coded 200 in the code on top.
Example:
old width: 100px
old height: 50px
new width: 200px
new height: (50 / 100) * 200 = 100px

Related

How to make the application display correctly on various screens?

The application looks good on a Pixel 4 XL (resolution of 1440 x 3040) but is overflowing on a Samsung A5 (720 x 1280).
I expected the components to be scaled based on the resolution/ppi, but it seems that I misunderstood.
So how can I fix this ?
Any help is greatly appreciated.
Thanks.
One way of achieving a great looking UI on different screen sizes is to size your widgets relatively to the screen size, and not with pixel amounts, since when the screen's width or height is smaller or bigger, and the widgets are the same size, the UI will either go out of bounds or you will have empty spaces in your UI.
how to achieve that:
in your build function you can store the screen size in a variable:
Widget build(BuildContext context) {
final screenSize = MediaQuery.of(context).size;
...
then in your widgets that you are returning in the build function, for example a container, change the pixel values to values relative to the screen size:
instead of
return Container(width: 50, height: 70);
write stuff like:
return Container(width: screenSize.width * 0.1,
height: screenSize.height * 0.12);

Swift: Size of UIImage when slicing enabled

When I slice the image in the assets folder in Xcode, the size property of the UIImage returns a wrong value. Does anyone know how to get the real image size when the slicing is enabled? Does not matter if size will be in pixels or in points.
Or maybe there is a way to get the size of the image's rounded part so that I could add the cap insets in code?
This is how I slice the image in Xcode:
Or, maybe there is a way to find the size of the highlighted (darker) part of the image?
I would appreciate any ideas!
When "slicing" an image in assets, you don't need to set the cap insets -- it's done automatically.
If you really need to get the "slice" values, you can read them via the .capInsets property:
guard let img = UIImage(named: "sliced") else { return }
print("image size:", img.size)
print("caps insets:", img.capInsets)
My quick test - of a 200 x 60 "capsule" image with 20-pixel corner radius - using the default slicing outputs:
image size: (39.0, 60.0)
caps insets: UIEdgeInsets(top: 0.0, left: 19.0, bottom: 0.0, right: 19.0)
So, the width is the left-inset plus the right-inset plus 1 (one) ... Because the center portion will stretch to fit, the "default* width of that section is 1.

How to get the result from fraction without rounding up in Thymeleaf

I am trying to get the relation between the height and width from image and then multiply by a fixed width to resize a picture using Thymeleaf.
For it, I saved the height and width in a java object called g. Using a fixed width: 270px I want to scale the height using the relation between the sized saved doing that:
th:style="'height:' + ${(g.height / g.width) * 270} +';
The saved and original size is: int height = 286 and int width = 423.
So the fraction's result should be 286/423 = 0.67.
But the problem is that this fraction g.height / g.width is giving me 0 as result.
How can I obtain decimals from this fraction? I tried with {#numbers.formatDecimal()} but not results.
Since both width & height are integers, it's doing integer division. Either store them as float/double on the object itself, or convert them to doubles in the expression.
th:style="'height:' + ${((0.0 + g.height) / g.width) * 270} +'px;'"

iText7 Bug: Endless loop in ImageRenderer

i came across an endless-loop-issue due to floating point arithmetic in iText7 DotNet ImageRenderer.
I've added an image with 2464x3692 pixels to an PDF page area of 523x770 pixels, causing the Layout() function to loop endlessly because every iteration returned LayoutResult.NOTHING.
The main issue is that the image height is calculated inside the Layout-function using the following statement:
Line 90: height = (float)width / imageWidth * imageHeight;
Due to the floating point operation the height got a value of something like 770.0001.
This is greater than the area height, causing the loop to return LayoutResult.NOTHING, so the image gets autoscaled again.
Inside the AutoScale-function only the image width is checked, which IS inside the area boundaries and so nothing is scaled.
I've fixed this issue by changing the following code inside ImageRenderer.cs:
90 - height = (float)width / imageWidth * imageHeight;
90 + float? propHeight = RetrieveHeight();
91 + height = propHeight == null ? (float)width / imageWidth * imageHeight : propHeight.Value;
214 - SetProperty(Property.HEIGHT, UnitValue.CreatePointValue(area.GetBBox().GetHeight()));
215 + SetProperty(Property.HEIGHT, area.GetBBox().GetHeight());
ImageRenderer now uses the height that is set inside AutoScale without recalculating it if not necessary.
Hopefully this will be fixed in one of the next releases. :)
Regards
Yosh

OpenXML distance, size units

What are the measurement units used to specify sizes or X,Y cordinates in OpenXML? (Presentation).
Does it makes sense to match those with pixels, if so how can be those converted to pixels?
graphicFrame.Transform = new Transform(new Offset() { X = 1650609L, Y = 4343400L }, new Extents { Cx =
6096000L, Cy = 741680L });
In above code X is set to 1650609 units? What units are they?
They are called EMU (English Metric Units)
http://en.wikipedia.org/wiki/English_Metric_Unit#DrawingML
http://polymathprogrammer.com/2009/10/22/english-metric-units-and-open-xml/
1pt = 12,700 EMU
Also as explained here 1px =~ 9525EMU
http://openxmldeveloper.org/discussions/formats/f/15/p/396/933.aspx
EMU is right, although converting EMU to PX depends on the image density. The conversion factor for 96ppi images is 9525, while for a 72ppi image is 12700 and for a 300ppi image is 3048.
So, the conversion factor would be emu's per inch (914,400) / image ppi.
Example: a 200px width image with a density of 300ppi, would give us 609,600 EMU:
609,600 EMU / (914,400 emus-per-inch / 300 pixels-per-inch) = 200 px
I am using a web that is helping me a lot for these things. I have found it in another post about all measures in word and their equivalents. is that: https://unit-converter-bcmmybn3dq-ez.a.run.app/
I found in here Default WordML Unit Measurement ? pixel or point or inches
You just need EMUS to px and the page calculates the equivalent with a lot of decimal for precision.
I hope it really helps you.