Android : Android rotated text with gesture on canvas

on Sunday, August 31, 2014


My goal is to take a picture from the camera or the gallery and add some text on it and allow the user to rotate the text with his two fingers, I have managed to rotate the text on the image but the text duplicates itself


http://i.stack.imgur.com/LkX91.png


Here is the code:



Bitmap bitmap = ((BitmapDrawable) ivImage.getDrawable()).getBitmap();

// Bitmap cs = null;
out = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.RGB_565);
Canvas comboText = new Canvas(out);
Paint paint = new Paint();
paint.setColor(Color.RED);

comboText.drawBitmap(bitmap, 0, 0, null);

int x = 75;
int y = 185;
paint.setColor(Color.GRAY);
paint.setTextSize(25);
String str2rotate = "Rotated!";
Rect rect = new Rect();
paint.getTextBounds(str2rotate, 0, str2rotate.length(), rect);

comboText.rotate(-1 * angle, x + rect.exactCenterX(), y + rect.exactCenterY());
paint.setStyle(Paint.Style.FILL);
comboText.drawText(str2rotate, x, y, paint);

ivImage.setImageBitmap(out);


This code is when the ImageView has triggerd an event which recognize RotateGesture and returns the angle, The problem is when I set the "out" bitmap to the image view and using it again at the begining.


Hope you understand what im tring to do, Please help :)


0 comments:

Post a Comment