Android: Draw circle of alphabets - android

I am working in android, I want to draw a circle of Alphabets, in this every alphabets A to Z must show. and this each alphabet must be clickable or touchable.
My view should look like following one:-
I do not have any idea related to this, how should I start ? please give me some suggestion so I can go ahead.what things should I use to do this.
you may provide me some suitable links.
Thank you in advance.

You will probably want to use the Android Canvas API.
Here's an example of drawing text on the Canvas: Android Canvas.drawText .
Bitmap b = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextSize(20);
canvas.drawText("Some Text", 10, 25, paint);
Just write a loop to iterate where to draw the text and iterate through a-z, like so:
for(char ch='a'; ch<='z'; ch++)
{
System.out.print(ch);
}

Related

Generate image with dynamic string in android

How could I programatically generate an image (ie output_file.png) which is a combination of user input (ie. strings) overlaid on top of another image file?
Hopefully the image below can illustrate it better
To write text directly into a bitmap you can do something similar to the following:
int textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, context.getResources().getDisplayMetrics());
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setSubpixelText(true);
paint.setStyle(Paint.Style.FILL);
paint.setTextSize(textSize);
paint.setColor(Color.WHITE);
Canvas myCanvas = new Canvas(myBitmap);
myCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
myCanvas.drawText(string, x, y, paint);
To write the bitmap to a file you can read the answer to this question here: Convert Bitmap to File
Do you actually need to create an image? Are you trying to save it/share it or just display text overlaying an image?
If you just need to overlay, you can set a textview to overlay the image using a RelativeLayout.
If you want to save and share the image, you should take a look at
How to programmatically take a screenshot in Android?

How to remove the drawing from a bitmap of a particular region in Android

I have a bitmap object.
I have a Region object that represents a small portion of the bitmap;
I want to remove drawing from the bitmap object of that particular region and make that portion transparent..
How to do it? any help....
I am using android api-level 8..
You can simply make a pixel transparent by using mBitmap.setPixel (100,100,Color.TRANSPARENT);, so basic idea is to iterate over all the pixel to make it transparent, but if you have to iterate over too many pixels, it might be slow.
OR
You can use PorterDuffXferMode to make a portion transparent,
For an example create a paint object as mentioned below and pass it to the canvas:
Paint mPaint = new Paint();
mPaint.setXferMode(new PorterDuffXferMode(PorterDuff.Mode.CLEAR));
You can pass it to the canvas as described below:
Canvas c = new Canvas(mBitmap);
c.drawCircle(cx, cy, radius, paint);
It is for the circle but hope you will get the hint to do it for the custom region as per your need.
If still it is not working then you might have to disable Hardware Acceleration for that particular View. For more information, refer this Google DOC.
Hope this will give you some hint.

Android: DrawText with background contrast

How to "set up" a paint to accomplish the "second" image above?
paint.setColor(Color.BLACK);
canvas.drawText(strValue, x, y, paint);
First Image: text all in black as result of that code above.
Second Image: better constrat to backgroud colors (edited with graphic editor just to illustrate here)
Note that "31" is partially black and partially white (but it could be any other color with a better contrast to red, as "36" could be to blue).
You could draw with PixelXorXfermode.
the only solution I could think of is that first on your onDraw you have a variable Canvas that you equals to the actual one and then you draw your number,
paint.setColor(Color.BLACK);
canvas.drawText(strValue, x, y, paint);
then you draw the red Rect
canvas.drawRect(myRect, redPaint);
then you draw your line
canvas.drawline(mStartX,mStartY, mFinishX, mFinishY, myLinePaint);
and at the very end outside your onDraw, you call a method like this one:
public void myMethod(){
Paint paint = new Paint();
paint.setColor(Color.BLACK);
this.canvas.drawText(strValue, x, y, paint);
//here you will define the area that you will mark as dirty
//(wich can have the same values as your red Rect)
Rect myRect = new Rect();
myRect.set(x0,y0,x1,y1);
//and finally here you invalidate ONLY the red area
this.canvas.invalidate(myRect);
}
Note: this will require that on your onDraw you verify that the global Canvas is not null
and if so, then you equals your global to the actual.
I'm not sure if this will actually work, however is the only solution I could think of doing so.
PixelXorXfermode is not good method when AntiAlias is set.
if you can get the red rectangle, I think use canvas.clipRect is better. like this
textpaint.setColor(black);
canvas.drawText(str,x,y,textpaint);
Rect oldClipRect = canvas.getClipBounds();
canvas.clipRect(rcRed,Op.REPLACE);
textpaint.setColor(white);
canvas.drawText(str,x,y,textpaint);
canvas.clipRect(oldclipRect,Op.REPLACE);

Trouble making parts of a bitmap transparent

I'm developing an android app where i need to capture text and save it as a transparent image. Capturing the text has been done but making a transparent png file is where i'm stuck as i'm not familiar with image pixel manipulation at all. Here's what I have so far... i first create a blank bitmap and fill it with a white background, then i set the paint's transparency to 0 (full transparency) and then draw the source bitmap into the destination bitmap using the XOR modes.. but when i run the app all i see is a blank white image. i'll be glad if someone points out what i'm doing wrong and how to fix it. Thanks in advance.
b = Bitmap.createBitmap(tw, th,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
Rect dest = new Rect(0,0,b.getWidth(),b.getHeight());
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);
canvas.drawRect(0, 0, b.getWidth(), b.getHeight(), paint);
paint.setAlpha(0);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR));
canvas.drawBitmap(bmp,null,dest,paint);
Have you looked at : How to change a bitmap's opacity?
Seems like
paint.setAlpha(0);
won't do anything as you need to set the alpha channel to something greater than 0...
Use:
Color.argb(0,0,0,0)
The first parameter is the alpha. Set it to 0 for complete transparency.

write text vertically on canvas

I want to display text vertically on Canvas.
Please help me.
You want to create a Path object that defines the verticle line you want your text to follow. Then use a canvas.drawTextOnPath() method.
Have you tried this:
Canvas canvas;
canvas.rotate(90);
canvas.drawText("The text", 0, 0, new Paint());

Categories

Resources