python pil thay đổi dpi mà không cần lưu tệp
nhìn vào mã. ^^
..
#tải hình ảnh
tif_path = '. /input_img. tif'
#mở hình ảnh
pil_image = Hình ảnh. mở [ tif_path ]
#thay đổi dpi trong bộ nhớ
temp_mem_file = BytesIO []
trang . lưu[ temp_mem_file , định dạng = 'png', dpi=[100,100]]
#lưu nó vào pil
temp_mem_file . tìm kiếm [ 0 ]
pil_image = Hình ảnh. mở [ temp_mem_file ]
#làm điều gì đó
#
#lưu tập tin
pil_image . lưu [ '. /đầu ra. png' ]
#www. marearts. com
#học. marearts. com
..
Cảm ơn bạn
작성자. con ngựa cái 시간. Ngày 21 tháng 9 năm 2021
Gửi email nàyBlogThis. Chia sẻ lên TwitterChia sẻ lên FacebookChia sẻ lên Pinterest
라벨. BytesIO, thay đổi dpi, dpi, PIL, Tổng cộng
def set_dpi_xy_byte[self, dpi_x, dpi_y]: """ Set the DPI on the mouse, Takes in 4 bytes big-endian and converts it to bytes :param dpi_x: X DPI :type dpi_x: int :param dpi_y: Y DPI :type dpi_x: int """ self.logger.debug["DBus call set_dpi_both"] driver_path = self.get_driver_path['dpi'] if dpi_x > 6750: dpi_x = 6750 elif dpi_x < 100: dpi_x = 100 if dpi_y > 6750: dpi_y = 6750 elif dpi_y < 100: dpi_y = 100 dpi_x_scaled = int[round[dpi_x / 6750 * 255, 2]] dpi_y_scaled = int[round[dpi_y / 6750 * 255, 2]] if self._testing: with open[driver_path, 'w'] as driver_file: driver_file.write["{}:{}".format[dpi_x_scaled, dpi_y_scaled]] return dpi_bytes = struct.pack['>BB', dpi_x_scaled, dpi_y_scaled] with open[driver_path, 'wb'] as driver_file: driver_file.write[dpi_bytes]
Matplotlib là một thư viện trong Python và nó là phần mở rộng số – toán học cho thư viện NumPy. Mô-đun hình cung cấp Nghệ sĩ cấp cao nhất, Hình, chứa tất cả các thành phần cốt truyện. Mô-đun này được sử dụng để kiểm soát khoảng cách mặc định của các ô con và vùng chứa cấp cao nhất cho tất cả các thành phần cốt truyện
matplotlib. nhân vật. Nhân vật. phương pháp dpi
Phương pháp dpi của mô-đun hình của thư viện matplotlib là độ phân giải tính bằng số chấm trên mỗi inch
cú pháp. quả sung. dpi
Thông số. Phương pháp này không chấp nhận bất kỳ tham số nào
trả lại. Phương pháp này trả về độ phân giải theo số chấm trên mỗi inch
Các ví dụ dưới đây minh họa matplotlib. nhân vật. Nhân vật. chức năng dpi trong matplotlib. nhân vật
ví dụ 1
# Implementation of matplotlib function
import
matplotlib.pyplot as plt
import
numpy as np
fig
=
# Implementation of matplotlib function
0
import
1=
import
3import
4import
5 import
6
import
7__=
import
3____30import
5 import
6
matplotlib.pyplot as plt
4=
matplotlib.pyplot as plt
6
matplotlib.pyplot as plt
7
matplotlib.pyplot as plt
9
import
0____9____22import
3
import
5
đầu ra
ví dụ 2
import
6
import
matplotlib.pyplot as plt
import
9 numpy as np
0import
numpy as np
2
import
numpy as np
numpy as np
6=
numpy as np
8
numpy as np
9=
1
3=
5
6_______9
8____69
0
1 import
5
3
5=
3______25
9
fig
0=
3______25 fig
4
fig
6=
fig
8
=
0=
=
2____93=
4
=
6______9 =
8
1=
4
# Implementation of matplotlib function
02=
# Implementation of matplotlib function
04
# Implementation of matplotlib function
05# Implementation of matplotlib function
06 # Implementation of matplotlib function
07# Implementation of matplotlib function
08 # Implementation of matplotlib function
09import
00import
01import
02import
03
import
05=
import
07
import
09=
import
11
import
12import
13import
14=
import
16import
17import
18import
5 import
20import
21=
import
23