tout le monde, je ne suis amuser à faire sur mon temps libre un petit programme avec python 2.7 et PIL et win32com, qui converti chaque pixel d'une image 32 bits en couleur intérieur sur Microsoft Office Excel 2007 et supérieur le code pour
image_pixel_by_pixel.py
celui pour Excel 2007.py
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 # -*- coding: cp1252 -*- import PIL from PIL import Image def image_pixel_by_pixel(pix, L, H): def hexadecimal(nombre): nb=hex(nombre)[2:] if len(nb)==1: return str("0" + hex(nombre)[2:]) elif len(nb)==2: return str(hex(nombre)[2:]) pix_colors_list=[] for p in pix[L, H]: pix_colors_list.append(hexadecimal(p)) pix_colors_list.reverse() pix_colors_nombre="".join(pix_colors_list) return pix_colors_nombre
et quand à l'image Excel 2007.png elle montre le résultat final, cote à cote à gauche Excel 2007 avec toutes les cellules de la feuille redimensionner en 1x1 pixel par cellule à la main bien sur toutes en même temps, et à droite l'image original dans paint.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 # -*- coding: cp1252 -*- import multiprocessing from multiprocessing import Process import PIL from PIL import Image from win32com.client import Dispatch from image_pixel_by_pixel import * BMP=raw_input("Chemin d'accès de l'image :").replace("\\", "/") xlApp = Dispatch("Excel.Application") xlApp.Visible = 0 xlApp.Workbooks.Add() im = Image.open(BMP) pix=im.load() Largeur, Hauteur=int(im.size[0]), int(im.size[1]) Total=Largeur * Hauteur cpu_nombre=int(multiprocessing.cpu_count()) def image_feuille(pix, Largeur_p, Hauteur_p, l, c, L, H): while 1: if H<Hauteur_p and L<Largeur_p: xlApp.Cells(l,c).Interior.Color = int((image_pixel_by_pixel(pix, L, H)), 16) l+=1 H+=1 elif H==Hauteur_p and L<Largeur_p: l=1 c+=1 L+=1 H=0 print "L =", str(L), "H =", str(H) elif H<Hauteur_p and L==Largeur_p: break Largeur_p, Hauteur_p=Largeur, Hauteur l=1 c=1 L=0 H=0 image_feuille(pix, Largeur_p, Hauteur_p, l, c, L, H) xlApp.Visible = 1
Voilà des sugestions pour amélioration(s)?
Partager