How can I make the ImageView as the same size fitting to the image in in - imageview

I have picture s such as 33*120 (height*width)
it is transparent ping,so this size is including transparent area.
My code is like this
in xml
<ImageView id="Pic"/>
in tss
"#Pic": {
backgroundColor:'blue',
image:"./img/menuj.png"
textAlign:Ti.UI.TEXT_ALIGNMENT_LEFT,
height:'10%',
left:'1%',
},
I would like to adjust imageview size to 10% height and width should keep the same ratio as original image size.
But,blue area(view) is much wider than I expected.
(blue area appears much bigger than image itself,moreover image file is not even left aligned in the view.)
How can I fit the ImageView to the image size?

just pass to the imageview the height and width of the original image (in your case, since you want a different height, the image might get stretched/shrinked).
Like this:
"#Pic": {
backgroundColor:'blue',
image:"./img/menuj.png"
textAlign:Ti.UI.TEXT_ALIGNMENT_LEFT,
height:'10%',
width: "120px"//PUT HERE THE WIDTH OF THE ORIGINAL IMAGE
left:'1%',
}
One last thing, drop the comma at the end of the tss description, it's not required.

Related

Konva-react Image Crop Functionality

I am using konva-react and want to crop my uploaded image in canvas editor. My approach is to show a rectangle on the selected image. when that rectangle is resised, then in onTransformEnd method, I am giving crop object with width, height , x and y as the resized rectangle.
Further If I want to crop more, then I want to show the actual image with reactangle to show the cropped part.
The issue is, when I try to crop second time, it sheo the cropped image and not the actul one. enter image description here

Responsive CheckBox JAVAFX

This is my first javaFX project. The project I'm working on includes a feature where the application window can be resized. Upon resizing the window, I expect all objects in my window to increase proportionally according to the window resize. I am not getting this to work with the "CheckBox" Objects.
As you can see below highlighted in red, a CheckBox object is shown before and after a window resize. Before the resize the red checkbox nicely fits in the green box, but after the resize, the red checkbox is the correct (scaled) width, but did not increase in height as I'd expect. Where should I begin my effort to make my CheckBox objects more vertically responsive?
Minimized
Maximized
As you can see (IN RED), the CheckBox scales horizontally as I expect, but it doesn't scale vertically to occupy the remaining space!
After a lot more research and helpful responses, I gathered a solution that works.
A "DoubleProperty" object is made, and binded to the width of the container holding my checkboxes. Call this container, "dryLeafGridPane" for example.
DoubleProperty checkboxFontSize = new SimpleDoubleProperty(10);
checkboxFontSize.bind((dryLeafGridPane.widthProperty().divide(36)));
The .divide(36) scales the CheckBox's font size to 1/36 the gridpane's width.
Finally, I just add the new font size using CSS.
dryLeafGridPane.styleProperty().bind(Bindings.concat("-fx-font-size: ", checkboxFontSize.asString()));
Here is a gif of the (slightly more) responsive app!
You can choose to increase the font size on the root pane when you go full screen. For example:
rootPane.setStyle("-fx-font-size: 150%;");
That isn't perfect though... it seems the size of the box that is checked doesn't scale with the font.

MURA: getImageURL small size cuts off the image

