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)

1 Answer 1

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);
1
  • 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. Aug 27, 2016 at 13:36

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.