Scaling ImageView Programmatically - imageview

I have 7*7 ImageViews and I want to put them scalingly in some positions.
I need to know how I scale ImageView and how to set their position relatively to screen size.
(I will need to reposition and animate them dynamically after program start)

You need to add a CGAffineTransormation onto the image view
imageView.transform = CGAffineTransformMakeScale(CGFloat sx, CGFloat sy);
This will scale down the image view, and will give you your desired output
Dealing with the repositioning, all you gotta do is add a CGAffineTransformationTranslation
imageView.transform = CGAffineTransformMakeTranslation(CGFloat tx, CGFloat ty)
Do this with all the image views that you watn, and you will get what you want
Hope this helps!

Related

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))

Resize window using QPropertyAnimation

I have the following problem: I want to resize a window using QPropertyAnimation, so as to look nice, but the window also instantly moves while the resizing takes place, while I don't want it to, I just want to resize the window and not to alter its position value.
So, here's my code:
animation = new QPropertyAnimation(this, "geometry");
animation->setDuration(150);
animation->setStartValue(QRect(preferences::x(), preferences::y(), width, window_height_min));
animation->setEndValue(QRect(preferences::x(), preferences::y(), width, window_height_min+expand_general_to));
animation->start();
where width and window_height_min and expand_general_to are my own variables that handle the amount of the resizing that has to be done. BUT, preferences::x() and preferences::y() truly handle the position of my window, so why it moves, while prefereces::x() will be the same both of the times? (in the start and in the end value) ?
Thanks in advance for any answers!
Please try to set size property.
animation = new QPropertyAnimation(this, "size");
animation->setDuration(150);
animation->setStartValue(QSize(width, window_height_min));
animation->setEndValue(QSize(width, window_height_min+expand_general_to));
animation->start();

Seadragon ajax fix coordinates system

I'm trying Seadragon Ajax with coordinates system in order to show in my website large images with big resolution .
I would to view a part of this image knowing their coordinates. The problem is that when I make zoom or drag the image , coordinates no longer correspond to the same part of the image.
I try with some code but no way.I need that coordinates system is fix for all the image .
As i can do?
Thanks
Sure, no problem. You have to transform the "real" pixelbased coordinate to the seadragon point-coordinate.
"Seadragon Ajax uses a normalized coordinate system. The top-left of the image is always at the origin (0, 0) while the width of the image is always 1. The height of the image is dependant on the aspect ratio, so an image which is half as tall as it is wide will have a height of 0.5"
So, if you know that your image is 500x500px, then point 1,1 = 500px,500px and 0.5,0.5 = 250px,250px.
Convert by writing a function like this:
var my_position_x=333; // the position you want to get point for
var my_position_y=666; // the position you want to get point for
var width=500;
var height=500;
var pointx=1/width * my_position_x;
var pointy=1/height * my_position_y;

How to scale and clip a BitmapImage in Flex 4.5

Here's my problem, I need to scale and clip images into square sized tiles to put into a tile list. Here's how I want it to work:
I want all my tiles to be, say, 300px x 300px.
For each image, I want to scale the shorter side (either width or height) to fit in the tile using the "letterbox" scaleMode (so that it maintains aspect ratio).
Then I want to position the image in the center and clip away anything left over from either both sides or the top and bottom.
Here's an example to help clarify:
I have an image with width=600px and height=1200px. First I want to scale the image to width=300px and height=600px (notice that aspect ratio is maintained), then center the image vertically and clip the image to 300 x 300.
Is this possible? This is actually a pretty standard way of displaying square thumbnails in many photo-based web sites, but I can't find a way to make it work in flex.
Any help would be appreciated, thanks!
UPDATE JUNE 2012:
Just in case anyone finds this thread now, this issue has been resolved in the latest version of the Flex SDK. On the spark image object there is a new scaleMode of "zoom" which does exactly what I've asked for here.
Take your big image and draw it on BitmapData with scale and reposition:
const zoom:Number = Math.max(THUMB_WIDTH/image.width, THUMB_HEIGHT/image.height);
const x:int = (THUMB_WIDTH - image.width*zoom)/2;
const y:int = (THUMB_HEIGHT - image.height*zoom)/2;
var matrix:Matrix = new Matrix;
matrix.scale(zoom, zoom);
matrix.translate(x, y);
var _thumbBitmap:BitmapData = new BitmapData(THUMB_WIDTH, THUMB_HEIGHT, false, 0xFFFFFF);
_thumbBitmap.draw(image, matrix, null, null, null, true);
Then assign resulting BitmapData to the source of the BitmapImage.
More: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#draw%28%29
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/primitives/BitmapImage.html#source

Resize Flex/Flash object from the left side?

I'm working on Flex component which can be resized using handles on the right and left (that is, if you click and drag the left side, the component will grow to the left, if you click and drag on the right, it will grow to the right).
Right now I am using:
var oldX:Number = this.x;
this.x = event.stageX + (initial.x - initial.stageX); // Move the left edge to the left
this.width += oldX - this.x; // Increase the width to compensate for the move to the left
But that makes the right side jump around, and generally looks ugly.
What is the "right" to do this? Is there something fundamental I've gotten wrong?
Thanks!
Edit: The jitter occurs on the right side of the component. When I set this.x, the component moves to the left, the screen redraws, then the width is updated, and the screen redraws again.
I'm not a Flex guy, but I imagine your jitter is something to do with the Flex framework internally using Stage.invalidate() or some such thing to cause redraws during frame execution.
I imagine there's probably a "framework" way to deal with the problem, but for a workaround to make your change into one atomic operation you could update the object's transform directly, along these lines:
var dx:Number = // however you're finding this
var m:Matrix = new Matrix();
m.scale( scaleX*(width-dx)/width, scaleY );
m.translate( x+dx, y );
transform.matrix = m;
That should work for a simple graphic, but I'm not sure if it would work with a component that probably needs to catch events that the dimensions have changed and redraw itself. I think that's the only way to make your update atomic though, so if something along those lines doesn't help then you'll need an answer from someone more up on the framework.
Had the same problem.
The problem is that the stage isn't refreshing enough.
Just add stage.invalidate(); after your 2 assignments ...
Depending on how you have the listeners for the handles set up, the problem could be that the resize code is called over and over again because when you set the new x position for the component the handle will go under the mouse cursor effectively calling the resize code again and so on.

Resources