repeate tile image with paths in android

69 Views Asked by At

I want to create frame Like this image using path I want to use a Bitmap that Tile on the Horizontal only, is there any way to do it, so that it will expand only on X like repeat x on CSS. I using the following code but the bitmap tile Horizontal and vertical. First I created four paint objects for drawPath(). Then I created four path object to draw rectangular frame and I want to repeat image with path.

Paint wallpaint = new Paint();
Shader mShader1 = new BitmapShader(rotated_bitmap_180, 
                                 Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
wallpaint.setShader(mShader1);

Paint wallpaint1 = new Paint();
mShader1 = new BitmapShader(rotated_bitmap_bottom, 
                                     Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
wallpaint1.setShader(mShader1);


Paint wallpaint3 = new Paint();
mShader1 = new BitmapShader(rotated_bitmap_90, Shader.TileMode.REPEAT, 
                                        Shader.TileMode.REPEAT);
wallpaint3.setShader(mShader1);
wallpaint3.setStrokeWidth((int) frameWidth);


Paint wallpaint2 = new Paint();
mShader1 = new BitmapShader(rotated_bitmap_270, Shader.TileMode.REPEAT, 
                                          Shader.TileMode.REPEAT);
wallpaint2.setShader(mShader1);


Path wallpath1 = new Path();
wallpath1.moveTo(0, 0);
wallpath1.lineTo((float) frame_area_width, 0); // used for first point
wallpath1.lineTo((float) (frame_area_width - (frameWidth * ppi)), (float) 
                                     (frameWidth * ppi));
wallpath1.lineTo((float) (frameWidth * ppi), (float) (frameWidth*ppi));
wallpath1.close();

Path wallpath2 = new Path();
wallpath2.moveTo(0, (float) frame_area_height);
wallpath2.lineTo((float) (frameWidth * ppi), (float) (frame_area_height - 
                              (frameWidth * ppi))); // used for first point
wallpath2.lineTo((float) (frame_area_width - (frameWidth * ppi)), (float) 
                               (frame_area_height - (frameWidth * ppi)));
wallpath2.lineTo((float) frame_area_width, (float) frame_area_height);
wallpath2.close();

Path wallpath3 = new Path();
wallpath3.moveTo(0, 0);
wallpath3.lineTo((float) (frameWidth * ppi), (float) (frameWidth * ppi)); 
wallpath3.lineTo((float) (frameWidth * ppi), (float) (frame_area_height - 
                             (frameWidth * ppi)));
wallpath3.lineTo(0, (float) frame_area_height);
wallpath3.close();

Path wallpath4 = new Path();
wallpath4.moveTo((float) (frame_area_width - (frameWidth * ppi)), (float) 
                                       (frameWidth * ppi));
wallpath4.lineTo((float) frame_area_width, 0); // used for first point
wallpath4.lineTo((float) frame_area_width, (float) frame_area_height);
wallpath4.lineTo((float) (frame_area_width - (frameWidth * ppi)), (float) 
                              (frame_area_height - (frameWidth * ppi)));
wallpath4.close();

canvas.drawPath(wallpath1, wallpaint);
canvas.drawPath(wallpath2, wallpaint1);
canvas.drawPath(wallpath3, wallpaint2);
canvas.drawPath(wallpath4, wallpaint3);
0

There are 0 best solutions below