Changeset 6814 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2014-02-05T23:22:04+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r6809 r6814 22 22 import java.io.StringReader; 23 23 import java.io.UnsupportedEncodingException; 24 import java.net.MalformedURLException;25 24 import java.net.URI; 26 25 import java.net.URL; … … 360 359 361 360 /** 362 * @see #get(java.lang.String, java.lang.String) 361 * @param name The icon name (base name with or without '.png' or '.svg' extension) 362 * @return the requested image or null if the request failed 363 * @see #get(String, String) 363 364 */ 364 365 public static ImageIcon get(String name) { … … 369 370 * Load an image with a given file name, but do not throw an exception 370 371 * when the image cannot be found. 371 * @see #get(java.lang.String, java.lang.String) 372 * 373 * @param subdir subdirectory the image lies in 374 * @param name The icon name (base name with or without '.png' or '.svg' extension) 375 * @return the requested image or null if the request failed 376 * @see #get(String, String) 372 377 */ 373 378 public static ImageIcon getIfAvailable(String subdir, String name) { … … 376 381 377 382 /** 378 * @see #getIfAvailable(java.lang.String, java.lang.String) 383 * @param name The icon name (base name with or without '.png' or '.svg' extension) 384 * @return the requested image or null if the request failed 385 * @see #getIfAvailable(String, String) 379 386 */ 380 387 public static ImageIcon getIfAvailable(String name) { … … 854 861 * @param img the image to be rotated. 855 862 * @param rotatedAngle the rotated angle, in degree, clockwise. It could be any double but we 856 * will mod it with 360 before using it. More over for caching performance, it will be rounded to 863 * will mod it with 360 before using it. More over for caching performance, it will be rounded to 857 864 * an entire value between 0 and 360. 858 865 * … … 863 870 return createRotatedImage(img, rotatedAngle, ImageResource.DEFAULT_DIMENSION); 864 871 } 865 872 866 873 /** 867 874 * Creates a rotated version of the input image, scaled to the given dimension. … … 869 876 * @param img the image to be rotated. 870 877 * @param rotatedAngle the rotated angle, in degree, clockwise. It could be any double but we 871 * will mod it with 360 before using it. More over for caching performance, it will be rounded to 878 * will mod it with 360 before using it. More over for caching performance, it will be rounded to 872 879 * an entire value between 0 and 360. 873 880 * @param dimension The requested dimensions. Use (-1,-1) for the original size … … 878 885 public static Image createRotatedImage(Image img, double rotatedAngle, Dimension dimension) { 879 886 CheckParameterUtil.ensureParameterNotNull(img, "img"); 880 887 881 888 // convert rotatedAngle to an integer value from 0 to 360 882 889 Long originalAngle = Math.round(rotatedAngle % 360); … … 884 891 originalAngle = 360L; 885 892 } 886 893 887 894 ImageResource imageResource = null; 888 895 … … 892 899 ROTATE_CACHE.put(img, cacheByAngle = new HashMap<Long, ImageResource>()); 893 900 } 894 901 895 902 imageResource = cacheByAngle.get(originalAngle); 896 903 897 904 if (imageResource == null) { 898 905 // convert originalAngle to a value from 0 to 90 … … 901 908 angle = 90.0; 902 909 } 903 910 904 911 double radian = Math.toRadians(angle); 905 912 906 913 new ImageIcon(img); // load completely 907 914 int iw = img.getWidth(null); … … 909 916 int w; 910 917 int h; 911 918 912 919 if ((originalAngle >= 0 && originalAngle <= 90) || (originalAngle > 180 && originalAngle <= 270)) { 913 920 w = (int) (iw * Math.sin(DEGREE_90 - radian) + ih * Math.sin(radian)); … … 921 928 Graphics g = image.getGraphics(); 922 929 Graphics2D g2d = (Graphics2D) g.create(); 923 930 924 931 // calculate the center of the icon. 925 932 int cx = iw / 2; 926 933 int cy = ih / 2; 927 934 928 935 // move the graphics center point to the center of the icon. 929 936 g2d.translate(w / 2, h / 2); 930 937 931 938 // rotate the graphics about the center point of the icon 932 939 g2d.rotate(Math.toRadians(originalAngle)); 933 940 934 941 g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); 935 942 g2d.drawImage(img, -cx, -cy, null); 936 943 937 944 g2d.dispose(); 938 945 new ImageIcon(image); // load completely … … 941 948 } 942 949 } 943 950 944 951 /** 945 952 * Creates a scaled down version of the input image to fit maximum dimensions. (Keeps aspect ratio) 946 953 * 947 954 * @param img the image to be scaled down. 948 * @param maxSize the maximum size in pixels (both for width and height) 955 * @param maxSize the maximum size in pixels (both for width and height) 949 956 * 950 957 * @return the image after scaling.
Note:
See TracChangeset
for help on using the changeset viewer.