• Post Reply Bookmark Topic Watch Topic
  • New Topic

JPEG changes size when it should not  RSS feed

 
Ranch Hand
Posts: 113
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The object of the code is to display jpegs on a label of a given size from two different sources which are of different sizes
so starting with the code that calls the size manipulation

note there are two lines of code one of which is commented out  marked with <<<<<<<<<<<<<<< so you can see what i am getting at now when this works correctly the will only be one line as the size will be determined by passing 1 or 3 to getScaledImage now moving to getScaledImage code


I have added the system.out.println statements so i can see what happens inside this code

info printed out  no resizing
factor= 1
width2= 120
height2= 120
info printed out resizing to 1 so image should be the same size but it is reduced in size
factor= 1
width2= 120
height2= 120
note the values inside getScaledImage are identical so why does it make the jpeg smaller?

what i can not figure out is why the image is not the same size and yet the values determining the size are
 
Master Rancher
Posts: 2223
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a pity you did not show the complete code. Now we can't run and test it.

First question: why don't you simply use the method 'getScaledInstance' of the Image class?

Then, if I look at your getScaledImage method"

you are creating an image with newWidth and newHeight equal to: size w / 3 * 2, newWidth * 5 / 4 (watch out for integer division!), so the new sizes are different from the original. Where does the size of the Label come into play?
 
peter m hayward
Ranch Hand
Posts: 113
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your reply, the only thing missing are the jpegs loaded into the array "anArrayOfUrls" which gets the from external source or the C drive, the label size is fixed ase its on gui with lots of other control. I fail to understand how this is happening given that the parameter are identical




Piet Souris wrote:It is a pity you did not show the complete code. Now we can't run and test it.

First question: why don't you simply use the method 'getScaledInstance' of the Image class?

Then, if I look at your getScaledImage method"

you are creating an image with newWidth and newHeight equal to: size w / 3 * 2, newWidth * 5 / 4 (watch out for integer division!), so the new sizes are different from the original. Where does the size of the Label come into play?

 
Piet Souris
Master Rancher
Posts: 2223
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... I still fail to see what the problem is, to be frank.

You invoke 'getScaledImage' with arguments image1, its width and height, and a scale factor of 1:

If I look at what gets printed in 'getScaledImage', width and height of the original are 120, factor = 1, so it returns a scaled image with size 120 / 3 * 2 = 80 and 80 * 5 / 4 = 100. Add a prinln with these values to the code, so you can see the format of the returned image. Next, you set this returned value as the icon of the label. So, if you look at these two lines:

The first, outcommented, line puts the scaled image to the icon (80 * 100), the second line puts the original image (120 * 120).
The labelbounds get adjusted to the size of the icon. If you want this label to retain its original size, then you should scale to the bounds of that label (perhaps taking the aspect ratio into account as well).

In case I still misunderstood the problem, can you explain what happens in the 'getScaledImage', and how you think you took care of that fixed label size?
 
peter m hayward
Ranch Hand
Posts: 113
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for trying to help i may have spotted  my error having read your reply if not i shall post a more detailed account

Piet Souris wrote:Hmmm... I still fail to see what the problem is, to be frank.

You invoke 'getScaledImage' with arguments image1, its width and height, and a scale factor of 1:

If I look at what gets printed in 'getScaledImage', width and height of the original are 120, factor = 1, so it returns a scaled image with size 120 / 3 * 2 = 80 and 80 * 5 / 4 = 100. Add a prinln with these values to the code, so you can see the format of the returned image. Next, you set this returned value as the icon of the label. So, if you look at these two lines:

The first, outcommented, line puts the scaled image to the icon (80 * 100), the second line puts the original image (120 * 120).
The labelbounds get adjusted to the size of the icon. If you want this label to retain its original size, then you should scale to the bounds of that label (perhaps taking the aspect ratio into account as well).

In case I still misunderstood the problem, can you explain what happens in the 'getScaledImage', and how you think you took care of that fixed label size?

 
peter m hayward
Ranch Hand
Posts: 113
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all the tried to help with this problem that turned out to be a rookie mistake it was never adjusting the size because i set to permanently  1 instead of what ever size was need


peter m hayward wrote:thanks for trying to help i may have spotted  my error having read your reply if not i shall post a more detailed account

Piet Souris wrote:Hmmm... I still fail to see what the problem is, to be frank.

You invoke 'getScaledImage' with arguments image1, its width and height, and a scale factor of 1:

If I look at what gets printed in 'getScaledImage', width and height of the original are 120, factor = 1, so it returns a scaled image with size 120 / 3 * 2 = 80 and 80 * 5 / 4 = 100. Add a prinln with these values to the code, so you can see the format of the returned image. Next, you set this returned value as the icon of the label. So, if you look at these two lines:

The first, outcommented, line puts the scaled image to the icon (80 * 100), the second line puts the original image (120 * 120).
The labelbounds get adjusted to the size of the icon. If you want this label to retain its original size, then you should scale to the bounds of that label (perhaps taking the aspect ratio into account as well).

In case I still misunderstood the problem, can you explain what happens in the 'getScaledImage', and how you think you took care of that fixed label size?

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!