-
March 21st, 2012, 04:09 PM
#1
C# Solution File - Image Stretches When I Change Color
Hi everyone.
I have a UI Design that I got coded by my software developer and
when I change the color of an image and then run under "debug"
The image stretches even though I never changed any dimentions or anything.
All I did was change the color.Any ideas what might be causing this?
-
March 21st, 2012, 04:53 PM
#2
Re: C# Solution File - Image Stretches When I Change Color
That's odd - it seems as if you changed the Font more than the color.
But how did you chaged the color? you meant the background color of a picturebox, or you redrawn the image? If the last one, you should ensure you did it correctly.
If instead it was the background color of a picturebox, I never heard of that problem, but you could give this a try, set the autoscalemode of form to "none" and try again. If the stretch do not apply anymore then something of weird is happening between colors and fonts...
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
March 21st, 2012, 05:26 PM
#3
Re: C# Solution File - Image Stretches When I Change Color
he made a .jpg a button and when i open the .jpg in photoshop and simply change the color and re-save it. and run debug to test out the UI the .jpg button image is stretched.
-
March 21st, 2012, 05:30 PM
#4
Re: C# Solution File - Image Stretches When I Change Color
seems as if photoshop changed the size of jpg too. Could you save them to disk and then see the size in bytes or the properties to see if the chaged with and height?
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
March 21st, 2012, 05:39 PM
#5
Re: C# Solution File - Image Stretches When I Change Color
it seems the height and width stay the same but when I change the color the size in bytes increases.
-
March 21st, 2012, 05:55 PM
#6
Re: C# Solution File - Image Stretches When I Change Color
Take a copy of the original, put a single point of color in the centre and save it as is, without changin the rest of it. Now use it as the image in your program. Is it stretched or is fine?
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
March 21st, 2012, 06:02 PM
#7
Re: C# Solution File - Image Stretches When I Change Color
yes. i put a tiny dot and the original picture jumped from 10 kilobytes to 13kilobytes and then i ran the debugger and the picture enlarged.
Do you think it has something to do with the size of the file?
-
March 21st, 2012, 06:29 PM
#8
Re: C# Solution File - Image Stretches When I Change Color
When you say that the image "stretched" - do you mean that it rescaled proportionately (became bigger or smaller)?
The problem is probably related to image DPI resolution - the Graphics class uses this value to rescale the image for the final display with respect to the selected values for PageScale and PageUnit properties.
You can do something like this in code:
Code:
float oldDpiX = bmp.HorizontalResolution;
float oldDpiY = bmp.VerticalResolution;
bmp.SetResolution(g.DpiX, g.DpiY);
g.DrawImage(bmp, buttonLoc.X, buttonLoc.Y); // EDIT: g is a Graphics instance
// sometime later...
bmp.SetResolution(oldDpiX, oldDpiY);
Or you can adjust the resolution in Photoshop, to match the one of the original file.
Go to Image menu > Image Size... and set the Resolution field, then save. (You can check the resolution of the original image the same way.)
P.S. Make sure it says "pixels/inch" in the dropdown menu.
-
March 21st, 2012, 06:45 PM
#9
Re: C# Solution File - Image Stretches When I Change Color
Just done a little experiment; this should also do the trick, in a neater way, if you're up for some code editing:
g.DrawImage(bmp, targetRectangle, srcRectangle, GraphicsUnit.Pixel);
The Graphics class uses pixels as PageUnit on displays, but uses "points" (1/72 in) when sampling images by default. The method overload used above allows you to specify that pixels should be used instead.
-
March 22nd, 2012, 12:17 AM
#10
Re: C# Solution File - Image Stretches When I Change Color
by the way: what I think is photoshop is changing the image enought to make it not suitable for your software. You could see if you have some options under the SaveAs of photoshop - like preserving quality or even changing the type form jpg to Png.
This last format should be better changeable than jpg
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|