Blender
Image Module 
To load an image 
in  PNG,JPG,TGA or BMP format
    Début   Index
precedentScript Dimension and  distance
Under construction Next

To download the script
 

# ==================================
# Load  a  jpg/png/tga/bmp image v.0.2
# with the new functions of the Blender python Image module

# jmsoler, 29/10/2004
# ==================================
import Blender
from Blender import BGL

IMAGE_ADRESSE="F:/EasyPHP/www/jmsoler/util/blenderfile/bonneannee2004.jpg"

img=Blender.Image.Load(IMAGE_ADRESSE)
img.glLoad()

def Display_Image(img,x,y,dx,dy): 
 """
 img =  objetc loaded with Blender.Image.Load() function
 x,y =   location in the script window from the left bottom corner
 dx,dy = scaling the image size dx for width and dy for height
 """
 BGL.glEnable(BGL.GL_TEXTURE_2D)
 BGL.glBindTexture(BGL.GL_TEXTURE_2D, img.getBindCode())
 BGL.glBegin(BGL.GL_POLYGON)
 BGL.glTexCoord2f(0.0,0.0) 
 BGL.glColor3f(1.0,1.0,1.0)
 BGL.glVertex3f(float(x),float(y),0.0)
 BGL.glTexCoord2f(1.0,0.0)
 BGL.glColor3f(1.0,1.0,1.0)
 BGL.glVertex3f(float(x+img.getSize()[0]*dx),float(y),0.0)
 BGL.glTexCoord2f(1.0,1.0)
 BGL.glColor3f(1.0,1.0,1.0)
 BGL.glVertex3f(float(x+img.getSize()[0]*dx),float(y+img.getSize()[1]*dy),0.0)
 BGL.glTexCoord2f(0.0,1.0) 
 BGL.glColor3f(1.0,1.0,1.0)
 BGL.glVertex3f(float(x),float(y+img.getSize()[1]*dy),0.0 )
 BGL.glEnd() 

 BGL.glDisable(BGL.GL_TEXTURE_2D)

def draw():
 global img
 size= BGL.Buffer(BGL.GL_FLOAT, 4)
 BGL.glGetFloatv(BGL.GL_SCISSOR_BOX, size) 
 size= size.list

 # Example 1, backgrounded image
 # sized to the script window
 Display_Image(img,1,1,size[2]/img.getSize()[0],size[3]/img.getSize()[1])

 #example 2, scaled image
 Display_Image(img,30,10,0.3,2.0)

 #example 3, slized by the right-top corner of the windows
 Display_Image(img,size[2]-100,size[3]-100,2.0,0.5)

 #example 4, normal sized image at the top of the pile
 Display_Image(img,130,100,1.0,1.0)

 Blender.Draw.Button("Exit", 1, 100, 10, 80, 19)

def event(evt, val): 
 global img
 if (evt== Blender.Draw.QKEY and not val): 
  Blender.Draw.Exit()
  img.glFree()
 else:
  Blender.Window.Redraw(Blender.Window.Types['SCRIPT']) 

def bevent(evt):
 if   (evt== 1): Blender.Draw.Exit()

Blender.Draw.Register(draw, event, bevent)


 
précédentScript Dimension et  distance
 Under construction Suivant
To  the top of the page

For questions,  the forum  :
 news://news.zoo-logique.org/3D.Blender