最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Pygame Transform圖像變形的實現(xiàn)示例

 更新時間:2021年11月17日 15:13:08   作者:天子驕龍  
pygame.transform 模塊允許您對加載、創(chuàng)建后的圖像進行一系列操作,比如調整圖像大小、旋轉圖片等操作,感興趣的可以了解一下

pygame.transform 模塊允許您對加載、創(chuàng)建后的圖像進行一系列操作,比如調整圖像大小、旋轉圖片等操作,常用方法如下所示:

下面看一組簡單的演示示例:

import pygame
#引入pygame中所有常量,比如 QUIT
from pygame.locals import *
pygame.init()
screen = pygame.display.set_mode((500,250))
pygame.display.set_caption('c語言中文網(wǎng)')
#加載一張圖片(455*191)
image_surface = pygame.image.load("C:/Users/Administrator/Desktop/c-net.png").convert()
image_new = pygame.transform.scale(image_surface,(300,300))
# 查看新生成的圖片的對象類型
#print(type(image_new))
# 對新生成的圖像進行旋轉至45度
image_1 =pygame.transform.rotate(image_new,45)
# 使用rotozoom() 旋轉 0 度,將圖像縮小0.5倍
image_2 = pygame.transform.rotozoom(image_1,0,0.5)
while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()
    # 將最后生成的image_2添加到顯示屏幕上
    screen.blit(image_2,(0,0))
    pygame.display.update()

實現(xiàn)示例

import pygame

pygame.init()
screen = pygame.display.set_mode((960, 600))
pygame.display.set_caption("圖像變換")
img = pygame.image.load('馬.jpg')
clock = pygame.time.Clock()

img1=pygame.transform.flip(img,False, True)  #圖像進行水平和垂直翻轉
#參數(shù)1:要翻轉的圖像
#參數(shù)2:水平是否翻轉
#參數(shù)3:垂直是否翻轉
#返回一個新圖像

while True:
    t = clock.tick(60)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
    screen.blit(img1,(100,50))
    pygame.display.update()
img1 = pygame.transform.scale(img, (200, 100))  #縮放
#參數(shù)2:新圖像的寬高
img1 = pygame.transform.smoothscale(img,(400,300))  #平滑縮放圖像
#此函數(shù)僅適用于24位或32位surface。 如果輸入表面位深度小于24,則拋出異常
img1 = pygame.transform.scale2x(img)  #快速的兩倍大小的放大
img = pygame.image.load('馬.jpg')
img1 = pygame.transform.rotate(img, 30)  #旋轉圖像
#參數(shù)2:要旋轉的角度--正數(shù)表示逆時針--負數(shù)表示順時針
#除非以90度的增量旋轉,否則圖像將被填充得更大的尺寸。 如果圖像具有像素alpha,則填充區(qū)域將是透明的
#旋轉是圍繞中心
img1 = pygame.transform.rotozoom(img, 30.0, 2.0)  #縮放+旋轉
#第一個參數(shù)指定要處理的圖像,第二個參數(shù)指定旋轉的角度數(shù),第三個參數(shù)指定縮放的比例
#這個函數(shù)會對圖像進行濾波處理,圖像效果會更好,但是速度會慢很多
img1 = pygame.transform.chop(img, (0, 0, 100, 50))  #對圖像進行裁減
#第一個參數(shù)指定要裁減的圖像,第二個參數(shù)指定要保留的圖像的區(qū)域
img = pygame.image.load('馬.jpg')
img1 = pygame.transform.laplacian(img)  #查找邊--輪廓

以上就是Pygame Transform圖像變形的實現(xiàn)示例的詳細內容,更多關于Pygame Transform圖像變形的資料請關注腳本之家其它相關文章!

您可能感興趣的文章:

相關文章

最新評論

绥棱县| 盐源县| 丽江市| 荥经县| 霍林郭勒市| 渝北区| 台湾省| 和顺县| 文安县| 江西省| 罗源县| 衡南县| 镇平县| 永春县| 普定县| 喀什市| 信宜市| 密山市| 华亭县| 汽车| 达尔| 富蕴县| 洛南县| 巫山县| 锡林郭勒盟| 三原县| 金溪县| 离岛区| 留坝县| 乌拉特中旗| 师宗县| 柳林县| 英山县| 那坡县| 且末县| 河北省| 永春县| 垣曲县| 寿阳县| 郓城县| 新密市|