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

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

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

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

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

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))
# 對新生成的圖像進(jìn)行旋轉(zhuǎn)至45度
image_1 =pygame.transform.rotate(image_new,45)
# 使用rotozoom() 旋轉(zhuǎn) 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)  #圖像進(jìn)行水平和垂直翻轉(zhuǎn)
#參數(shù)1:要翻轉(zhuǎn)的圖像
#參數(shù)2:水平是否翻轉(zhuǎn)
#參數(shù)3:垂直是否翻轉(zhuǎn)
#返回一個新圖像

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)  #旋轉(zhuǎn)圖像
#參數(shù)2:要旋轉(zhuǎn)的角度--正數(shù)表示逆時針--負(fù)數(shù)表示順時針
#除非以90度的增量旋轉(zhuǎn),否則圖像將被填充得更大的尺寸。 如果圖像具有像素alpha,則填充區(qū)域?qū)⑹峭该鞯?
#旋轉(zhuǎn)是圍繞中心
img1 = pygame.transform.rotozoom(img, 30.0, 2.0)  #縮放+旋轉(zhuǎn)
#第一個參數(shù)指定要處理的圖像,第二個參數(shù)指定旋轉(zhuǎn)的角度數(shù),第三個參數(shù)指定縮放的比例
#這個函數(shù)會對圖像進(jìn)行濾波處理,圖像效果會更好,但是速度會慢很多
img1 = pygame.transform.chop(img, (0, 0, 100, 50))  #對圖像進(jìn)行裁減
#第一個參數(shù)指定要裁減的圖像,第二個參數(shù)指定要保留的圖像的區(qū)域
img = pygame.image.load('馬.jpg')
img1 = pygame.transform.laplacian(img)  #查找邊--輪廓

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

您可能感興趣的文章:

相關(guān)文章

最新評論

贡觉县| 横峰县| 孝昌县| 北辰区| 宁远县| 乌恰县| 泰宁县| 桂东县| 巫溪县| 江陵县| 新泰市| 常熟市| 嫩江县| 来安县| 临海市| 辽中县| 博野县| 黑河市| 商南县| 石泉县| 宝坻区| 都江堰市| 琼海市| 莱芜市| 黄浦区| 航空| 古蔺县| 广饶县| 拜泉县| 韩城市| 阳东县| 唐山市| 泰安市| 仁寿县| 凉城县| 仙桃市| 玉树县| 金溪县| 湟源县| 卢湾区| 灵川县|