Advertisement
Guest User

Untitled

a guest
May 3rd, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. img= (ImageView) findViewById(R.id.imageView);
  2. skBar= (SeekBar) findViewById(R.id.seekBar);
  3. Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.img);
  4. bm = textAsBitmap("TEXT CHECK", 140.0f, Color.BLUE);
  5. img.setImageBitmap(overlay(bm,bm));
  6. skBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
  7. @Override
  8. public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
  9. img.setRotationY(Float.parseFloat(String.valueOf(progress)));
  10. }
  11.  
  12. @Override
  13. public void onStartTrackingTouch(SeekBar seekBar) {
  14.  
  15. }
  16.  
  17. @Override
  18. public void onStopTrackingTouch(SeekBar seekBar) {
  19.  
  20. }
  21. });
  22.  
  23.  
  24. public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
  25. Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
  26. Canvas canvas = new Canvas(bmOverlay);
  27. canvas.drawBitmap(bmp1, new Matrix(), null);
  28. for (float i = 20; i > 0; i-=0.5f) {
  29. canvas.drawBitmap(bmp2, i, i, null);
  30. }
  31. for (float i = 1; i <= 20; i+=0.5f) {
  32. canvas.drawBitmap(bmp2, i, i, null);
  33. }
  34. return bmOverlay;
  35. }
  36. public Bitmap textAsBitmap(String text, float textSize, int textColor) {
  37. Paint paint = new Paint();
  38. paint.setTextSize(textSize);
  39. paint.setColor(textColor);
  40. paint.setTextAlign(Paint.Align.LEFT);
  41. paint.setTextScaleX(1.5f);
  42. // paint.setTexth(5.0f);
  43. float baseline = -paint.ascent(); // ascent() is negative
  44. int width = (int) (paint.measureText(text) + 0.5f); // round
  45. int height = (int) (baseline + paint.descent() + 0.5f);
  46. Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  47. Canvas canvas = new Canvas(image);
  48. canvas.drawText(text, 0, baseline, paint);
  49. return image;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement