Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi members,

I have a colour gradient image that is set to fit nicely on a chart range from 0 - 120. However my problem now is that my chart range can change dynamically according to the charts that is populated.

My question is how can I dynamically crop my image in asp.net C# to crop the image nicely to the chart?


Currently the default colour gradient image that fits nicely for range 0 - 120:
http://i.stack.imgur.com/Xlh8N.png[^]

However lets take a look at the problem which the image is static and does not adjust accordingly to the chart range:
http://i.stack.imgur.com/1aVPc.png[^]

Thus I would like to do in this approach:

1. get the max value of the chart

2. e.g. if value = 60, the % = 60/120 = 50%

3. dynamically crop 50% from the top and stretch it to 100% to fit the Y Axis height

which I would like the results to be:
http://i.stack.imgur.com/p8Bmt.png[^]
OR if there is any other approach to create gradient colour image like these dynamically do suggest too! thanks a lot.
Posted
Comments
Sergey Alexandrovich Kryukov 17-Nov-15 0:22am    
What have you tried so far?
—SA
waynetan123 17-Nov-15 4:24am    
bitmap but doesn't work. first time doing cropping thus not much experience thanks
Sergey Alexandrovich Kryukov 17-Nov-15 10:11am    
If you don't want to answer, don't. :-)
—SA

1 solution

This one is fourth result on google here from CP: Cropping Images[^]

It crops by mouse drawn rectangle, but you can adapt it to use your dynamic range.
 
Share this answer
 
Comments
waynetan123 17-Nov-15 19:25pm    
I need it to crop automatically upon page load. thanks
Sinisa Hajnal 18-Nov-15 3:24am    
But at page load you can get all needed parameters, right? You know how wide/high the image should be. So crop based on that instead of mouse rectangle. Use cropping code from the example, just use your own rectangle.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900