VideoPlayer height fit content / No black bars - nativescript

I wan't my VideoPlayer to have the height of the Video itself, so that there are no black bars. This way I can't set height to a constant value because on different devices with different width, the video has black bars. When I do this:
<VideoPlayer #video
src="https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
autoplay="true"
fill="false"
muted="true">
</VideoPlayer>
It looks like this:
I know the video aspect ratio is 16/9.
I tried something like this: [height]="video.clientWidth / (16/9)" but it's not working.
What can i do?

Related

Get Image Width & Height?

How can I get the width and height of an image in NativeScript?
I've tried referencing like:
<Image src="~/assets/images/logo.jpg" ref="img1"/>
And getting the width like:
this.$refs.img1.getMeasuredWidth
But no luck.

d3.tree scrollbar instead of panning

I have a tree width d3.js. when tree overflows svg, it is hidden and I can view hidden parts by panning on tree. is there any way to add scrollbar for view hidden parts instead of panning?
for example in this sample http://bl.ocks.org/robschmuecker/7880033 I want to add scroll bar to this tree. this sample is not what I want: https://bl.ocks.org/CrandellWS/ca7e6626c9e6b1413963
because in this example when we collapse nodes, scrollbar size not change.
You can get the svg bounding box using svg.getBBox(), where svg is your svg node, e.g.
let svg = document.getElementsByTagName("svg")[0];
let box = svg.getBBox()
and then use box.x, .y, .width and .height to calculate the correct viewBox attribute value, width and height.

How to get width/height of displayed image in javafx imageView?

I need to get width/height of displayed image in imegView and compare it to orginal image size which is in imageView.getImage().getWidth()/getHeight() and listen changes if user resize it form application GUI.
I get this size from imageView.fitWidthProperty() and similar for height, but I get size of imageView not image within it:
I get size of blue which is imageView but I need size of displayed image (green). How can I get it as property to listen when user resize window app (green also change size but it seems to have max and min size so it stop resize with imageView when it is max or min).
I use this property to compute % of size of orginal image in bottom right below blue rectangle.
Is it possible?
E: Below is fxml of this tab:
<BorderPane fx:id="root" fx:controller="..."
xmlns:fx="..." xmlns="..." stylesheets="#...css">
<center>
<StackPane>
<ImageView fx:id="..."/>
<fx:include source="...fxml" fx:id="..."/>
</StackPane>
</center>
<bottom>
<VBox fx:id="..." minHeight="110" styleClass="small-padding" spacing="5">
<HBox alignment="CENTER_RIGHT" spacing="5">
<fx:include source="...fxml" resources="..."
fx:id="..."/>
</HBox>
<TextArea fx:id="..." promptText="%..." styleClass="-fx-description-text-area"/>
</VBox>
</bottom>
When the ImageView is set to preserve the aspect ratio, one has to calculate the real dimensions by hand. At least I've not found another way.
double aspectRatio = image.getWidth() / image.getHeight();
double realWidth = Math.min(imageView.getFitWidth(), imageView.getFitHeight() * aspectRatio);
double realHeight = Math.min(imageView.getFitHeight(), imageView.getFitWidth() / aspectRatio);
To explain this a bit: getFitHeight/Width is your blue rectangle. When preserving the aspect ratio of the source image, at least one side of the blue rectangle must have the same length as the corresponding side of the green rectangle. Also, the green rectangle will always be inside of the blue one, hence the call to Math.min().
~>1)
The fact that the Image is not resizing to cover all the ImageView has to do with preserveRatio method.If you want to be covered setPreserveRatio(false);
with a combination of setSmooth( true );
~>2)
The green border is the size of the original image.
~>3)
Before adding the Image to the ImageView you can do:
Image image = new Image("FILE:...");
image.getWidth( );
image.getHeight( );
And that is the original size of the image.
As for the size of the image when it is displayed inside the ImageView:
imageView.getFitWidth();
imageView.getFitHeight();
For the size of ImageView inside the Scene (the blue border in your question):
imageView.getWidth();
imageView.getHeight();
ImageView class has properties for the above.
I am not aware of any property that you could use directly to get at the numbers you want but you might propose this as an improvement for a future version of JavaFX.
What you can do now is write some code which tracks all proerties of the ImageView which have an influence on the size of the displayed image and then compute the displayed size yourself. This does not sound too complicated to me.

How to maintain and apply aspect ratio of images in extjs4

I am working in extjs4. I am trying to display image by using following component=
xtype : 'image',
height : 600,
width : 800,
src :me.imageSrc
Where,me.imageSrc is having image path. But sometimes image is shown as blurred or expanded if image's height and width is too large. So how to calculate aspect ratio and apply it in extjs4 in order to show images properly.
In order to get the size of the loaded image you need to listen the "load" event on the image element, in the listener callback you have access to the with and height.
Here's the code that makes the magic:
var img = imageCmp.imgEl
img.on('load',function(){
Ext.Msg.alert('IMG Size',img.getWidth()+'x'+img.getHeight());
});
Here's a working example:
http://jsfiddle.net/crysfel/utUA2/
Make sure you remove the hardcoded width and height ;)

rmagick auto scaling with proportions

Is there a way for me to scale and image in rmagick where i set the width, and the height auto scales so the image contain the same proportions?
I use the resize_to_fit method, which will use the parameters supplied as the maximum width/height, but will keep the aspect ration. So, something like this:
#scaled = #image.resize_to_fit 640 640
That will ensure that either the width or height is no greater than 640, but will not stretch the image making it look funny. So, you might end up with 640x480 or 480x640. There is also a resize_to_fit! method that converts in place
If you want to resize to a given width without respect to a bounding box, you will have to write a helper function. Something like this:
#img = Magick::Image::read(file_name).first
def resize_by_width image new_width
#new_height = new_width * image.x_resolution.to_f / image.y_resolution.to_f
new_image = image.scale(new_width, new_height)
return new_image
end
#resized = resize_by_width #img 1024
Hope that helps!

Resources