The small size creates an image too large to fit in the box. Is there a way by which the image can be wrapped completely?
I am doing
<div class="catimgback">
<img src="#arguments.item.getImageURL(size='arguments.size',width=arguments.width,height=arguments.height)#" alt="#htmlEditFormat(arguments.item.getValue('title'))#" class="catimg" />
</div>
Where arguments.width = 163px; arguments.height=163px; and arguments.size = small
If i make catimgback's style=height:100% then all goes well. Also, I played with keeping the size to be custom and giving custom width and height but could not get the images to work. all the small size images gets cut off.
I think you may be confused as to how getImageURL() works. The only time you need to pass in the height or width arguments, is if you pass in size='custom' or omit the size attribute altogether.
Also, when you use size='custom', the image gets cropped automatically based on the dimensions of the image that's been uploaded. So, in your case, you want a square image ... but what if the image that's been uploaded is not exactly square, maybe it's a rectangle. So, in that case, Mura starts at the very center of the image, then scales out from there to the outer most boundaries. If the image were a vertical rectangle, you can imagine then that the top and bottom parts of the rectangle won't make the cut. Conversely, if the image were a horizontal rectangle, then the left and right edges of the image won't make it into the cut.
What you really want in this case is a pre-defined image size called catimg with a height and width attribute of 163px. To create this:
Go to Site Config > Edit Site from the Admin area
Click the Images tab
Towards the bottom, click Add Custom Image Size
Enter a Name (for example, catimg)
Enter the Height
Enter the Width
Click Save (You now have a custom image size that can be used for any content items)
Go to the Site Manager, and add/edit a content item
If editing an existing content item that already has an image, click the crop marks to get to the Image Details screen. Otherwise, select an image to upload, and Publish.
From the Image Details screen, scroll down to the custom image size you've created, and you can now Re-Crop your image to select your desired image region.
Now, anytime you call getImageURL(size='catimg'), Mura will use this specific image to display.
Cheers!

Resize images inside qt-label

I have a qt label which by default has a place holder image in it:
self.label.setPixmap(QtGui.QPixmap(_fromUtf8("place_holder.jpg")))
There is a function to update the image contained in the label which is:
def selectFile(self):
image = QtGui.QFileDialog.getOpenFileName(None, 'Select Reference Image', '', '*.jpg')
self.label.setPixmap(QtGui.QPixmap(_fromUtf8(image)))
This works fine (the image is updated), but it is also deformed if the image used to update the label has different size from the place holder image.
Is there any way to fix this? I mean to adapt the image and to keep fix the size of the label?
You can try to set the scaledContents property:
self.label.setScaledContents(True)
self.label.setPixmap(QPixmap("your_image.jpeg"))
It works fine for me.
Beware that this scale the image to fill all available space. It means that the aspect ratio of the image wont be preserved unless the label size and the image have the same aspect ratio. You will have the same problem using the QPixmap.scale method as you can see in the images here.
Scale the image each time you import it. If you already have a size in mind for your label, you can even scale the place holder.
try (c++)
//initial setup
QPixmap pixPlaceHolder = QPixmap(_fromUtf8("place_holder.jpg");
QSize desiredsize = pixPlaceHolder.size(); // or any of the size you want
Each time you select a file:
label.setPixmap(QPixmap(_fromUtf8(image).scaled(desiredsize));
try this, this helped me for scaling the image to fit the label while maintaining the aspect ratio. Will also help to resize the image based on the label size.
pixmap = QPixmap(x)
pixmap = pixmap.scaled(self.label.size().width(),self.ui.label_4.size().height(), Qt.KeepAspectRatio)
self.label.setPixmap(QPixmap(pixmap))

BitmapData with Scale9Grid

I have a Skin for SkinnableContainer.
Skin contains only the original contentGroup and s:BitmapImage as background.
Background image stretchers out according to width and height content.
The used image is .png with transparent regions.
To create hitarea, I used this algorithm:
http://www.webverwirklichung.com/en/blog/programming/flex/creating-hitarea-png-image-transparent-alpha-regions-flex
Everything's working fine until I start to stretch the SkinnableContainer (along with the image in the skin).
I have a scale9Grid for the image.
The problem is, that when stretching the image, the bitmapData of the image is still the same (same width and height). Therefore I need to somehow obtain the bitmapData of the image for the scale9Grid application.
The background of the component is an image, which has some transparent areas. It is only possible to click on the visible part of the image. The image will stretch according to the content in contentGroup.
Need an advice, please.
How about using the BitmapData.draw() method?
After the container is resized and the 9 slice scaling has been applied (or whatever the appropriate trigger is) do:
var b:BitmapData = new BitmapData(container.width, container.height);
b.draw(container);
Then use this new bitmap with the algorithm that creates the hit area.

Resources