• <nav id="wkkge"><strong id="wkkge"></strong></nav>
  • <menu id="wkkge"></menu>
  • Java8新特性
    Java9新特性

    Java9多分辨率圖像API

     

     

    Java 9 定義多分辨率圖像 API,開發者可以很容易的操作和展示不同分辨率的圖像了。

     

    以下是多分辨率圖像的主要操作方法:

     

    • Image getResolutionVariant(double destImageWidth, double destImageHeight) − 獲取特定分辨率的圖像變體-表示一張已知分辨率單位為DPI的特定尺寸大小的邏輯圖像,并且這張圖像是最佳的變體。

     

    • List getResolutionVariants() − 返回可讀的分辨率的圖像變體列表。

     

    import java.io.IOException;
    import java.net.URL;
    import java.net.MalformedURLException;
    import java.util.ArrayList;
    import java.util.List;
    import java.awt.Image;
    import java.awt.image.MultiResolutionImage;
    import java.awt.image.BaseMultiResolutionImage;
     
    import javax.imageio.ImageIO;
     
    public class Tester {
       public static void main(String[] args) throws IOException, MalformedURLException {
     
          List<String> imgUrls = List.of("http://www.povk5b.com/wp-content/themes/bjpowernode/assets/img/bjpowernode-logo@2x.png",
             "http://www.povk5b.com/wp-content/themes/bjpowernode/assets/img/bjpowernode-logo.png",
             "http://www.povk5b.com/wp-content/themes/bjpowernode/assets/images/qrcode.png");
     
          List<Image> images = new ArrayList<Image>();
     
          for (String url : imgUrls) {
             images.add(ImageIO.read(new URL(url)));
          }
     
          // 讀取所有圖片
          MultiResolutionImage multiResolutionImage = 
             new BaseMultiResolutionImage(images.toArray(new Image[0]));
     
          // 獲取圖片的所有分辨率
          List<Image> variants = multiResolutionImage.getResolutionVariants();
     
          System.out.println("Total number of images: " + variants.size());
     
          for (Image img : variants) {
             System.out.println(img);
          }
     
          // 根據不同尺寸獲取對應的圖像分辨率
          Image variant1 = multiResolutionImage.getResolutionVariant(156, 45);
          System.out.printf("\nImage for destination[%d,%d]: [%d,%d]", 
             156, 45, variant1.getWidth(null), variant1.getHeight(null));
     
          Image variant2 = multiResolutionImage.getResolutionVariant(311, 89);
          System.out.printf("\nImage for destination[%d,%d]: [%d,%d]", 311, 89, 
             variant2.getWidth(null), variant2.getHeight(null));
     
          Image variant3 = multiResolutionImage.getResolutionVariant(622, 178);
          System.out.printf("\nImage for destination[%d,%d]: [%d,%d]", 622, 178, 
             variant3.getWidth(null), variant3.getHeight(null));
     
          Image variant4 = multiResolutionImage.getResolutionVariant(300, 300);
          System.out.printf("\nImage for destination[%d,%d]: [%d,%d]", 300, 300, 
             variant4.getWidth(null), variant4.getHeight(null));
       }  
    }

     

    全部教程
  • <nav id="wkkge"><strong id="wkkge"></strong></nav>
  • <menu id="wkkge"></menu>
  • 面对面棋牌游戏