This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
I have an instance of a Buffered Image object, myImg, and need to change its dimensions. For example, if the dimensions are 200 wide and 100 high, I need to change it to 100 wide by 200 high.
I know about drawImage(sourceImg, 0, 0, newWidth, newHeight, null) but this just adjusts the width and height of the sourceImg that will be added to myImg (the dimensions of myImg will remain 200x100).
My application is a method to rotate an image by 90deg, which is initially contained in myImg. After rotating the image, I want it to end up back in myImg with the new dimensions of myImg as 100x200.
Performing the rotation is not the issue here. The issue is resizing myImg so that its dimensions will match those of the rotated image.
In my current implementation, the image is rotated correctly and is added to myImg, but what appears in myImg is just the first 100x100 pixels of the rotated image. To the right of the rotated image, I have the remnants of what was in myImage before the rotation, and the bottom half of the rotated image is clipped off because the dimensions of myImg has remained 200x100 instead of the necessary 100x200.
Here is the code for my rotation method. I pass the image that I wish to rotate (wkgImg) to the method through the bi argument. wkgImg is declared to be global, so the final result of the rotation ends up as bi and hence wkgImg. It all works except that bi (wkgImg) is not being resized to accommodate the dimensions of the rotated image. The original dimensions of wkgImg are retained.
Bob Sale wrote:I think that when the new instance of bi is created, it is not associated with the argument bi -- is this possible?
This doesn't make any sense to me. What do you mean by "the new instance of bi"? And what do you mean by "associated with the argument bi"?
However I do think that you should return the rotated image as the result of the method instead of declaring it to return nothing. Otherwise you're trying to modify the image which is referred to by the "bi" parameter, which your code doesn't do. Your code creates a new image.