Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- img= (ImageView) findViewById(R.id.imageView);
- skBar= (SeekBar) findViewById(R.id.seekBar);
- Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.img);
- bm = textAsBitmap("TEXT CHECK", 140.0f, Color.BLUE);
- img.setImageBitmap(overlay(bm,bm));
- skBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
- @Override
- public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
- img.setRotationY(Float.parseFloat(String.valueOf(progress)));
- }
- @Override
- public void onStartTrackingTouch(SeekBar seekBar) {
- }
- @Override
- public void onStopTrackingTouch(SeekBar seekBar) {
- }
- });
- public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
- Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
- Canvas canvas = new Canvas(bmOverlay);
- canvas.drawBitmap(bmp1, new Matrix(), null);
- for (float i = 20; i > 0; i-=0.5f) {
- canvas.drawBitmap(bmp2, i, i, null);
- }
- for (float i = 1; i <= 20; i+=0.5f) {
- canvas.drawBitmap(bmp2, i, i, null);
- }
- return bmOverlay;
- }
- public Bitmap textAsBitmap(String text, float textSize, int textColor) {
- Paint paint = new Paint();
- paint.setTextSize(textSize);
- paint.setColor(textColor);
- paint.setTextAlign(Paint.Align.LEFT);
- paint.setTextScaleX(1.5f);
- // paint.setTexth(5.0f);
- float baseline = -paint.ascent(); // ascent() is negative
- int width = (int) (paint.measureText(text) + 0.5f); // round
- int height = (int) (baseline + paint.descent() + 0.5f);
- Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
- Canvas canvas = new Canvas(image);
- canvas.drawText(text, 0, baseline, paint);
- return image;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement