pygame release 1.9 for python 3.1——image模块介绍

AUG 1 2009 ,PYGAME 终于可以支持python3.1了 详情请见pygame.org

这个教程嘛 估计没个把月是不会有教程了 咕~~(╯﹏╰)b ~~

自己研究研究好了,其实我翻译得很烂 有翻译得不好的地方大家一起探讨探讨~~~ 啊

先把release包里的DOC文件看一通再说

 

(pygame-1.9.0release/src/image.doc)

 

pygame.image
pygame module for image transfer

 

pygame.image
pygame模块的图像转换



The image module contains functions for loading and saving pictures, as
well as transferring Surfaces to formats usable by other packages.

 

 

image模块包含的功能有:加载和保存的图片,还可以用其他软件包转换surface成可用的格式。

Note that there is no Image class; an image is loaded as a
Surface object. The Surface class allows manipulation (drawing lines,
setting pixels, capturing regions, etc.).

 

请注意,image模块没有image类;每张图片都要作为一个surface对象来加载的。surface类是可以操作的(画线,设置像素,捕捉区域等等) 。

The image module is a required
dependency of Pygame, but it only optionally supports any extended file formats.
By default it can only load uncompressed BMP images. When built with full image
support, the pygame.image.load() function can support the following formats.

* JPG
* PNG
* GIF (non animated)
* BMP
* PCX
* TGA (uncompressed)
* TIF
* LBM (and PBM)
* PBM (and PGM, PPM)
* XPM

 

image模块是pygame必需的,但它只能有选择地支持一些扩展文件格式。
默认情况下它只能加载未压缩的BMP图片。当内置充分完全图片支持, pygame.image.load ( )函数可以支持以下格式。

* JPG
* PNG
* GIF (非动画)
* BMP
* PCX
* TGA (非压缩)
* TIF
* LBM (和 PBM)
* PBM (和 PGM, PPM)
* XPM

Saving images only supports a limited set of formats. You can save
to the following formats.

* BMP
* TGA
* PNG
* JPEG

PNG, JPEG saving new in pygame 1.8.
<SECTION>

 

保存图片只支持一组有限类型的格式。你可以按照以下类型的格式保存。

* BMP格式
* TGA格式
* PNG格式
* JPEG格式

PNG,JPEG的保存格式都是在pygame 1.8 新加的。



load

 

加载


load new image from a file
pygame.image.load(filename): return Surface
pygame.image.load(fileobj, namehint=""): return Surface

 

从文件中加载新图片

pygame.image.load(filename): return Surface
pygame.image.load(fileobj, namehint=""): return Surface 

 

 


Load an image from a file source. You can pass either a filename or a Python
file-like object.

 

从文件资源中加载图片。

你可以通过一个文件名或python文件类对象。

 

 



Pygame will automatically determine the image type (e.g., GIF or bitmap)
and create a new Surface object from the data. In some cases it will need to
know the file extension (e.g., GIF images should end in ".gif").
If you pass a raw file-like object, you may also want to pass the original
filename as the namehint argument.

 

Pygame将自动确定图片类型(例如GIF或者位图)并从数据中创建一个新的Surface类型的对象。在一些情况下,这需要事先知道的文件扩展名(例如GIF图片应该以".gif"作结尾) 。如果是通过原始文件类对象,你可能还需要通过原始文件名作为namehint。

The returned Surface will contain the same color format, colorkey and alpha
transparency as the file it came from. You will often want to call
Surface.convert() with no arguments, to create a copy that will draw more
quickly on the screen.

 

返回的Surface将和来自的文件一样,包含相同的①颜色格式,②colorkey和③Alpha透明值。你会经常要调用不带参数的函数:Surface.convert ( ),用来创建一个可以在屏幕上更快显示的副本。

For alpha transparency, like in .png images use the convert_alpha() method
after loading so that the image has per pixel transparency.

 

对于Alpha透明度,举例来说,对于.png格式的图片在加载后使用convert_alpha ( )方法,以便图片可以拥有每个像素的透明值。


Pygame may not always be built to support all image formats. At minimum it will
support uncompressed BMP. If pygame.image.get_extended() returns 'True', you
should be able to load most images( including png, jpg and gif ).

You should use os.path.join() for compatibility. 
  eg. asurf = pygame.image.load(os.path.join('data', 'bla.png'))

 

Pygame可能并不总是内置支持所有图片格式。但它至少可以
支持未压缩的BMP格式图片。如果pygame.image.get_extended ()返回'True(真)' ,你
应该能够加载大部分格式的图片(包括PNG,JPG和GIF 格式) 。

为了兼容性,你最好使用os.path.join ( )。
  例如,
asurf = pygame.image.load(os.path.join('data', 'bla.png'))

<END>


save

 

保存


save an image to disk
pygame.image.save(Surface, filename): return None

This will save your Surface as either a BMP, TGA, PNG, or JPEG image. If the
filename extension is unrecognized it will default to TGA. Both TGA, and BMP
file formats create uncompressed files. 

PNG, JPEG saving new in pygame 1.8.

 

保存一张图片到磁盘
pygame.image.save(Surface, filename): return None

这样可以保存你的Surface为BMP, TGA, PNG, or JPEG 图像。如果
文件扩展名是无法识别的,那么将默认为TGA格式,TGA和BMP
文件格式都可以创建压缩文件。


<END>



get_extended
test if extended image formats can be loaded
pygame.image.get_extended(): return bool

If pygame is built with extended image formats this function will return True.
It is still not possible to determine which formats will be available, but
generally you will be able to load them all.

 

get_extended
测试扩展图像格式是否可以被加载
pygame.image.get_extended(): return bool


