How is the margin of a UIElement calculated - xaml

For the xml below
<Image Width="30px" Height="30px" Margin="1 1 1 1" />
The margin is 1 1 1 1 but the image is at the centre of the screen (668 369 668 369). Why is this happening? Isn't the margin above invalid? Also, for the position of anything, you just need margin left and margin top. That's how winforms works, right? I don't understand why the Thickness constructer requires 4 values.

A Thickness for a Margin is how many pixels from each edge of the element. These are Left, Top, Right, and Bottom.
Here's an example:
Margin="10,15,5,0"
The code above defines a margin of:
10 Pixels from the Left.
15 Pixels from the Top.
5 Pixels from the Right.
0 Pixels from the Bottom.
The margin is always defined as Left, Top, Right, Bottom. However there are some shortcuts.
For example:
Margin="10,15"
The margin here will be defines as:
10 Pixels on the Left and Right.
15 Pixels on the Top and Bottom.
And also:
Margin="15"
This margin will be 15 pixels on all sides.
To answer your question more directly, you are simply missing the commas.

Related

combine two pictures(different size) horizontally?

I have 2 pictures, need to combine them horizontally. I know numpy and cv2(opencv) should help me to do this. But don't know how.
I used img1 = cv2.imread(file1), img2 = cv2.imread(file2)
the 2 images' shape are (2048, 1334, 3) and (720, 1200, 3)
How could I do this? when I open These 2 images, they have similar height, different width.
I only know if the 2 pics have the same size, then just use concate, but my 2 pics are different sizes.
For the final output, I want to have them keep their own width, height choose the biggest/smallest...
So I imagine the final output should maybe 2/3 width one picture, 1/3 width the other pic which is totally good. I don't need these 2 are evenly distributed. Just keep their own width. Thanks!
You need to either trim a bit of the bottom of the taller image or add some black pixels.
In order to trim a part of the image, you can do:
trimmed = image2[:image1.shape[0],:,:]
This keeps only the lines from 0 up to the height of image1.
Or, you can add some black pixels:
black = np.zeros(image1.shape[0] - image2.shape[0], image1.shape[1])
image2 = np.hstack(image2, black)
And then you vertically concatenate.
I just solved my question.
Basically use cv2.resize()function to resize the images
Then simply concatenate them horizontally or vertically.
Just change the axis.
img1 = cv2.imread('xxx.png')
img2 = cv2.imread('yyy.jpg')
then compare img1.shape() and img2.shape()
Use resize()function to make them width the same or height the same.
vis = np.concatenate((img1, img2), axis=1)
cv2.imwrite('out.png', vis)

How does positioning work on overlay image in cloudinary?

given the url(image) below as an example
https://res.cloudinary.com/demo/image/upload/w_220,h_140,c_fill/l_brown_sheep,w_220,h_140,c_fill,x_220,y_140/l_horses,w_220,h_140,c_fill,x_220,y_140/yellow_tulip.jpg
From what I understand, the first image yellow_tulip is drawn on (0, 0) which is the top left corner. The second image brown_sheep draws from (220, 140), which is the right bottom corner of yellow_tulip because (0, 0) starts from top left of canvas.
Everything makes sense from what I understand til the third image kicks in. horses also starts from (220, 140) but how come it starts from the center of second image brown_sheep? I'm really confused.
The dimensions of the image changes when you apply the overlay changes so that should be taken into consideration when applying the x and y coordinates.
The coordinates are calculated from the center of the image but since the size of the canvas in the first image is 220 by 140, setting the brown sheep overlay's coordinates to 220 by 140 will double the size of the canvas to 440 by 280.
Meaning the following URL is now 440 by 280 https://res.cloudinary.com/demo/image/upload/w_220,h_140,c_fill/l_brown_sheep,w_220,h_140,c_fill,x_220,y_140/l_horses,w_220,h_140,c_fill/yellow_tulip.jpg
To now overlay the horsed over the brown sheep you will need to recalculate the dimensions to the following- https://res.cloudinary.com/demo/image/upload/w_220,h_140,c_fill/l_brown_sheep,w_220,h_140,c_fill,x_220,y_140/l_horses,w_220,h_140,c_fill,x_110,y_70/yellow_tulip.jpg
Or
https://res.cloudinary.com/demo/image/upload/w_220,h_140,c_fill/l_brown_sheep,w_220,h_140,c_fill,x_220,y_140/l_horses,w_220,h_140,c_fill,x_330,y_210/yellow_tulip.jpg

VBA Userform: Text of same font size changes size based on Top property

