8

I have an 8x8 Image. (bitmap - can be changed)

What I want to do is be able to draw a shape, given a Path and Paint object onto my SurfaceView.

At the moment all I can do is fill the shape with solid colour. How can I draw it with a pattern.

Example

In the image you can see the brush pattern (The cross). It can be anything from a cross to a donut or an elf.

How would I go about drawing this pattern background.

I also eventually want to apply colours to it.

So far, my theory is to create a clip area of the shape, and tile the bitmaps until area is covered, but this is extreme overkill in processing. Nor sound ideal.

In terms of colouring, I can edit the brushes to be alpha, fill the same with background colour, then draw the images on top. The real issue it the tiling of such patterns.

Ive found a few questions of a similar nature, all unanswered, and/or not applicable to my situation. (use of xmls on views etc)

IAmGroot
  • 13,760
  • 18
  • 84
  • 154

1 Answers1

20

Did you checked this blog. Its using BitmapShader

Example:

    //Initialize the bitmap object by loading an image from the resources folder  
    fillBMP = BitmapFactory.decodeResource(m_context.getResources(), R.drawable.cross);  
    //Initialize the BitmapShader with the Bitmap object and set the texture tile mode  
    fillBMPshader = new BitmapShader(fillBMP, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);  

    fillPaint.setStyle(Paint.Style.FILL);  
    //Assign the 'fillBMPshader' to this paint  
    fillPaint.setShader(fillBMPshader);  

    //Draw the fill of any shape you want, using the paint object.
    canvas.drawCircle(posX, posY, 100, fillPaint);
IAmGroot
  • 13,760
  • 18
  • 84
  • 154
Sandeep Manne
  • 6,030
  • 5
  • 39
  • 55
  • 1
    Any suggestion regarding the performance issue? Since you are rapidly drawing bitmaps on the canvas this will lead to a heavy UI. Causing very slow performance. – Prokash Sarkar Aug 27 '16 at 13:36