Reputation: 22988
I'm trying to create a custom component looking like a rectangle radio dial:
As a base I'm taking the custom ScrollableImageField.java component and passing it an image from project resources in my Screen:
_dial = new FMRadioDial(EncodedImage.getEncodedImageResource("big_dial.png"));
_dial = new FMRadioDial(bmp);
add(_dial);
This works well and I can scroll an image by the optical touch pad and also by swiping the Torch screen.
Then I'm trying to generate a white rectangle image myself:
Bitmap bmp = new Bitmap(Display.getWidth()*4, Display.getHeight()/2);
_dial = new FMRadioDial(bmp);
add(_dial);
this compiles, but I get a black image.
So my question is: how to generate an image (should I use Bitmap or maybe EncodedImage here?) from the code and how can I paint a white rectangle, a gradient and some text into it?
Thank you! Alex
Upvotes: 2
Views: 831
Reputation: 863
Hi you can do something like this:
int bmpWidth = 100;
int bmpHeight = 100;
Bitmap bmp = new Bitmap(bmpWidth,bmpHeight);
Graphics g = new Graphics(bmp);
int[] X_PTS = { 0, 0, bmpWidth, bmpWidth };
int[] Y_PTS = { 0, bmpHeight, bmpHeight, 0 };
int[] drawColors = {0x646464, 0xffffff, 0xffffff, 0x646464 };
g.drawShadedFilledPath(X_PTS, Y_PTS, null, drawColors, null);
g.setColor(0x0000ff);
g.drawText("TEXT", 50, 50);
But if you want to just display it, you don't need to create Bitmap, you can extend Field and override paint method:
public class CustomField extends Field {
private int myWidth = 200;
private int myHeight = 100;
public int getPreferredWidth() {
return myWidth;
}
public int getPreferredHeight() {
return myHeight;
}
protected void layout(int width, int height) {
setExtent(myWidth, myHeight);
}
protected void paint(Graphics g) {
int[] X_PTS = { 0, 0, myWidth, myWidth };
int[] Y_PTS = { 0, myHeight, myHeight, 0 };
int[] drawColors = {0x646464, 0xffffff, 0xffffff, 0x646464 };
g.drawShadedFilledPath(X_PTS, Y_PTS, null, drawColors, null);
g.setColor(0x0000ff);
g.drawText("TEXT", 50, 50); }
}
Upvotes: 1