<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # Python 程序:查找圖像的大小(分辨率) > 原文: [https://www.programiz.com/python-programming/examples/resolution-image](https://www.programiz.com/python-programming/examples/resolution-image) #### 在此示例中,您將學習如何找到 jpeg 圖像的分辨率,而無需使用外部庫 要理解此示例,您應該了解以下 [Python 編程](/python-programming "Python tutorial")主題: * [Python 函數](/python-programming/function) * [Python 用戶定義函數](/python-programming/user-defined-function) * [Python 文件 I/O](/python-programming/file-operation) * * * JPEG(發音為“jay-peg”)代表聯合圖像專家組。 它是用于圖像壓縮的最廣泛使用的壓縮技術之一。 大多數文件格式都有標頭(頭幾個字節),這些標頭包含有關文件的有用信息。 例如,jpeg 標頭包含高度,寬度,顏色數(灰度或 RGB)等信息。在此程序中,我們無需使用任何外部庫即可找到讀取這些標頭的 jpeg 圖像的分辨率。 ## 查找 JPEG 圖像分辨率的源代碼 ```py def jpeg_res(filename): """"This function prints the resolution of the jpeg image file passed into it""" # open image for reading in binary mode with open(filename,'rb') as img_file: # height of image (in 2 bytes) is at 164th position img_file.seek(163) # read the 2 bytes a = img_file.read(2) # calculate height height = (a[0] << 8) + a[1] # next 2 bytes is width a = img_file.read(2) # calculate width width = (a[0] << 8) + a[1] print("The resolution of the image is",width,"x",height) jpeg_res("img1.jpg") ``` **輸出** ```py The resolution of the image is 280 x 280 ``` 在此程序中,我們以二進制模式打開了圖像。 非文本文件必須在此模式下打開。 圖像的高度在第 164 位,然后是圖像的寬度。 兩者均為 2 個字節長。 請注意,這僅適用于 JPEG 文件交換格式(JFIF)標準。 如果您的圖像是使用其他標準(例如 EXIF)編碼的,則該代碼將無法正常工作。 我們使用按位移位運算符`<<`將 2 個字節轉換為數字。 最后,顯示分辨率。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看