• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Apply Landscape To Portrait Transform To Objects Drawn on Page In Incorrect Orientation

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am in the process of maintaining a legacy application built in Java and am encountering an issue with objects drawn on the page as if they were drawn on a landscape page as opposed to portrait page.  The page in question is drawn as a buffered image in the portrait orientation and most of the graphics to be drawn on the page are drawn as Java polygons and lines in the correct portrait orientation, these objects come from one database, and are drawn correctly.  However the objects which come from the second database are drawn as if the page were in landscape orientation, which is subsequently incorrect, these objects are polygons created as Java paths from coordinates and then an area object is created from them and drawn.  

I have tried creating a rotation transform for both 90 degrees and 270 degrees, converted to radians, and in both instances the objects in question are drawn off the page when rotated.  The page occupies the positive x and negative y quadrant of a xy axis.  

As an experiment I rotated the page in question back to landscape and the misaligned objects were now aligned correctly, with all the other objects. I continued down this path and rotated the page back to portrait orientation after the objects in question were drawn and they then rotated back to the portrait position and everything appeared correct, but when attempting to zoom in, the objects were not draw at all.  

Is there some way I could create and apply a landscape to portrait transform to the areas of the objects in question for the given bounds of the page, and then have them move to the right position instead of having to rotate the page to match their orientation, I suspect that this way would also solve the zoom issue as well?  

The page must be in the portrait orientation as a second page needs to be drawn next to it, in landscape orientation there is no space.

Thanks in advance

Kind regards

Vaughan
 
Saloon Keeper
Posts: 4346
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Vaughan,

welcome to the Ranch and enjoy the stay!

When you talk about rotation, how come you did not see simply a rotated image, with all figures also rotated?

Anyway, two quick solutions come to mind, both far from ideal. First, you could give a BufferedImage an AffineTransform, that translates landscape coordinates to portrait coordinates. Problem is that some figures will be squized or stetched a bit. Other possibility: draw a scaled landscape BI on a Portrait BI, so that the original BI will be reduced in size, but not deformed.
 
Vaughan Beckwith
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Piet,

Thanks for your response.  Unfortunately the when the data is loaded for the page it instructs the application to rotate the page to the landscape orientation and then draw the objects.  The problem objects  are unfortunately drawn in the portrait format.  I would like to change as little as possible as the application has a number of caveats.

I'll try what you mention.

Kind regards

Vaughan
 
Marshal
Posts: 72406
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch again.
Beware of affine transforms; they can sometimes not reverse themselves. If you have that problem, try taking a copy of the Graphics object.I have had such problems myself, but only with shear(...).
 
Piet Souris
Saloon Keeper
Posts: 4346
163
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:I have had such problems myself, but only with shear(...).


You really have to do your best to get a non-invertible shear!
 
Campbell Ritchie
Marshal
Posts: 72406
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That cuts both ways; you can cut things with the shears, one way with one blade and the other way with the other blade, and then you can't join them back together.
 
Vaughan Beckwith
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

A thanks to everyone for their help.  I was able to solve the issue by swapping the x and y values given from the one original application for the Java application, this put the object into portrait from landscape.  So in other words x from the initial application became y for the Java application and y from the original application became x for the Java application.

Thanks

Vaughan
 
Piet Souris
Saloon Keeper
Posts: 4346
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that is certainly a valid solution, although your polygons will also be mirrored. Can you show us the code you used to mirror your landscape to portrait?
 
Campbell Ritchie
Marshal
Posts: 72406
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can take a copy of the Graphics object with its create() method and apply any transforms to that copy only.
 
Piet Souris
Saloon Keeper
Posts: 4346
163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That would not be sufficient: you need two BufferedImages, source (W x H) and target (H x W). Now, you could copy every pixel (x, y) from source to pixel (y, x) from target, and I get the impression that that is what OP did. Nothing wrong with it.

The method I had in mind, was indeed using some AffineTransform. You can get one that transposes source to target by this:

and I was just curious if OP did anything like this.
 
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic