1
\$\begingroup\$

I'm trying to fit a bitmap to a random size rect but I don't want the bitmap to be streched out. I've tried using BitmapShader and tile it but it become animated and not fixed.

Here is my code without BitmapShader.

 public void draw(Canvas canvas) {
      Paint paint = new Paint();
      canvas.drawBitmap(spike1, null, rectangle, paint);
      canvas.drawBitmap(spike1, null, rectangle2, paint);
 }

Here is my code with BitmapShader.

 public void draw(Canvas canvas) {
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(spike1, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT));
    canvas.drawRect(rectangle, paint);
    canvas.drawRect(rectangle2, paint);
}

Here is a picture of my problems Here is a picture of my problems

Can somebody tell what I need to do so the image is fix but not stretched?

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You probably shouldn't repeat the texture vertically \$\endgroup\$
    – Bálint
    Commented Feb 21, 2017 at 7:24
  • \$\begingroup\$ their are 3 options, mirror, clamp and tile and none of them works. I also try not passing anything vertically but it's the same thing. :-l \$\endgroup\$
    – realNewbie
    Commented Feb 22, 2017 at 4:14

0

You must log in to answer this question.

Browse other questions tagged .