I have a few issues with my drag and drop. I have a resized imageview (obj) that I can drag and drop. The problem is when I drag it the cursor is in the middle. I want to change that. I'v tried db.setDragViewOffsetX(); but it doesn't work. Also the image displayed is full size, and since my imageview is resized I want it to match the imageview size but there seem to be no function to resize Image type...
Dragboard db = obj.startDragAndDrop(TransferMode.MOVE);
ClipboardContent content = new ClipboardContent();
Image sourceImage = obj.getImage();
content.putImage(sourceImage);
db.setContent(content);
Thanks for helping
I had the same problem using the Drag/Drop for precise image movements in my application. Also the effect, that for large images, the shown Drag/Drop image is scaled down was annoying too. So I decided to move images not using Drag/Drop within my application and change into Drag/Drop transfer mode if the movement left my application area.
See How to delay the Drag-Start to combine move and Drag-And-Drop dynamically for that approach.
For a solution on the mouse anchor during Drag/Drop:there also is a comment from José Perera about more control on the Drag/Drop image mouse anchor during move...
Related
How can I put an image (img2.jpg) on top of another image (img1.jpg) in an ImageView using JavaFX so that if I move ahead through the pictures of the image slider and come back to the img1.jpg, then img2.jpg stays attached on top of img1.jpg.
It's like thinking of an image of a garden (img1.jpg) and a small cat (img2.jpg) in a particular spot in the garden, it stays attached to it.
Do I use a StackPane?
I have a Button with text and an ImageView as icon. The image might be of any resolution. Currently, the button will adapt its size to fit the image, e.g. if the image is 400x400, the button will be huge and the text will be tiny next to it.
What I want though, is the image to fit into the button. It should always be as tall as the text is.
ImageView img = new ImageView(image);
button = new Button("Some text", img);
button.setStyle("-fx-background-radius: 6em;");
Wouldn't have thought the solution to this is so easy:
img.setPreserveRatio(true);
img.setFitHeight(button.getFont().getSize());
does the trick for me. JavaFX is weirdly unintuitive sometimes. If the font size may change (e.g. via CSS styling), use a binding instead:
img.fitHeightProperty().bind(Bindings.createDoubleBinding(() -> button.getFont().getSize(), button.fontProperty()));
You can set your image height via
image_view.getLayoutParams().height = YOURHEIGHT
as discussed here.
I would suggest setting your text size to an appropriate value and use the above command to scale the image to the same height.
Test around whether you can size the image with em, otherwise use cm/inch.
If there a problems with image distortion when setting height, refer to this thread.
I'm trying to build an progress bar in libGDX, for that I have one full horizontal image and in two lines I trying to display 2 different widths of that image:
imageFull:
imageFull.draw(batch,10,80,600,50);
imageFull.draw(batch,10,20,100,50);
the result is:
Its looks like when the width is 'small' its stretched and looks bad.
Why I can't display only part of the image without destroying the left side of the image?
Any ideas how to fix it?
That is normal behavior. If you stretch a image without keeping it's aspect ratio it will deform, it does not know the stretchable part by itself.
9-patch will help you here but you cannot simply draw the sprite as you are doing now (maybe with SpriteDrawable though?).
If I where you I would use the Scene2D Actor named ProgressBar. Feed that a 9-patch image, then it should stretch correctly. Or just use a Image if you want to control it yourself, and feed this image a ninepatch.
A quick way to create a ninepatch is to specify it's stretching regions yourself by hardcoding it.
texture = new NinePatch(yourTexture, A, B, C, D)
Where ABCD corresponds to the following image:
Now create a Scene2D Image with that ninepatch and it should stretch properly.
If you have a this texture already in a Atlas you can also supply the line split:a,b,c,d to the image data in the .atlas file and Scene2D will automatically pick it up as a ninepatch.
If you don't want to use Scene2D and/or ninepatch (but I recommend you to use it) you have to code the behavior yourself. Or cut the texture up yourself and stick the caps on the left and right side of your rectangle. But Scene2D is invented for this and a ton more GUI functionality.
I'm looking for an automatic way to grab a piece of a bitmap and extract a certain part of it.
Let me explain:
If I have this image:
http://imgur.com/B9U9E
It has a big white border. (see link for better white result) I'm looking for a way to only grab the dialog above. So no white borders around the dialog. Is there a way to do this by code or with a library?
You should know that the image could have any form and positioned anywhere on the white dialog.
So a user draws something on the white panel and i need the program to automatically make a rectangle about where the users drew on the canvas and save that bitmap where the user drew on the canvas (Everything in between that rectangle).
Pseudocode
Define the background color.
Scan from the left, right, bottom, top and store the locations of the transitions from background to drawing.
The rectangle defined by (left, bottom) and (right, top) defines the cropping area
For a Java code example, please see: How to auto crop an image white border in Java?
Look into Bitmap.createBitmap.
I'm having a problem with positioning images,I need to position a lot images over another larger background image.
An image Like this
I have tried Absolute but it does not keep the position of the image say I wanted to put a clip art image of a board pin over the background image and need it pointing at a sun and when it's clicked I get a popup dialog,
but then when I change the size of the emulator screen the clip art image is not at the same position I wanted it on the background image.
I first tried just putting the clip art on it with a image editor and used onTouch Listener but that didn't work out when I changed the size of the screen with the x and y coordinates. And tried Absolute Layout and that doesn seem to keep the position.
any ideas would help me big time thanks
AbsoluteLayout is deprecated, so it's probably best to use relative layout alongside with dp.
You could use relative layout so you can use layout_below="#id/view1", android:layout_toRightOf="#id/view2", and android:layout_toLeftOf="#id/view3". You can also use android:layout_marginLeft="10dip", android:layout_marginRight="10dip", android:layout_marginTop="10dip", and android:layout_marginBottom="10dip" to move the views left/right and up/down relative to their current positions. There is also ALIGN_PARENT_LEFT, ALIGN_PARENT_RIGHT, ALIGN_PARENT_TOP, and ALIGN_PARENT_BOTTOM. Click here for more properties.
You can manually calculate visible width and height of the image by using its drawable's getIntrinsicHeight() and getIntrinsicWidth() and then set Image's scaleType to FIT_XY (this saves image's ratio, and also makes its size correct, while FIT_CENTER does not).