簡體   English   中英

如何在iOS中檢查下載的圖像是縱向還是橫向?

[英]How to check whether the downloaded image is Portrait or Landscape in ios?

在我的項目中,我必須使用從URL獲取的圖像填充UITableViewCell 很好,我將URL轉換為Image,但是出現了問題,如何檢查下載的圖像是Portrait還是Landscape?

只需檢查UIImage此屬性

    image.imageOrientation

更多詳細信息,請閱讀此文檔

只需檢查其大小即可:

UIImage* myImage = ...;
if (myImage.size.width > myImage.size.height)
{
    //landscape
}
else
{
    //portrait
}

請按照以下步驟操作:

  1. 下載完整的圖像。
  2. 動態獲取寬度和高度。
  3. 現在找到它的比例

如果(寬度/高度> 1)

  // you can consider it as Landscape Image. 

其他

  // you can consider it as Portrait Image. 

如果您需要進一步說明,請告訴我。

通過這些條件,只需檢查圖像的寬度和高度。

UIImage* yourImg = @"imgName";

if (yourImg.size.width > yourImg.size.height)
{
  //yourImg is Landscape
}
else
{
  //yourImg is Portrait
}

暫無
暫無

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

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