So I have an image and I set its position absolute (jsf). Then the user can change the position with the drag/drop functions from primefaces. The new coordinates (left/top) are then stored in the mysql database. When the page is reloaded, the image is again absolutely positioned with the coordinates from the db.
For example the image coordinates are (the page is scrollable): left:68px; top: 826.5px
--> In java I use itext and I want to place the image with the absolute values from the database. I know that the 0/0 coordinates of the PDF document are bottom left.
I want to use image.setAbsolutePosition() but how does the coordinates match???
They right coordinates for the pdf would be: x about 135 and y about 700 but how this fit together with the coordinates on the screen 68px/826.5px? I have already calculate around a lot but do not understand it...
I also scale the images: the original with/height on screen: 35x35
and I use: image.scaleAbsolute(25, 25);
So how does this work? thx :)
If you have an image whose top left corner is at {x,y} in a top-left coordinate system and you want to place it in a coordinate system that uses bottom-left for the origin and bottom-left for placement then you need to know both the height of the image and the height of the document. The {x} won't change but the new {y} should be Document.Height - {original y} - Image.Height}.
The image below shows an image that's at {50,50} in a top-left system. Once we add it to a document we need to know the document's height (800px) so that we can map. We also need to know the image's height (75px).
Related
I was curious how would I move pixel with particular coordinates to another location? Or in other word, change the locations of pixels in the image? And then output the changed image again.
using Images
img_lab = rand(Lab, 10, 10)
For example pixel in (1,1) move to (2,3) and overwrite the existing pixel.
Later I want to implement this idea to real images and to all pixels in the image.
img_lab[2,3] = img_lab[1,1]
The image is just a matrix, and you manipulate its elements the same way.
I want to make a controller button prompt in my game where it says 'Press X to Join', but I want the X to be an actual graphic of the 'X' button, like how it is in many games. How would I go about doing that? Right now I'm just putting a big space in my prompt text and putting a UI Image of the button in it, but I want to know if there's a better way about it.
For the sake of scaling to different resolution sizes, you would wanna scale the anchors of the UI elements correctly and have an appropriate parent-child relation tree in Unity's hierarchy.
The red box is the hierarchy.
The 2 green boxes shows ways of scaling the anchors.
The orange box shows the end result of it.
Anchors in combination with their relative position, allows Unity's UI elements to scale up and down according to screen size.
So for example if you say that an anchor is at 0.25x, that would be that its anchored at 25% of for example the x axis. Same goes if you set it for the y axis, just the vertical instead of horizontal anchoring.
You can use the anchors to adjust a minimum and a maximum anchor which the elements may float within, they may have the same value as well, then it's a fixed anchor point.
To clarify, I suggest that you use a panel to hold 2 text elements and the image with the X, each text element being on the left and right side of the X instead of having spacing inside the UI text elements. To keep correct spacing you then must use anchor points. This way your spacing stays correct despite changing screen and resolution sizes.
Please note that the "left", "top", "right" and "bottom" values are then relative to the anchor points. So if you move "left" 5 pixels, those 5 pixels will be out from the relative anchor point.
Here's the values I used:
My left text is at 0.25x, right text is at 0.8x, image is at 0.5x.
The panel holding the 3 is at 0.2 minimum x to 0.8 max x, same goes for y axis.
The largest parent panel is stretched to max fit in the canvas.
I am using http://imageresizing.net/ tools to create an editor.
The user can crop and rotate, but when they crop first and then rotate they lose the correct crop coords because the image coords have changed
for example, given a 100x100 image with a crop of the top left 50x50 pixels would then get rotated clockwise and now shows the crop as the original bottom left 50x50 pixels of the source image.
another example with images:
step one crop:
step two rotate:
coords haven't changed, but now it is no longer the proper crop area
does anyone know of a way to have the crop be relative to the original instead of the origin point?
Are you building something like StudioJS?
StudioJS uses ImageResizer.js to manage the command string and translate co-ordinates.
Consider a workflow where your user crops, rotates, and then re-crops the image. To preserve the original crop you will need to translate the coordinates in javascript. ImageResizer.js can do this.
Is there any way of labeling plots with images. For example, when I use the following:
plot(Y(:,1),Y(:,2),'o','LineWidth',2);
gname(names)
I can label each dot in a plot with a name. Is there any way to insert images instead of names?
It is possible, but not as convenient as gname by far. You can use the low-level version of image to insert images in your plot at arbitrary positions. Here's a simple example which puts the "Mandrill" image that comes with Matlab with its upper left corner pixel at the position (pi/2, 0):
% example plot
x = linspace(0, 2*pi, 100);
plot(x, cos(x))
% insert image
load mandrill
colormap(map)
image('CData', X, 'XData', [pi/2, pi/2 + 0.5], 'YData', [0, -0.3])
The result looks like this:
Problems with this approach:
There is no interactive point-and-click facility, you have to explicitly insert and position the image labels programmatically, or program such a point-and-click facility yourself. ginput might help doing so.
A figure window can only have one associated color map. That means if you have different images, they either all have to use the same colormap or have to be truecolor images.
Not just the position, but also the display size of the image has to be specified in the call to image, and both are by default specified with respect to the plot's coordinate system. This makes it hard to achieve the correct aspect ratio. You can switch (temporarily) to absolute units using the axes property 'Units' , but then you have to figure out the correct position in e.g. absolute millimeters or inches. Moreover, images are usually indexed with vertical coordinates increasing from top to bottom, while plots usually have vertical coordinates increasing from bottom to top. This is the reason for the negative value -0.3 in the 'YData' property above.
Alternatively, you can insert images each in their own little axes sitting on top of the plot's axes, which makes it easy to get the right orientation and aspect ratio using axis image. You'll still have the problem though to figure out the correct position for the axes.
I have a GUI which display 2D image. However, I am not able to recover data accurately by using mouse coordinates. This is because I am not able to convert image coordinates to array indices properly.
I use ginput to get mouse coordinates.
Any help would be appreciated.
Regards
Dushyant
When displaying an image in matlab, your origin(for image) sits at top left corner of the image, x-axis increase towards downwards and y-axis increase towards right, while with mouse you get co-ordinates with x-axis increasing towards right and y-axis towards up(so a rotation of +90 degrees with respect to image co-ordinates plus a translation),,, so you have to transform one of your co-ordinates to the other to get the right values, for example if your origin of figure window is at top left corner and image spans the whole frame then,,,
x_image = -y_mouse and
y_image = x_mouse.
Try that:
fig=figure, imshow(myfigure);
[x, y] = getpts(fig);