当前位置: 首页>>代码示例>>Python>>正文


Python PNMImage.getReadYSize方法代码示例

本文整理汇总了Python中panda3d.core.PNMImage.getReadYSize方法的典型用法代码示例。如果您正苦于以下问题:Python PNMImage.getReadYSize方法的具体用法?Python PNMImage.getReadYSize怎么用?Python PNMImage.getReadYSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在panda3d.core.PNMImage的用法示例。


在下文中一共展示了PNMImage.getReadYSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: loadImage

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getReadYSize [as 别名]
  def loadImage(self,file_path,cols,rows,scale_x,scale_y,frame_rate):

    # Make a filepath
    image_file = Filename(file_path)
    if image_file .empty():
        raise IOError, "File not found"
        return False

    # Instead of loading it outright, check with the PNMImageHeader if we can open
    # the file.
    img_head = PNMImageHeader()
    if not img_head.readHeader(image_file ):
        raise IOError, "PNMImageHeader could not read file %s. Try using absolute filepaths"%(file_path)
        return False

    # Load the image with a PNMImage
    full_image = PNMImage(img_head.getXSize(),img_head.getYSize())
    full_image.alphaFill(0)
    full_image.read(image_file) 

    right_image = PNMImage(img_head.getXSize(),img_head.getYSize())
    left_image = PNMImage(img_head.getXSize(),img_head.getYSize())
    right_image.copyFrom(full_image)    
    left_image.copyFrom(full_image)
    left_image.flip(True,False,False)

    # storing individual sprite size
    self.size_ = (right_image.getReadXSize()/cols,right_image.getReadYSize()/rows)

    self.seq_right_ = self.attachNewNode(self.createSequenceNode(self.name_ + '_right_seq',right_image,cols,rows,scale_x,scale_y,frame_rate))
    self.seq_left_ = self.attachNewNode(self.createSequenceNode(self.name_ + '_left_seq',left_image,cols,rows,scale_x,scale_y,frame_rate))
    self.seq_right_.reparentTo(self)
    self.seq_left_.reparentTo(self)

    right_image.clear()
    left_image.clear()
    full_image.clear()

    self.faceRight(True)      

    return True
开发者ID:jrgnicho,项目名称:platformer_games_project,代码行数:43,代码来源:test_sprite_animation.py

示例2: getTotalClickableArea

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getReadYSize [as 别名]
    def getTotalClickableArea(self):
        '''Compute the total clickable area, and compute its percentage relative to the image total size'''
        ### RENDERING CLICKABLE AREA
        # Prepare the rendering of the clickable area
        self.renderClickableArea()
        # Render the frame
        self.base.graphicsEngine.renderFrame()

        ### FETCHING THE RENDERED IMAGE
        # Prepare the variable that will store the frame image (in a PNMImage class, this is NOT a file format, but a convenient image manipulation class offered by Panda3D)
        screenshot = PNMImage()
        # Set display region to the default
        dr = base.camNode.getDisplayRegion(0)
        # Store the rendered frame into the variable screenshot
        dr.getScreenshot(screenshot)

        ### COMPUTE THE CLICKABLE AREA PERCENTAGE
        # Prepare an histogram object
        hist = PNMImage().Histogram()
        # Compute the histogram
        screenshot.makeHistogram(hist)
        # Get the number of white opaque pixels (the clickable area)
        totalClickableArea = hist.getCount(PNMImageHeader.PixelSpec(255,255,255, 255))
        # Get the percentage of clickable area relative to the total image size
        totalClickableAreaPercentage = float(totalClickableArea) * 100 / (screenshot.getReadXSize() * screenshot.getReadYSize())

        if self.debug:
            print("Total unique intensity pixels: %f" % hist.getNumPixels())
            print("Total clickable area: %f" % totalClickableArea)
            totalClickableAreaSqrt = sqrt(float(totalClickableArea))
            print("Total clickable area sqrt: %f" % totalClickableAreaSqrt)
            print("Size of image X*Y: %f * %f" %(screenshot.getReadXSize(), screenshot.getReadYSize()))
            print("Total clickable area percentage: %f" % totalClickableAreaPercentage)

            blackarea = hist.getCount(PNMImageHeader.PixelSpec(0,0,0, 255))
            print("Total black area: %f" % blackarea)
            print("Total black area percentage: %f" % (float(blackarea) * 100 / (screenshot.getReadXSize() * screenshot.getReadYSize()))  )

        return totalClickableAreaPercentage
开发者ID:lrq3000,项目名称:waCaptcha,代码行数:41,代码来源:worldgenerator.py


注:本文中的panda3d.core.PNMImage.getReadYSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。