簡體   English   中英

Android:如何更改圖像的方向以在imageview中設置它?

[英]Android: How to change the orientation of an image to set it in imageview?

我正在將圖像設置為ImageView,但是未從設備存儲中選擇圖像,而是由服務器發送了圖像,我想在將圖像設置為imageview之前了解圖像的方向。 因此,是否可以使用其URL和ExifInterface檢查來自服務器的jpg圖像的方向,然后根據設置為imageview的要求更改其方向?

無法確定方向。 您將必須檢查寬度和高度,並根據ImageView對齊圖像。

也許這可以幫助您

void readAndDisplayMetadata( String fileName ) {
    try {

        File file = new File( fileName );
        ImageInputStream iis = ImageIO.createImageInputStream(file);
        Iterator<ImageReader> readers = ImageIO.getImageReaders(iis);

        if (readers.hasNext()) {

            // pick the first available ImageReader
            ImageReader reader = readers.next();

            // attach source to the reader
            reader.setInput(iis, true);

            // read metadata of first image
            IIOMetadata metadata = reader.getImageMetadata(0);

            String[] names = metadata.getMetadataFormatNames();
            int length = names.length;
            for (int i = 0; i < length; i++) {
                System.out.println( "Format name: " + names[ i ] );
                displayMetadata(metadata.getAsTree(names[i]));
            }
        }
    }
    catch (Exception e) {

        e.printStackTrace();
    }
}

http://johnbokma.com/java/obtaining-image-metadata.html

注意:如果並且僅當圖像高度大於寬度時,才能確定圖像是縱向的,因此可以對其進行測量以找到其方向。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM