I am trying to build some sort of messenger service but I am having issues with the rendering of a text bubble. I started by splitting a bubble into 9 images, The four corner would be static. Where I have an issue is the NORTH, SOUTH, EAST and WEST images.
I would like them to repeat themselves similar to the CSS option repeat. Basically, adapting the bubble to the content.
I looked around but a lot are Android or IOS solutions. Is there a repeat functionality in Java and can do this without re-sizing the image inside the paintComponent which causes the image to be distorted.
Here is what I got for the moment when I try to generate a bubble:
Any ideas are welcome!
One can scale the images with Graphics.drawImage(x, y, w, h, null). For north and south scale the width of a an image of 1 pixel width, and similar for east and west.
To add on to @Joop Eggen's answer, you basically need to scale your north and south images to be the necessary width and your east and west images to be the necessary height.
It would look something like below. You would have 8 or 9 images, depending on whether you had a center image. You would scale the north and south to width of
innerWidth = outerWidth - 2 * borderWidth
; your east and west would be scaled vertically to a height ofinnerHeight = outerHeight - 2 * borderHeight
.You have (at least) two options available to you. You can tile the image elements as required or you can scale them to fit.
While I have no doubt scaling will work, how good it looks will depend on how good the source image is and may produce undesirable artifacts as the image is scaled.
Alternatively, you could tile the images to fill the available space. Based on the size and complexity of the image and the area being tilted, this may take some time to renderer.
Obviously the time to tile/scale and image can mitigated by buffering the result and only re-generating the output when it changes.
The final solution will come down to exactly what it is you hope to achieve.
The following is a tiled exampled