numpy と Image(PIL) ライブラリを使用して画像を一連の行列として読み取り、pyglet (および opengl) を使用して画像を再構築するこのプログラムを作成しました。
pyglet を使用したコードは次のとおりです。
import Image
import numpy
import window
import sys
import pyglet
import random
a=numpy.asarray(Image.open(sys.argv[1]))
h,w= a.shape[0],a.shape[1]
s=a[0]
print s.shape
#######################################
def display():
x_a=0;y_a=h
for page in a:
for array in page:
j=array[2]
k=array[1]
l=array[0]
pyglet.gl.glColor3f(l,j,k)
pyglet.gl.glVertex2i(x_a,y_a)
x_a+=1
y_a-=1
x_a=0
######################################33
def on_draw(self):
global w,h
self.clear
pyglet.gl.glClear(pyglet.gl.GL_COLOR_BUFFER_BIT)
pyglet.gl.glBegin(pyglet.gl.GL_POINTS)
display()
pyglet.gl.glEnd()
pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot.png')
window.win.on_draw=on_draw
#######################################
u=window.win(w,h)
pyglet.app.run()
pygame ライブラリを使用するように変更された同じコード (および opengl の使用がない)
import pygame
import numpy
import Image
import sys
from pygame import gfxdraw
color=(255,255,255)
a=numpy.asarray(Image.open(sys.argv[1]))
h,w=a.shape[0],a.shape[1]
pygame.init()
screen = pygame.display.set_mode((w,h))
def uu():
y_a=0
for page in a:
x_a=0
for array in page:
co=(array[0],array[1],array[2])
pygame.gfxdraw.pixel(screen,x_a,y_a,co)
x_a+=1
y_a+=1
uu()
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
pygame.display.flip()
pyglet と pygame の結果:
だから私の質問は...なぜ問題があるのですか?opengl を使用してピクセルごとに画像を描画する方法に問題がありますか、それとも今のところ私の理解を超えている何かがありますか?