Soley
Soley

Reputation: 1776

Apply AffineTransform to TexturePaint

I would like to know how can I rotate a texture paint with image in java.

Normally it is easy to rotate the Graphics2D g2 object, but I don't want to do that. I also don't want to rotate my shape and do some crazy rotation scales, etc. It will be easy to normally do the drawing and fills with paint while paint itself is scaled, rotated, etc.

I also don't want to create a rotated image and then texturepaint it.

There is a createContext inside the texturepaint class but I don't know how can I use it to rotate the original image.

I hope you understand what I mean by rotating the texture itself nwo :) ?

Thank you.

Edit: I was playing with Java custom Paint implementation performance issue but there is an issue I cannot handle. When there is an offset to where tiling will be started, it does not start correctly.

Sorry for mixing up the problem.

Upvotes: 0

Views: 290

Answers (1)

Soley
Soley

Reputation: 1776

I decided to create a second shape before transform the canvas, and then rotate it back to match the inverse of the trnsform.

This solved my problem.

try {
    this.shape = new Path2D.Double(bx.createInverse().createTransformedShape(shape));
} catch (NoninvertibleTransformException ex) {
}

Upvotes: 1

Related Questions