Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Image
- def getpix(img, r, g=0, b=0):
- ret = []
- sizex, sizey = img.size
- for x in range(sizex):
- for y in range(sizey):
- _r, _g, _b, _a = img.getpixel((x, y))
- if _r == r and _g == g and _b == b:
- ret.append((x, y))
- return ret
- def getstroke(imgfile='picture.png', outfile='stroke.java'):
- img = Image.open(imgfile)
- outf = open(outfile, 'w')
- for b in range(5, 256, 5):
- lst = sorted(getpix(img, r=0,g=0,b=b))
- if len(lst) == 0:
- continue
- outf.write('path = new Path();\n')
- outf.write('this.paths.add(path);\n')
- first = True
- for ele in lst:
- if first:
- func = 'moveTo'
- first = False
- else:
- func = 'lineTo'
- outf.write('path.{0}({1}f, {2}f);\n'.format(func, ele[0], ele[1]))
- outf.write('\n')
- outf.close()
Add Comment
Please, Sign In to add comment