I have a userform. In multiple cases across several different controls, I have observed the objects with the same Width, Height, Font, and Font Size display different font sizes depending on where they are placed on my userform.
. . . .
Above is an example of this. The two textbox's are both 26H and 48W, with a Left of 90. Both have font Tahoma Regular size 18. The only difference between them is their Top property. And yet visually, the upper one has much wider text than the lower one. The picture on the right has added dots to prove this is not an optical illusion. The upper one can only fit one dot between the letter and the edge. The lower one can fit at least two dots between the letter and the edge.
Can anyone explain why this is happening? What is happening? Or how I could stop it from happening?
Why its happening?
A normal windows graphical application renders in 96dpi/ppi.
However, excel’s rendering system is in 72dpi/ppi,so, when you specify 26 as the height, excel will first convert 72 to 96 dpi.
26 x 96 / 72 = 34.6667
Which means your control height is 34.667 pixels.
This will create artefacts in the rendering of your control.
How can you stop it?
Make sure that the final position of your control and its height has a final pixel position in the form to be a whole number.
You can do this by multiplying by your screen dpi and divide by excel dpi(72)
In your case you can apply a height of 25.5 which will render it correctly.
I hope I solved your answer!!
As Krishna Soni says in this thread, you should use a height of 25.5 for all the reasons he present.
This is equivalent to using controls with a height that is a multiple of 3. Since the rounding of 25.5 is 30, we can take 3 as a multiple of the Top, Height, and Width properties and avoid the text resizing issues.
Seen on Weird change of font size when changing Top proprierty by 1

Can a HScrollbar be used to rotate a label?

I am currently doing work for my college and I need help with a specific part of the program (Visual Studio 2010).
I have a HScrollbar that has a minimum of 0 and maximum of 85, which are supposed to represent angle values. I have it so that as you scroll the scrollbar the value is displayed in a label underneath(lblangle.text = HScrollbar.value)and above the scrollbar is a 90 ° vertical rectangle (colored -in label). How can I make it so that the colored in rectangular label rotates with the value in the label (lblangle) bellow. So for example lblangle will display 40 and so the rectangle rotates 40 degrees clockwise. I would also like this to update real time so that every time the scrollbar is scrolled the colored-in label is rotated accordingly.
Images of visuals and what should be the relevant code.

iOS constraints: 4 Buttons

I would like to place 4 buttons on the screen. They should be all of the same height and width. The margin between the buttons should be 35px and the outter margin to the views border should be 20px.
Now the buttons should be scaling to the different sizes of the screen. But all my tries with the constrains have failed.
Does somebody know how to use them properly?
layout:
---------------
| |
| x x |
| |
| x x |
| |
---------------
X are the buttons
If the result you want is the one presented below, please follow the steps:
Always keep in mind this method. Design your view as-it-should-render in your storyboard (600x600) and then apply your constraints.
Position your four buttons as expected for a 600x600px. view:
Select all buttons, then choose "Equal Width" and "Equal Height" constraint in the lower Constraint helper:
Drag-n-drop from B1 to B2 with Ctrl key pressed, release and select "Horizontal Spacing". Do the same between B3 and B4.
Repeat the previous step with B1/B3 and B2/B4 but choose "Vertical Spacing".
For B1, attach-it to 20px. from left and top bounds as presented below:
Deselect Constraint to margins before applying constraint.
Do the same for B2 (top/right), B3 (left/bottom) and B4 (right/bottom).
You're all set, your view will now scale appropriately, no matter what's the screen size.
You could write a program to calculate the sizes of the buttons. First, get your screen width, say 320. Then: 320 = 20 + button width + 35 + button width + 20
2 * button width = 245. button width = 122.5.
The same would apply for the height.
I would do the following:
1) Add a 1x1 view which has a background color which is clear and add constraints which center it relative to the containing view. This gives you a point in the center.
2) For the left buttons, set the trailing distance to the 1x1 view as 17.5.
3) For the right buttons. set the leading distance to the 1x1 view as 17.5.
4) For the top buttons, set the bottom distance to the 1x1 view as 17.5.
5) For the bottom buttons, set the top distance to the 1x1 view as 17.5.
This gives you the buttons relative to this 1x1 view. You can move this up or down now if you want the buttons at the top or bottom etc... Now you want to handle the scaling of the width.
6) Add an aspect ratio for the buttons which meets your needs. 1:1 for square etc.
7) For the left buttons, set the leading distance to the containing view to be 20pts.
8) For the right buttons, set the trailing distance to the containing view to be 20pts.
As you have the aspect ratio set, the buttons should scale width and height proportionally to satisfy the 20pt constraint and constraint to the 1x1 center point.