如果pygame内建有扩展的图像格式,该函数将返回真。
我们仍然无法确定哪种格式是可以使用的,但一般来说,你应该是可以加载它们的。

<END>



tostring

transfer image to string buffer

pygame.image.tostring(Surface, format, flipped=False): return string

Creates a string that can be transferred with the 'fromstring' method in
other Python imaging packages. Some Python image packages prefer their images
in bottom-to-top format (PyOpenGL for example). If you pass True for the
flipped argument, the string buffer will be vertically flipped.

The format argument is a string of one of the following values. Note that only
8bit Surfaces can use the "P" format. The other formats will work for any
Surface. Also note that other Python image packages support more formats than
Pygame.

 

tostring
转换图片到字符串缓冲区
pygame.image.tostring(Surface, format, flipped=False): return string


创建一个可以从其他python图片包中用'fromstring'方法转换的字符串。一些python图片包偏爱使用自下而上的格式(例如PyOpenGL) 。如果你设置翻转参数成True,该字符串缓冲区将垂直翻转。

格式参数是下列值之一的一个字符串。请注意,只有8位的面可以使用"P"格式。其他格式将支持任何Surface。还需注意到的是,其他的Python图片包可以比Pygame支持更多的格式 。


 

* P, 8bit palettized Surfaces
* RGB, 24bit image
* RGBX, 32bit image with unused space
* RGBA, 32bit image with an alpha channel
* ARGB, 32bit image with alpha channel first
* RGBA_PREMULT, 32bit image with colors scaled by alpha channel
* ARGB_PREMULT, 32bit image with colors scaled by alpha channel, alpha channel first


* P, 8位调色板的面
* RGB, 24位图像
* RGBX, 未使用的空间的32位图像
* RGBA, 图像通道-Alpha的32位图像
* ARGB, Alpha-图像通道的32位图像
* RGBA_PREMULT,32位图像色彩规模的alpha通道
* ARGB_PREMULT, 32位图像色彩规模的Alpha通道, Alpha通道第一

<END>



fromstring
create new Surface from a string buffer

 

fromstring

从一个字符缓冲区中创建一个新的Surface


pygame.image.fromstring(string, size, format, flipped=False): return Surface

This function takes arguments similar to pygame.image.tostring(). The size
argument is a pair of numbers representing the width and height. Once the
new Surface is created you can destroy the string buffer.

The size and format image must compute the exact same size as the passed
string buffer. Otherwise an exception will be raised.

See the pygame.image.frombuffer() method for a potentially faster way to
transfer images into Pygame.

 

pygame.image.fromstring(string, size, format, flipped=False): return Surface

此函数的参数类似pygame.image.tostring ( ) 。大小
参数是一个对数字代表的宽度和高度。一旦
创建新的Surface,你可以摧毁字符串缓冲区。

图片的大小和格式必须估计得和刚才的字符缓冲区确切相同的大小。否则将会抛出异常例外。

从pygame.image.frombuffer ( )方法看出这是一个传输图像到Pygame的更快的潜在途径。

<END>


frombuffer
create a new Surface that shares data inside a string buffer

 

frombuffer
创建一个新的可以在字符缓冲区里共享数据的Surface


pygame.image.frombuffer(string, size, format): return Surface

Create a new Surface that shares pixel data directly from the string buffer.
This method takes the same arguments as pygame.image.fromstring(), but is
unable to vertically flip the source data.

This will run much faster than pygame.image.fromstring, since no pixel data
must be allocated and copied.

 

pygame.image.frombuffer(string, size, format): return Surface

 

创建一个新的直接从字符串缓冲区里共享像素数据的Surface。
该方法和pygame.image.fromstring ( )有着同样的参数 ,但
无法垂直翻转资源的数据。

这将使得运行速度远远超过pygame.image.fromstring ,因为没有任何像素数据被分配和复制。

<END>
<END>

 

 

 

 

翻译得差不多了 这是详细的介绍 通过键入help('pygame.image') ,还可以得到下面的介绍 我插入了中文的介绍 = = 加了红字的是用法。。。

 

>>> help('pygame.image')

# pygame中pygame.image模块的帮助文档
Help on module pygame.image in pygame:

NAME
    pygame.image - pygame module for image transfer

FILE
    d:/python31/lib/site-packages/pygame/image.pyd

FUNCTIONS
    frombuffer(...)
        pygame.image.frombuffer(string, size, format): return Surface
        ### 创建一个在字符串缓冲区里共享数据的Surface
        create a new Surface that shares data inside a string buffer
   
    fromstring(...)
        pygame.image.fromstring(string, size, format, flipped=False): return Surface
        ### 从字符串缓冲区里创建新的Surface
        create new Surface from a string buffer
   
    get_extended(...)
        pygame.image.get_extended(): return bool
        ### 测试扩展图片格式能否被加载
        test if extended image formats can be loaded
   
    load = load_extended(...)
   ### 为图像转换的pygame模块  
        pygame module for image transfer
   
    load_basic(...)
        pygame.image.load(filename): return Surface
        pygame.image.load(fileobj, namehint=): return Surface

        ### 从文件中加载图片
        load new image from a file
   
    load_extended(...)

        ### 为图像转换的pygame模块
        pygame module for image transfer
   
    save(...)
        pygame.image.save(Surface, filename): return None

        ### 保存图片到磁盘中
        save an image to disk
   
    save_extended(...)

        ### 为图像转换的pygame模块
        pygame module for image transfer
   
    tostring(...)
        pygame.image.tostring(Surface, format, flipped=False): return string

        ### 转换图片为字符串缓冲区
        transfer image to string buffer

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值