Creating a color image in j2me - java

I need to create different image size with green color in microedition, is it possible?
I need to create the image on the fly without loading an image.

Here you go,
http://www.java2s.com/Code/Java/2D-Graphics-GUI/DrawanImageandsavetopng.htm
change the color from black to green in example.
If you want images to be unique draw unique numbers instead of text.
if you don't want to use text in the image then simply draw something but start the drawing at a random location in the image.
Out of curiosity are you trying to test the servlet or the phone app?
Sorry earlier I missed that you wanted to achieve this in J2ME
See the link below
http://www.java2s.com/Code/Java/J2ME/MutableImageExample.htm

Related

Change Specific Colors of Drawable on Runtime

I am learning android studio using Java and I want to know if it's possible to change a specific color of a drawable.
Say for example, I added a PNG image in res as a drawable. This image has 3 distinct colors (red,green,blue), and during runtime, I want to output an image where all red(#FF0000) is changed to orange(#FF8800) and blue(#0000FF) to violet(#FF00FF). Green remains green. I have done this in other languages, where sometimes I iterate pixel by pixel, and sometimes they already have a function to input original color and desired color.
Any way to achieve this without making a custom function? I can consider leaning other methods other than uploading a PNG image if neccessary, as well as using libraries.

how to get a region out of an image?

Lets say I use a black key jpg image as my layout in Java Code. Is there an easy way to get the region out of an image so I can use region.Contains() for my onTouchListener?
I've looked for them and there isn't any. I ask this because Im making a piano app and would like to get the regions of the images I use for the black/white keys.
Rather than use an image, try rendering the piano keys yourself, and check if input is in the black key regions you render, rather than using an image.
If you really want to use the image, define the black regions within the image by hand.
Detecting regions in an image is a difficult problem, one you probably don't want to get into for such a simple purpose. If you had many images, or had to do this frequently it might be worth the headache but as you presumably don't... don't worry about it.

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

Java: Is it possible to take a GUI Panel and output it into a picture?

So I have this chart that's a little special. Kind of like an XY plot of points but my boss wanted to look like a bunch of boxes rather than dots connected by lines. And I basically made a chart using gridlayout and a whole bunch of cells that I'll be colouring in black or white depending on the data.
Now he sorta wants it to be outputted to a image file. Is there any way to save a Panel into a picture? He wants to display not only the data but also save a visual representation of the data into an image file.
Is there any way to save a Panel into
a picture?
Screen Image
You can create a Graphics context which paints to an image. This technique is often used with animations to prepare drawings offline and swap them in place to avoid artifacts.
Typically you can use the same paint methos as used to paint your canvas.
Here are more details

Android color picker - updating color array

I'm trying to create a color picker for Android that looks like a minimalistic version of Gimp's. So, it has a hue slider and a rectangle with saturation/value variants of a color chosen in hue slider.
Question: what is the best way to create the rectangle?
Right now, I'm creating an 200x200 array of pixels, but it takes ~5sec to create and display rectangle with that array. And I need colors in rectangle to change whenever I change the value in hue slider...
Rectangle is bitmap, btw. Can I use color matrices on that and how? Any examples?
Thanks in advance!
You can create the rectangle with saturation/value variants that change according to the selected hue, by drawing the rectangle with LinearGradients.
You can incorporate the code here: http://code.google.com/p/android-color-picker/ into your application. Seems that this is what you want.
OpenIntents has a very nice color picker you can use. It can be installed as an independent app and launched with Intents.
Code: http://code.google.com/p/openintents/source/browse/#svn/trunk/ColorPicker
Screenshots/download: http://www.openintents.org/en/colorpicker
Intent specification: http://www.openintents.org/en/node/670
One possibility is to pre-create the rectangles on your developer PC for each slider position, embed them as resources, and then swap in the right one when the slider changes. This may make for a portly application, but it will be nice and quick.
I have not dealt with the 2D graphics API much, so I don't know if there are other possibilities (e.g., color matrices).
Can this be applied to an image color picker as well?
Use case:
Select a particular pixel on an image.
The pixel selected generates a color on a rectangle shape.
Perhaps generating color codes for the pixel selected?

Categories

Resources