Python - hello friends can help me fix this python 2.7 code

 
Vista:
sin imagen de perfil
Val: 8
Ha disminuido su posición en 9 puestos en Python (en relación al último mes)
Gráfica de Python

hello friends can help me fix this python 2.7 code

Publicado por jorge (5 intervenciones) el 21/12/2018 17:17:38
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
 
 
#
#
 
#
 
 
import argparse
import os
import sys
import time
import struct
import binascii
import re
import io
import glob
import codecs
from tempfile import mkstemp
from shutil import move
from os import remove, close
import StringIO
 
 
 
def unpack_spr( path_to_spr ):
       spr_file = open(path_to_spr, 'rb')
       (bmp_path, bmp_name) = os.path.split(path_to_spr)
       (bmp_short_name, temp2) = os.path.splitext(bmp_name)
 
       spr_file.seek(72)
       j = 1
 
       bmp_path2 = bmp_path + '\\' + bmp_short_name + '\\'
       if not os.path.exists(bmp_path2):
              os.mkdir(bmp_path2)
 
 
       while True:
 
              width = struct.unpack('I', spr_file.read(4))[0]
              height = struct.unpack('I', spr_file.read(4))[0]
              size = width * height * 2
              #image_data = spr_file.read(size)
              try:
                     image_data_io = StringIO.StringIO(spr_file.read(size))
              except:
                     break
 
              bmp_name = "Image" + str(j) + '.bmp'
              bmp_new_path = bmp_path2 + '\\' + bmp_name
              j += 1
              print bmp_new_path
 
 
 
              bmp_file = open(bmp_new_path, 'wb+')
              #                        size                  unused               pixel arr off       size of dib hed
              header = '\x42\x4d' + '\x0a\x29\x00\x00' + '\x00\x00\x00\x00' + '\x8a\x00\x00\x00' + '\x7c\x00\x00\x00'
              bmp_file.write(header)
 
              bmp_file.write(struct.Struct("<l").pack(width))
              bmp_file.write(struct.Struct("<l").pack(height))
 
              #            color plan   b per pix     ???                  size of raw 
              header2 = '\x01\x00' + '\x10\x00' + '\x03\x00\x00\x00' + '\x80\x28\x00\x00' + '\xc4\x0e\x00\x00' '\xf1\x00\x00\x00' + '\x00\x00\x00\x00' + '\x00\x00\x00\x00'
              bmp_file.write(header2)
              bitmask565 = '\x00\xF8\x00\x00\xE0\x07\x00\x00\x1F\x00\x00\x00'
              bmp_file.write(bitmask565)
              header4 = '\x00\x00\x00\x00\x42\x47\x52\x73\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00';
              bmp_file.write(header4)
 
 
              #num_rows = size / height
              row_size = size / height
              data_arr = []
 
              for i in range(height):
                     data_row = image_data_io.read(row_size)
                     data_arr .append(data_row)
 
              data_arr.reverse()
 
              for i in range(height):
                     bmp_file.write(data_arr[i])
 
 
              bmp_file.close()
 
              #bmp_file.write(image_data)       
 
       print " End...."
 
 
path_to_spr = 'C:\etc.spr'
unpack_spr( path_to_spr )
123
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 2.239
Plata
Ha mantenido su posición en Python (en relación al último mes)
Gráfica de Python

hello friends can help me fix this python 2.7 code

Publicado por xve (1646 intervenciones) el 21/12/2018 20:24:22
Que necesitas?? o que problema tienes??
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil
Val: 8
Ha disminuido su posición en 9 puestos en Python (en relación al último mes)
Gráfica de Python

hello friends can help me fix this python 2.7 code

Publicado por jorge (5 intervenciones) el 21/12/2018 21:29:58
My problem is that the code does not extract all the images from the file, as seen in the image of the publication, it only extracts some images
123
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar