Selecting a part of Image while Cropping - java

I'm cropping a image in java swing, but when I select a part of image for cropping, I need to make selection part visible to user.
Like a transparent rectangle on that image.

GraphPanel shows one approach to rendering such a selection rectangle, mouseRect. The rendering is controlled by the boolean selecting attribute.
Addendum: Once you know the bounds of the selection, you can use getSubimage() to clone the corresponding part of the image. There's a related example here.

Related

How can you crop an image to pieces in javafx in order to create a game puzzle with tiles?

I am trying to do a project with javafx but I can't create the figures to a puzzle game with tiles, in order to push them with the click of a button. How can an Image be cropped and saved as an individual tile ?
The ImageView class is used to display an image. It has a viewport property that represents the portion of the image it is viewing. So you can create multiple image views from the same image, each with a different viewport: then you can add the image views to a pane of some kind, register mouse handlers on them, etc.
If you actually need to store each piece as an individual image, you can snapshot the image view to create a new Image from it. You'll probably find you don't need this, however.
You might want to try PixelReader and WritableImage APIs from JavaFX platform.

how can I create a custom clickable shape on an image in android?

I want to create a clickable image, my image has some different clickable parts in it, like this one:
I want to draw a custom shape like :
A,B,C,D,E,F
and make sure when user click on of this something happen.
the problem is I don't have any kind of idea to, how create shapes like the shapes in the image make sure it just fix on the image and in different screen size don't see a massed up thing.
Will there be more than many of such images?
If no I suggest you to create mask image for each region where black part of image represents the region and white part excludes rest.
To draw image:
create custom View
in constructor don't forget to use setWillNotDraw to true so you can do custom drawing
override View.onDraw method where you can draw main image and all others with some filters via setColorFilter.
To handle click events:
override onTouchEvent method
get touch position
compare touch position with point color in mask image
To optimise:
create mask image downscaled by some scale factor
during comparison divide touch position by scale factor
This is not ideal, but solution with vectors is non trivial I think
Take it as image and setOnclickListner for that image

Dimensions of an Android Image

I am creating a reference app which has a navigation bar at the top and the information, in the form of an ImageView, below it surrounded by a ScrollView. I have worked out how to change the image when the next button is pressed. I noticed this being implemented on the below app. I am able to get all the programming working, but I am not to keen on visual editing.
http://media1.android-apps.com/images/pname/com.ninjacoders.mcanary/image1.png
What should the dimensions of the Image be in Gimp?
How would I go about creating customs home screen buttons, and what dimensions should I use for them?
Any further advice on how I should do this would be greatly appreciated.
From within GIMP, you should zoom enough your image - and work with the "pencil" tool, and the "pixel" brush (the one brush right after the pepper brush - they are sorted alphabetically) - this will allow you to proper edit pixel-art images.
You can use teh colorpicker and create a new palette resort to let it easier to pick the few grey tones you are using.
To get to know the exact dimensions, one of the tools in GIMP's toolbox is the "measure" tool - use it to get to know which icon size you need.
As a final tip: do your work on this larger image, and draw the icons you want in separate layers - whenever an icon is done, crop its layer using the crop tool, with the option "crop layers" on (else it will crop the whole image) - and then drage the thumbnail for the image layer containing your icon from the layers dialog into the toolbox - this will create a new image consisting of the icon alone (and is a quite faster workflow than copy + paste as new image).

moving images in java applet

The question is about java applet programming
I used a java applet to draw an image in the paint method using the following code:
g.draw(Myimage,0,0,this);
The image was drawn on the screen, But what i want to do is to be able to change the position of this image without clearing the screen and without drawing blank image in the previous position of the image..
Thanks in advance.
You can simply draw another image in other place. Just change the parameters in your code. For more details about graphics object follow the link. http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/Graphics.html
Other wise why dont you simply extend GraphicsProgram class provided by acm. It has a move function which will exactly do what you want to do. Check out the link.
http://jtf.acm.org/rationale/graphics-package.html
Hope this helps.
But what i want to do is to be able to change the position of this image without clearing the screen and without drawing blank image in the previous position of the image..
Then use a JLabel. When you want to move the label you use the setLocation() method. The RepaintManager will repaint the location where the label was and then paint the label in its new location so you don't have to worry about calculating the area affected by the move.

How to create a custom Java Swing GUI Component with a shape and gradient

I have to create a custom component on my JFrame, the Component will show the storage status of that user, the storage will be in percentage.
I need to create something like this:
I tried a custom JLabel to create a label and then coloring that label from left to right, but I was unable to create a cloud shape Label and then filling that label according to a variable value.
How should I do this and what is the best way to do it?
One time I thought I should use series of images to show the status of user storage.
Thanks!
I think you're going to need to use an image mask (examples here and here) if you are to replicate that cloud exactly.
The process will require 2 images:
The cloud outline (the blue parts)
An image mask is the shape of the cloud, probably black outside and white inside
Then your drawing process, which you'll have to do each time the % storage changes will be:
Create a new buffered image
Draw then green fill bar in the style you want (e.g. slanted as in this image)
Copy the image mask over this
Draw this new image to the screen, with the mask applied as described here
Draw the cloud outline image to screen
That's going to take an hour or so for you to put together, so I'm not going to do it for you. Have a go, and if you run in to problems (or don't understand anything I just described) then ask about that specifically.
You can use GlyphVector#getGlyphOutline() to get the shape of a Unicode character like ☁ \u2601 and fill it with a GradientPaint.
You can do that with a JLabel and a custom-implemented class derived from Icon.
doesn't this help? Java gradient label example
And if you understand (or can translate from) portuguese, there's also this discussion with a solution at the end

Categories

Resources