pygame.transform
pygame module to transform surfaces
pygame.transform.flip
— flip vertically and horizontally pygame.transform.scale
— resize to new resolution pygame.transform.scale_by
— resize to new resolution, using scalar(s) pygame.transform.rotate
— rotate an image pygame.transform.rotozoom
— filtered scale and rotation pygame.transform.scale2x
— specialized image doubler pygame.transform.smoothscale
— scale a surface to an arbitrary size smoothly pygame.transform.smoothscale_by
— resize to new resolution, using scalar(s) pygame.transform.get_smoothscale_backend
— return smoothscale filter version in use: 'GENERIC', 'MMX', or 'SSE' pygame.transform.set_smoothscale_backend
— set smoothscale filter version to one of: 'GENERIC', 'MMX', or 'SSE' pygame.transform.chop
— gets a copy of an image with an interior area removed pygame.transform.laplacian
— find edges in a surface pygame.transform.average_surfaces
— find the average surface from many surfaces. pygame.transform.average_color
— finds the average color of a surface pygame.transform.grayscale
— grayscale a surface pygame.transform.threshold
— finds which, and how many pixels in a surface are within a threshold of a 'search_color' or a 'search_surf'. A Surface transform is an operation that moves or resizes the pixels. All thesefunctions take a Surface to operate on and return a new Surface with theresults.
Some of the transforms are considered destructive. These means every time theyare performed they lose pixel data. Common examples of this are resizing androtating. For this reason, it is better to re-transform the original surfacethan to keep transforming an image multiple times. (For example, suppose youare animating a bouncing spring which expands and contracts. If you applied thesize changes incrementally to the previous images, you would lose detail.Instead, always begin with the original image and scale to the desired size.)
Changed in pygame 2.0.2: transform functions now support keyword arguments.
- pygame.transform.flip()¶
flip vertically and horizontally
flip(surface, flip_x, flip_y) -> Surface
This can flip a Surface either vertically, horizontally, or both.The arguments
flip_x
andflip_y
are booleans that control whetherto flip each axis. Flipping a Surface is non-destructive and returns a newSurface with the same dimensions.
- pygame.transform.scale()¶
resize to new resolution
scale(surface, size, dest_surface=None) -> Surface
Resizes the Surface to a new size, given as (width, height).This is a fast scale operation that does not sample the results.
An optional destination surface can be used, rather than have it create anew one. This is quicker if you want to repeatedly scale something. Howeverthe destination must be the same size as the size (width, height) passed in. Alsothe destination surface must be the same format.
- pygame.transform.scale_by()¶
resize to new resolution, using scalar(s)
scale_by(surface, factor, dest_surface=None) -> Surface
Experimental: feature still in development available for testing and feedback. It may change.Please leave scale_by feedback with authors
Same as scale(), but scales by some factor, rather than takingthe new size explicitly. For example,
transform.scale_by(surf, 3)
will triple the size of the surface in both dimensions. Optionally, thescale factor can be a sequence of two numbers, controlling x and y scalingseparately. For example,transform.scale_by(surf, (2, 1))
doublesthe image width but keeps the height the same.New in pygame 2.1.3.
- pygame.transform.rotate()¶
rotate an image
rotate(surface, angle) -> Surface
Unfiltered counterclockwise rotation. The angle argument represents degreesand can be any floating point value. Negative angle amounts will rotateclockwise.
Unless rotating by 90 degree increments, the image will be padded larger tohold the new size. If the image has pixel alphas, the padded area will betransparent. Otherwise pygame will pick a color that matches the Surfacecolorkey or the topleft pixel value.
- pygame.transform.rotozoom()¶
filtered scale and rotation
rotozoom(surface, angle, scale) -> Surface
This is a combined scale and rotation transform. The resulting Surface willbe a filtered 32-bit Surface. The scale argument is a floating point valuethat will be multiplied by the current resolution. The angle argument is afloating point value that represents the counterclockwise degrees to rotate.A negative rotation angle will rotate clockwise.
- pygame.transform.scale2x()¶
specialized image doubler
scale2x(surface, dest_surface=None) -> Surface
This will return a new image that is double the size of the original. Ituses the AdvanceMAME Scale2X algorithm which does a 'jaggie-less' scale ofbitmap graphics.
This really only has an effect on simple images with solid colors. Onphotographic and antialiased images it will look like a regular unfilteredscale.
An optional destination surface can be used, rather than have it create anew one. This is quicker if you want to repeatedly scale something. Howeverthe destination must be twice the size of the source surface passed in. Alsothe destination surface must be the same format.
- pygame.transform.smoothscale()¶
scale a surface to an arbitrary size smoothly
smoothscale(surface, size, dest_surface=None) -> Surface
Uses one of two different algorithms for scaling each dimension of the inputsurface as required. For shrinkage, the output pixels are area averages ofthe colors they cover. For expansion, a bilinear filter is used. For thex86-64 and i686 architectures, optimized
MMX
routines are included andwill run much faster than other machine types. The size is a 2 numbersequence for (width, height). This function only works for 24-bit or 32-bitsurfaces. An exception will be thrown if the input surface bit depth is lessthan 24.New in pygame 1.8.
- pygame.transform.smoothscale_by()¶
resize to new resolution, using scalar(s)
smoothscale_by(surface, factor, dest_surface=None) -> Surface
Experimental: feature still in development available for testing and feedback. It may change.Please leave smoothscale_by feedback with authors
Same as smoothscale(), but scales by some factor, rather thantaking the new size explicitly. For example,
transform.smoothscale_by(surf, 3)
will triple the size of thesurface in both dimensions. Optionally, the scale factor can be a sequenceof two numbers, controlling x and y scaling separately. For example,transform.smoothscale_by(surf, (2, 1))
doubles the image width butkeeps the height the same.New in pygame 2.1.3.
- pygame.transform.get_smoothscale_backend()¶
return smoothscale filter version in use: 'GENERIC', 'MMX', or 'SSE'
get_smoothscale_backend() -> string
Shows whether or not smoothscale is using
MMX
orSSE
acceleration.If no acceleration is available then "GENERIC" is returned. For a x86processor the level of acceleration to use is determined at runtime.This function is provided for pygame testing and debugging.
- pygame.transform.set_smoothscale_backend()¶
set smoothscale filter version to one of: 'GENERIC', 'MMX', or 'SSE'
set_smoothscale_backend(backend) -> None
Sets smoothscale acceleration. Takes a string argument. A value of 'GENERIC'turns off acceleration. 'MMX' uses
MMX
instructions only. 'SSE' allowsSSE
extensions as well. A value error is raised if type is notrecognized or not supported by the current processor.This function is provided for pygame testing and debugging. If smoothscalecauses an invalid instruction error then it is a pygame/SDL bug that shouldbe reported. Use this function as a temporary fix only.
- pygame.transform.chop()¶
gets a copy of an image with an interior area removed
chop(surface, rect) -> Surface
Extracts a portion of an image. All vertical and horizontal pixelssurrounding the given rectangle area are removed. The corner areas (diagonalto the rect) are then brought together. (The original image is not alteredby this operation.)
NOTE
: If you want a "crop" that returns the part of an image within arect, you can blit with a rect to a new surface or copy a subsurface.
- pygame.transform.laplacian()¶
find edges in a surface
laplacian(surface, dest_surface=None) -> Surface
Finds the edges in a surface using the laplacian algorithm.
New in pygame 1.8.
- pygame.transform.average_surfaces()¶
find the average surface from many surfaces.
average_surfaces(surfaces, dest_surface=None, palette_colors=1) -> Surface
Takes a sequence of surfaces and returns a surface with average colors fromeach of the surfaces.
palette_colors - if true we average the colors in palette, otherwise weaverage the pixel values. This is useful if the surface is actuallygreyscale colors, and not palette colors.
Note, this function currently does not handle palette using surfacescorrectly.
New in pygame 1.8.
New in pygame 1.9:
palette_colors
argument
- pygame.transform.average_color()¶
finds the average color of a surface
average_color(surface, rect=None, consider_alpha=False) -> Color
Finds the average color of a Surface or a region of a surface specified by aRect, and returns it as a Color. If consider_alpha is set to True, then alpha istaken into account (removing the black artifacts).
New in pygame 2.1.2:
consider_alpha
argument
- pygame.transform.grayscale()¶
grayscale a surface
grayscale(surface, dest_surface=None) -> Surface
Returns a grayscaled version of the original surface using the luminosity formula which weights red, green and blue according to their wavelengths.
An optional destination surface can be passed which is faster than creating a new Surface.This destination surface must have the same dimensions (width, height) and depth as the source Surface.
- pygame.transform.threshold()¶
finds which, and how many pixels in a surface are within a threshold of a 'search_color' or a 'search_surf'.
threshold(dest_surface, surface, search_color, threshold=(0,0,0,0), set_color=(0,0,0,0), set_behavior=1, search_surf=None, inverse_set=False) -> num_threshold_pixels
This versatile function can be used for find colors in a 'surf' close to a 'search_color'or close to colors in a separate 'search_surf'.
It can also be used to transfer pixels into a 'dest_surf' that match or don't match.
By default it sets pixels in the 'dest_surf' where all of the pixels NOT within thethreshold are changed to set_color. If inverse_set is optionally set to True,the pixels that ARE within the threshold are changed to set_color.
If the optional 'search_surf' surface is given, it is used to threshold againstrather than the specified 'set_color'. That is, it will find each pixel in the'surf' that is within the 'threshold' of the pixel at the same coordinatesof the 'search_surf'.
- Parameters
dest_surf (pygame.Surfacepygame object for representing images or None) -- Surface we are changing. See 'set_behavior'.Should be None if counting (set_behavior is 0).
surf (pygame.Surfacepygame object for representing images) -- Surface we are looking at.
search_color (pygame.Colorpygame object for color representations) -- Color we are searching for.
threshold (pygame.Colorpygame object for color representations) -- Within this distance from search_color (or search_surf).You can use a threshold of (r,g,b,a) where the r,g,b can have differentthresholds. So you could use an r threshold of 40 and a blue threshold of 2if you like.
set_color (pygame.Colorpygame object for color representations or None) -- Color we set in dest_surf.
set_behavior (int) --
set_behavior=1 (default). Pixels in dest_surface will be changed to 'set_color'.
set_behavior=0 we do not change 'dest_surf', just count. Make dest_surf=None.
set_behavior=2 pixels set in 'dest_surf' will be from 'surf'.
search_surf (pygame.Surfacepygame object for representing images or None) --
search_surf=None (default). Search against 'search_color' instead.
search_surf=Surface. Look at the color in 'search_surf' rather than using 'search_color'.
inverse_set (bool) --
False, default. Pixels outside of threshold are changed.
True, Pixels within threshold are changed.
- Return type
int
- Returns
The number of pixels that are within the 'threshold' in 'surf'compared to either 'search_color' or search_surf.
- Examples
See the threshold tests for a full of examples: https://github.com/pygame/pygame/blob/main/test/transform_test.py
def test_threshold_dest_surf_not_change(self): """the pixels within the threshold. All pixels not within threshold are changed to set_color. So there should be none changed in this test. """ (w, h) = size = (32, 32) threshold = (20, 20, 20, 20) original_color = (25, 25, 25, 25) original_dest_color = (65, 65, 65, 55) threshold_color = (10, 10, 10, 10) set_color = (255, 10, 10, 10) surf = pygame.Surface(size, pygame.SRCALPHA, 32) dest_surf = pygame.Surface(size, pygame.SRCALPHA, 32) search_surf = pygame.Surface(size, pygame.SRCALPHA, 32) surf.fill(original_color) search_surf.fill(threshold_color) dest_surf.fill(original_dest_color) # set_behavior=1, set dest_surface from set_color. # all within threshold of third_surface, so no color is set. THRESHOLD_BEHAVIOR_FROM_SEARCH_COLOR = 1 pixels_within_threshold = pygame.transform.threshold( dest_surface=dest_surf, surface=surf, search_color=None, threshold=threshold, set_color=set_color, set_behavior=THRESHOLD_BEHAVIOR_FROM_SEARCH_COLOR, search_surf=search_surf, ) # # Return, of pixels within threshold is correct self.assertEqual(w * h, pixels_within_threshold) # # Size of dest surface is correct dest_rect = dest_surf.get_rect() dest_size = dest_rect.size self.assertEqual(size, dest_size) # The color is not the change_color specified for every pixel As all # pixels are within threshold for pt in test_utils.rect_area_pts(dest_rect): self.assertNotEqual(dest_surf.get_at(pt), set_color) self.assertEqual(dest_surf.get_at(pt), original_dest_color)
New in pygame 1.8.
Changed in pygame 1.9.4: Fixed a lot of bugs and added keyword arguments. Test your code.
pygame.transform — pygame v2.6.0 documentation (2024)
References
- https://www.largescaleforums.com/threads/xb-to-xbe-conversion-starting.35196/
- https://www.storyofmathematics.com/vertical-stretch/
- https://www.pygame.org/docs/ref/transform.html
- https://www.linkedin.com/jobs/view/4054758050
- https://www.johnpyeauctions.co.uk/Event/LotDetails/291474238/2-X-BOXES-OF-ITEMS-INC-SALTER-ARC-ELECTRONIC-KITCHEN-SCALE-BRIGHT-STARTS-MUSICAL-TOY
Top Articles
How To Get Into Ulta
Mechanical Engineer or Applied Physicist for Ultra-High Vacuum Technology (TE-VSC-BVO-2024-146-LD) at Switzerland
Job Opportunities at Unitrans | MyJobMag
Latest Posts
Why social capital is essential in the fight against COVID-19 - Policy Forum
Stylist in Las Vegas, Nevada | Ulta Beauty, Inc.
Recommended Articles
- Digi Charat: Winter Garden Episode 8 Discussion
- IT Brushes For ULTA - Makeup | Ulta Beauty
- Spongebozz: Warum Sun Diego Deutschlands bester Rapper ist - WELT
- Steve Reeves In Sunglasses
- Is Kigyou Senshi Arslan Dark
- Review George Gershwin Alone (2020) Movie
- Tracking the Swing States for Harris and Trump
- Drea Garcia Cannes 2022
- 新・映像の世紀 Movie Summary
- Düsseldorf | Zo leuk is de hoofdstad van Noordrijn-Westfalen
- Coluche Getting Divorced
- The Last Wagon | Rotten Tomatoes
- Oyacodon Us Release
- Find a Marriage Counselor and Learn About Marriage Counse...
- Gugu Mbatha-Raw In 90S
- Where Did They Film Supermarsu (2018)
- Submerged: Hidden Depths is a Relaxing Puzzle Game That isn't Too Challenging - RESPAWN STATION
- The Dos and Don’ts of Using Neti Pots and Sinus Rinses
- Film Poster ハクション大魔王2020
- Looking for the Ultimate Anti-Aging Hack? It Might Be Collagen
- Bugsnax: A Faith-Filled Adventure In A Colorful World
- The 10 Best Face Massagers for Sculpting and Lifting
- What is Acrylic: Properties, Processing, and Applications
- An In-Depth Look at the Different Types of Medical Gloves and Their Applications - HealthNord
- Q-bics Fogless Shower Shaving Mirror, Set of 2
- Watch The Silence Of The Sky (2016) Internet Archive
- Watch Demon Slayer: Kimetsu no Yaiba English Sub/Dub online Free on HiAnime.to
- Miniatur-Zen-Garten: 5 Gründe, warum du einen brauchst!
- Bofuri: I Don't Want To Get Hurt Story
- 10-Gatsu No Hanabi Ep 7 Sub
- Movies Made By Sam Reid
- Keep Talking and Nobody Explodes - Bomb Defusal Manual
- Yōkai: An Overview and History - Mythical Encyclopedia
- Rei And Fuko Europe
- Eko Health | New Product: CORE 500™ Digital Stethoscope
- Chou Denji Robo Combattler V Mecha
- Board Game Review - Kamigami Battles: River of Souls — The Late Night Players
- Mermaid Forest Ova Smut
- When Does Asagiri No Miko Air
- Ian Mckellen Nominated For Oscar
- Hifuu Nightmare Diary ~ Violet Detector Optimized Settings
- Batplane (Object) - Comic Vine
- The Paddock Birthday Party Ideas
- Pulse Racer Aimbot Free
- Les Sims 5 : Vous pensiez qu'il était en développement, mais il n'en est finalement rien.
- 3세 남아를 위한 인기 폭발 장난감 총집합 뽀로로 폴리스 드라이브 바니랜드 출동 구조대 공룡 완구 세트 등 장난감 추천 어린이 완구 놀이 아이템
- Super Solvers: Outnumbered! Egg
- Makai Toushi Saga Figurine
- All 'The Walking Dead' Shows Coming to Netflix & How To Watch In Order
- Adventurer Tier List - Dragalia Lost Guide - IGN
- Laugh Under The Sun Ep 39
- Derby Stallion Ds Cool Outfits
- The Best Microcurrent Devices Are Like a Rewind Button for Skin
- What is special category data?
- Is Hitsuji No Uta Slice Of Life
- List of visual kei lives | ビジュアル系のライブ・一覧
- Gekiga Hitler Preview
- The Color Of The Clear Blue Sky Movie Explained
- Square Deal: The Game Of Two Dimensional Poker Drop Rate
- We Rigorously Tested 13 of the Best BB Creams—These 8 Passed
- God Of Deception Season 3 English Cast
- Because I Like You Mobile Game English
- SEAL Team Season 7 Cast, Characters & Actors (Photos)
- Apex Legends In-Contro
- 13 Best Travel Toiletry Bottles: Editor Tested, Leakproof, & Reusable
- Watch Onna No Ko Keikaku Online English Sub
- 'The Perfect Couple' Ending Explained: All About the Series' Major Twist — and How It Differs From the Novel
- Stephen Holden Movie Career
- Watch Elfen Lied English Sub/Dub online Free on HiAnime.to
- Best☆Position E621
- Shaving vs. Waxing: Benefits, Cons and Results
- These 13 Brow Pens Are the Next Best Thing to a Spendy Microblading Appointment
- Hand Maid Mai Sad Quotes
- Why cupping therapy is so popular among celebs and athletes — and whether it's right for you
- Non-Celiac Disease Conditions Associated with Elevated Tissue Transglutaminase IgA Antibodies (tTG-IgA)
- The Dreamhold Sound Bug
- What Happens At The End Of Love Clinic (2015)
- Who Wrote 虹猫蓝兔火凤凰 (2010)
- 10 Best Villains of the 1940s, Ranked
- Build Your Skincare Routine With Our Favorite, Top-Tested Products (Ever!)
- The Best Lubes for Smooth Sailing Alone or With a Partner
- Is Le Syndrome De La Havane - Menace Sur L’amérique The Last Movie
- Tino Mewes Cologne
- Doraemon Movie 12: Nobita No Dorabian Nights 3 Myanimelist
- Advanced Battle Manga Poster
- Zhao Zhao Yi Perfume Commercial
- Car Mechanic Simulator 2021 Cheats, Cheat Codes, Hints and Walkthroughs for Playstation 4
- Apa itu Tegangan Nominal (VDC)? - produsen baterai ebike
- There's no real cure for rosacea, but there are ways to tame flare ups
- Saiki Kusuo no Ψ-nan: Ψ-shidou-hen
- Maya-San No Yofukashi Creators
- Shim Ji-Ho Boyfriend
- Lum The Invader Girl/Urusei Yatsura Bbc Dub Remaster Complete Collection (NSSB) :: Nyaa
- Descargar Manga Life: Senjou No Bokura Pdf
- دانلود بازی Wolf Girl With You برای کامپیوتر
- What Movie Is After The Duke Of Burgundy (2014)
- Summary Of 新世紀エヴァンゲリオン
- When Did Mii-Chan Wants To Be Kept Manga Start
- Jungle Taitei: Yuuki Ga Mirai Wo Kaeru Episodes Free Download
- Do Pimple Patches Actually Work?
- nail art tie decoration
- colorful jelly clear ribbon bowknot nail charms heart pearls flower flat back gems parts nail art manicure decorations
- nail art sticker
- sj
- accessories manicure flower butterfly
- cat animal bunny 3d korean cartoon scrawl relief self adhesive nail art stickers cute pretty puppy
- nail decoration foils
- design stamp for nails printing stencil templates
- letters mould stamping design gel stencils diy manicure accessory tools
- hobbies
Article information
Author: Wyatt Volkman LLD
Last Updated:
Views: 6517
Rating: 4.6 / 5 (46 voted)
Reviews: 85% of readers found this page helpful
Author information
Name: Wyatt Volkman LLD
Birthday: 1992-02-16
Address: Suite 851 78549 Lubowitz Well, Wardside, TX 98080-8615
Phone: +67618977178100
Job: Manufacturing Director
Hobby: Running, Mountaineering, Inline skating, Writing, Baton twirling, Computer programming, Stone skipping
Introduction: My name is Wyatt Volkman LLD, I am a handsome, rich, comfortable, lively, zealous, graceful, gifted person who loves writing and wants to share my knowledge and understanding with you.