01 移除器件
一、背景介绍
焊接电路板是电子工程师的基本功, 将元器件从电路板上移除是电路调试过程中的基本功。 今天看到一个视频短片,作者详细介绍了对于这种密集电路板上各种元器件焊下来的技巧。 下面让我们一起来听听他的经验吧。
二、具体操作
最简单的移除器件,就是这种表贴电阻、电容器件。 比如这里的C32电容。只要简单利用烙铁在电容两端补锡加热,便可以轻松将电容取下。 取下之后然后利用吸锡铜丝网清理焊盘, 在利用粘有清洗剂棉花球擦洗焊盘表面,为下一次焊接做准备。
利用这种方式对于小于1206封装的电阻电容非常有效。但对于体积超过1206的器件,特别是电容器件,这种方法往往比较困难。 比如这里的胆电容,体积比较大。如果使用热风枪对它进行拆卸,热量 有可能使其损坏。 这里采用的方法就是在电容两端补锡之后,再使用两个尖头烙铁同时加热将其取下。 后面清理焊盘工作都是一样的。
对于SOP封装的小型芯片,则需要使用热风枪来进行拆焊。 比如这里SOP8封装的芯片,先在其管脚涂抹助焊剂,然后在使用热风枪进行加热,直到可以使用尖头镊子将芯片取下。 后面使用吸锡铜网或者多股铜丝对焊盘进行清理。
对于这种SOP8封装的芯片,也可以采用双烙铁方式将其拆焊。 先给芯片涂抹助焊剂,然后在其管脚补锡,之后在利用双烙铁将其加热取下。 焊盘上还残留了较多的焊锡。 然后在利用吸锡铜网清理焊盘,并使用洗板水进行擦洗干净。
对于这种表贴的铝电解电容,使用热风枪拆卸很容易将其损坏,塑料底座也会融化。 利用双烙铁方法还是比较容易将其取下。只是它的焊盘连接较粗的引线,散热较快,所以需要较长的时间加热, 加热之后,在对焊盘进行清理。
除了热风枪、双烙铁方法之外,还可以使用钳子移除这种表贴电解电容。感觉就像拔牙一样。 之后在对焊盘进行清理。 当然这种蛮力拆焊器件方法有一定的危险, 有可能损坏焊盘。 所以最安全还是利用双烙铁方法进行拆焊。 双烙铁适用于双管脚器件和SOP8封装器件。 但对于芯片下面有散热焊盘的芯片不适用,只能使用热风枪。
拆除器件时,有时需要注意别伤及无辜。 比如需要移除的排阻旁边, 有一个塑料插座。如果使用热风枪进行移除时, 需要考虑对它的保护。 一种方法就是利用铝箔纸粘贴在插座旁边,这样就可以放心大胆利用热风枪移除排阻了。 作为对比,可以看到热风枪很容易损坏塑料插座, 这是被热风枪损坏的情况。
※ 总 结 ※
本文给出了在拆焊电路板元器件的过程中,需要注意的地方。 俗话说,胆大心细,多琢磨,任何技巧都有使用的场合。 掌握好热风枪、烙铁、助焊剂的品性,面对在复杂的情形都能够游刃有余。 最后别忘了对拆焊后的焊盘进行清理,修旧如旧。
拆焊专家
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# GIF2MPG.PY -- by Dr. ZhuoQing 2020-02-21
#
# gif2mpg * # Change gif to microvideo and put image on CSDN
# gif2mpg + # Change video and put file name on CSDN
# gif2mpg . # Move d:\temp\1.avi to MicroVideo
# gif2mpg / # Change gif to microvideo and generate hide
# # move 1.wav, 1.mp3 to MicroVideo
# gif2mpg 150|* # Insert multiple picture into CSDN
# gif2mpg @,R # Resize select image into view size
# gif2mpg |,P # Paste select image into view size
# gif2mpg xxx c,C,\ # Copy the mpeg GIF to temp\GIF
# gif2mpg \ # Copy mpeg to MicroVideo and Snag GIF
# gif2mpg \. # Copy mpeg to MicroVideo and Snag GIF, keep last Picture
# gif2mpg \.. # Copy mpeg to MicroVideo and Snag GIF, keep last Picture, Snag last GIF
# gif2mpg \... # Copy mpeg to MicroVideo, SnagGIF, SnagFirst and last Picture.
#
#
# Note:
#============================================================
from head import *
import shutil
import cv2
import numpy as np
import glob
from io import BytesIO
import win32clipboard
from PIL import Image
#------------------------------------------------------------
csdn_title = '写文章-CSDN博客'
#------------------------------------------------------------
microvideo_dir = r'd:\Nutdisk\MicroVideo'
microvideo_mooc = r'd:\MooC\MicroVideo'
microvideo_flag = 0
numstr = 'GM%d'%(int(time.time()))
#------------------------------------------------------------
def send_to_clipboard(clip_type, data):
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(clip_type, data)
win32clipboard.CloseClipboard()
#------------------------------------------------------------
tspdropfile2pastetext()
strall = clipboard.paste().split()
AUDACITY_TITLE = 'Audacity'
audacityflag = 0
microvideo_flag = 0
#------------------------------------------------------------
def AudacitySave(fname):
tspsendwindowkey(AUDACITY_TITLE, "fe", alt=1, noreturn=1)
time.sleep(1)
rect = tspgetwindowrect("导出音频")
if sum(rect) == 0:
printf("ERROR: Can not open the save dialog.\a")
exit()
clipboard.copy(fname)
tspsendwindowkey("导出音频", "t", alt=1,noreturn=1)
tspsendwindowkey("导出音频", "cm", noreturn=1)
tspsendwindowkey("导出音频", "n", alt=1, noreturn=1)
tspsendwindowkey("导出音频", "v", control=1, noreturn=1)
tspsendwindowkey("导出音频", "s", alt=1, noreturn=1)
time.sleep(1)
rect = tspgetwindowrect("警告")
printf(rect)
if sum(rect) != 0:
printf("DEBUG")
time.sleep(.5)
tspsendwindowkey("警告", "y", alt=1, noreturn=1)
time.sleep(.5)
rect = tspgetwindowrect("编辑元信息")
if sum(rect) == 0:
printf("ERROR: Can not open the edit dialog.\a")
tspsendwindowkey("编辑元信息", "\r", noreturn=1)
time.sleep(1.5)
tspsendwindowkey(AUDACITY_TITLE, "tv", alt=1, noreturn=1)
#------------------------------------------------------------
def imagepastesize(fname, width, height, topdown=0):
if not os.path.isfile(fname):
return 1
im = Image.new(mode='RGB', size=(width, height), color=(255,255,255))
imshow = Image.open(fname)
imwidth,imheight = imshow.size
offset = ((width-imwidth)//2, (height-imheight)//((topdown+1)*2))
im.paste(imshow, offset)
# im.save(r'd:\temp\%s'%os.path.basename(fname))
im.save(fname)
#------------------------------------------------------------
def imageresize(fname, width, height):
if not os.path.isfile(fname):
return 1
im = Image.new(mode='RGB', size=(width, height), color=(255,255,255))
imshow = Image.open(fname)
imwidth,imheight = imshow.size
resizewidth = width
resizeheight = height
if imwidth*height > imheight*width:
resizeheight = imheight*width//imwidth
else:
resizewidth = imwidth*height//imheight
imshow = imshow.resize((resizewidth, resizeheight))
offset = ((width-resizewidth)//2, (height-resizeheight)//2)
im.paste(imshow, offset)
# im.save(r'd:\temp\%s'%os.path.basename(fname))
im.save(fname)
#------------------------------------------------------------
def getgifpic():
rect = tspgetviewdcrange()
iddim = tspgetdopidall()
tempdim = []
for id in iddim:
infor = tspgetinfor(id)
# printf(id, infor)
if not 'type' in infor.keys():
continue
type = infor['type']
if type == 11:
ratio = infor['ratio']
range1 = infor['range']
width = int((range1[2]-range1[0])/ratio[0])
height = int((range1[3]-range1[1])/ratio[1])
if abs(width - rect[4]) < 10 and abs(height - rect[5]) < 10:
if ratio[0] < 0.3 and ratio[1] < 0.3:
tempdim.append(id)
return tempdim
#------------------------------------------------------------
def changeimgrect(fname):
rect = tspgetviewdcrange()
img = Image.open(fname)
rectwidth = rect[4]
rectheight = rect[5]
rectwidth = (rectwidth + 5) // 10 * 10
rectheight = (rectheight + 5) // 10 * 10
img = img.resize((rectwidth, rectheight))
img.save(fname)
#------------------------------------------------------------
printf(sys.argv)
if len(sys.argv) == 3 or len(sys.argv) == 2:
viewsize = tspgetviewsize()
selid = tspgetselectid()
if sys.argv[-1] == '@' or sys.argv[-1] == 'r' or sys.argv[-1] == 'R':
for id in selid:
filename = tspgetdopfile(id)
imageresize(filename, viewsize[0], viewsize[1])
tsprefreshimagebuffer()
printf('\a')
tsprv()
exit()
elif sys.argv[-1] == '#' or sys.argv[-1] == 'p' or sys.argv[-1] == 'P' or sys.argv[-1] == '|':
for id in selid:
filename = tspgetdopfile(id)
imagepastesize(filename, viewsize[0], viewsize[1], 1)
tsprefreshimagebuffer()
tsprv()
printf('\a')
exit()
#------------------------------------------------------------
tsprefreshimagebuffer()
addhidegifpage = 0
keeplastpage = 0
if sys.argv[-1] == '\\' or sys.argv[-1] == '、':
addhidegifpage = 1
microvideo_flag = 1
sys.argv = sys.argv[:-1]
elif sys.argv[-1] == '\\\\' or sys.argv[-1] == '、、':
addhidegifpage = 1
audacityflag = 1
microvideo_flag = 1
sys.argv = sys.argv[:-1]
elif sys.argv[-1][-1] == '\\' or sys.argv[-1][-1] == '、':
sys.argv[-1] = sys.argv[-1][:-1]
audacityflag = 1
microvideo_flag = 1
elif sys.argv[-1] == '\\.' or sys.argv[-1] == '、。':
addhidegifpage = 1
microvideo_flag = 1
sys.argv = sys.argv[:-1]
keeplastpage = 1
elif sys.argv[-1] == '\\\\.' or sys.argv[-1] == '、、。':
addhidegifpage = 1
audacityflag = 1
microvideo_flag = 1
keeplastpage = 1
sys.argv = sys.argv[:-1]
elif sys.argv[-1] == '\\..' or sys.argv[-1] == '、。。':
addhidegifpage = 1
microvideo_flag = 1
sys.argv = sys.argv[:-1]
keeplastpage = 2
elif sys.argv[-1] == '\\\\..' or sys.argv[-1] == '、、。。':
addhidegifpage = 1
audacityflag = 1
microvideo_flag = 1
keeplastpage = 2
sys.argv = sys.argv[:-1]
elif sys.argv[-1] == '\\...' or sys.argv[-1] == '、。。。':
addhidegifpage = 1
microvideo_flag = 1
sys.argv = sys.argv[:-1]
keeplastpage = 3
elif sys.argv[-1] == '\\\\...' or sys.argv[-1] == '、、。。。':
addhidegifpage = 1
audacityflag = 1
microvideo_flag = 1
keeplastpage = 3
sys.argv = sys.argv[:-1]
#------------------------------------------------------------
hideiddim = tspgethideid()
rect = tspgetviewdcrange()
tempdim = []
for id in hideiddim:
infor = tspgetinfor(id)
type = infor['type']
if type == 11:
ratio = infor['ratio']
range1 = infor['range']
width = int((range1[2]-range1[0])/ratio[0])
height = int((range1[3]-range1[1])/ratio[1])
if abs(width - rect[4]) < 10 and abs(height - rect[5]) < 10:
tempdim.append(id)
hideiddim = tempdim
headpageid = 0
if len(hideiddim) == 0:
hideiddim = getgifpic()
elif len(hideiddim) == 1:
headpageid = hideiddim[0]
hideiddim = getgifpic()
if headpageid in hideiddim:
headpageid = hideiddim.index(headpageid)
else: headpageid = 0
#------------------------------------------------------------
leftwidth = 0
leftstring = ''
if len(sys.argv) > 1:
idid = len(sys.argv) - 1
id = sys.argv[idid].find('|')
if id > 0:
if sys.argv[idid][:id].isdigit():
leftwidth = int(sys.argv[idid][:id])
leftstring = sys.argv[idid][id+1:]
elif sys.argv[idid] == 'ii' or sys.argv[idid] == 'i':
leftwidth = 160
leftstring = sys.argv[idid][id+1:].replace('》', '>')
cid = leftstring.find('C')
if cid < 0: cid = leftstring.find('c')
if cid >= 0:
if leftstring[cid+1:].replace('-','').isdigit():
headpageid = int(leftstring[cid+1:])
leftstring = leftstring[:cid+1]
printf(leftstring, headpageid)
#------------------------------------------------------------
if leftstring.find('p') >= 0 or leftstring.find('P') >= 0 or leftstring.find('|') > 0 or\
leftstring.find('#') >= 0 or leftstring.find('c') >= 0 or leftstring.find('C') >= 0:
viewsize = tspgetviewsize()
selid = tspgetselectid()
flag = 0
if len(selid) == 0 and len(hideiddim) > 0:
selid = hideiddim
for id in selid:
filename = tspgetdopfile(id)
if isgifname(filename) == 0:
flag = 1
break
imagepastesize(filename, viewsize[0], viewsize[1], 1)
leftstring = leftstring.replace('p','').replace('P','').replace('|','').replace('#','')
if flag == 0 and len(selid) > 0:
leftstring = leftstring + '_-%d'%len(selid)
if leftstring.find('R') >= 0 or leftstring.find('r') >= 0 or leftstring.find('\\') >= 0:
viewsize = tspgetviewsize()
selid = tspgetselectid()
if len(selid) == 0 and len(hideiddim) > 0:
selid = hideiddim
flag = 0
for id in selid:
filename = tspgetdopfile(id)
if isgifname(filename) == 0:
flag = 1
break
imageresize(filename, viewsize[0], viewsize[1])
leftstring = leftstring.replace('*', '').replace('r','').replace('R','').replace('\\','')
if flag == 0 and len(selid) > 0:
leftstring = leftstring + '_-%d'%len(selid)
#------------------------------------------------------------
for s in sys.argv[1:]:
filename = os.path.join(microvideo_dir, s+".MPG")
if os.path.isfile(filename): strall.append(filename)
filename = os.path.join(microvideo_dir, s+".AVI")
if os.path.isfile(filename): strall.append(filename)
filename = os.path.join(microvideo_mooc, s+".MPG")
if os.path.isfile(filename): strall.append(filename)
filename = os.path.join(microvideo_mooc, s+".AVI")
if os.path.isfile(filename): strall.append(filename)
#------------------------------------------------------------
def avi2csdn(filename, newfile):
#--------------------------------------------------------
cam = cv2.VideoCapture(filename)
ret, frame = cam.read()
cv2.imwrite(r'd:\temp\1.bmp', frame)
for _ in range(20):
time.sleep(.25)
printf('\a')
if os.path.isfile(r'd:\temp\1.bmp'):
break
image = Image.open(r'd:\temp\1.bmp')
output = BytesIO()
image.convert('RGB').save(output, 'BMP')
data = output.getvalue()[14:]
output.close()
send_to_clipboard(win32clipboard.CF_DIB, data)
tspsendwindowkey(csdn_title, 'v', control=1)
cam.release()
for i in range(40):
time.sleep(.5)
readdata = tspread()
if readdata[2] == 1: break
if readdata[7] != 0: break
if readdata[8] != 0: exit()
if readdata[9] != 0: exit()
tspsendwindowkey(csdn_title, 'c', control=1, noreturn=1)
if clipboard.paste().find('在这里插入图片描述') >= 0:
tspbeep(1500, 200)
time.sleep(.25)
break
printf('\a')
for i in range(20):
readdata = tspread()
if readdata[7] == 0 and readdata[8] == 0 and readdata[9] == 0: break
tspbeep(2500, 15)
time.sleep(.25)
tspsendwindowkey(csdn_title, 'ac', control=1, noreturn=1)
pastestr = clipboard.paste().split('![在这里插入图片描述](')
if len(pastestr) < 2:
printf("Can not find the ![Insert picture] discriptor !\a")
exit()
tspsendwindowkey(csdn_title, 'z', control=1)
pastestr = pastestr[1].split(')')[0]
pastestr = pastestr.split('?')[0]
insertstr = '![%s](%s#pic_center =%dx)'%(newfile, pastestr, picwidth)
if leftwidth > 0:
# insertstr = '![%s|%s](%s#pic_left =%dx) '%(newfile, leftstring, pastestr, leftwidth)
if leftstring.find('c') < 0 and leftstring.find('C') < 0:
insertstr = '![%s|%s](%s#pic_left =%dx) '%(filename, leftstring, pastestr, leftwidth)
else:
leftstring = leftstring.replace('c', '').replace('C', '')
insertstr = '![%s|%s](%s#pic_center =%dx)\n\n'%(filename, leftstring, pastestr, leftwidth)
clipboard.copy(insertstr)
tspsendwindowkey(csdn_title, "v", control=1, noreturn=1)
os.remove(r'd:\temp\1.bmp')
#------------------------------------------------------------
img_array = []
size = (100, 100)
mpegfile = []
avimove_flag = 0
copy_flag = 0 # Save picture to temp\gif
#------------------------------------------------------------
picwidth = 350
if len(sys.argv) > 1:
if sys.argv[1] == '**':
microvideo_flag = 1
if sys.argv[1] == '*':
microvideo_flag = 1
picwidth = 160
if len(sys.argv) > 2:
if sys.argv[2].isdigit():
picwidth = int(sys.argv[2])
argstr = ''.join(sys.argv[1:])
if sys.argv[1] == '+' or argstr[:2] == '*+':
microvideo_flag = 2
if sys.argv[1] == '.' or argstr[:2] == '*.' or argstr[:2] == '*。':
avimove_flag = 1
microvideo_flag = 0
if sys.argv[-1].isdigit():
picwidth = int(sys.argv[-1])
if len(sys.argv) > 2:
if sys.argv[2] == '\\' or sys.argv[2] == 'C' or sys.argv[2] == 'c':
copy_flag = 1
#printf(sys.argv, avimove_flag)
#exit()
#------------------------------------------------------------
for f in strall:
if os.path.isfile(f):
microvideo_flag = 1
picwidth = 160
break
printf(microvideo_flag)
#------------------------------------------------------------
if microvideo_flag > 0:
clipboard.copy("")
gifiddim = tspgetgifid()
seliddim = tspgetselectid()
pictureflag = 0
if len(gifiddim) == 0:
if len(seliddim) > 0:
gifiddim = seliddim
pictureflag = 1
if len(gifiddim) == 0:
seliddim = hideiddim
gifiddim = hideiddim
pictureflag = 1
if len(gifiddim) == 0:
filecount = 0
for s in strall:
if os.path.isfile(s):
filecount += 1
if filecount == 0:
printf('DOP has not GIF DOP .\a')
exit()
for s in strall:
if os.path.isfile(s):
ext = s.split('.')[-1].upper()
if ext == 'MPG' or ext == 'AVI' or ext == 'MP4':
avi2csdn(s, os.path.basename(s))
exit()
#------------------------------------------------------------
outfile = numstr
frameps = 20
pagedim = []
#------------------------------------------------------------
if keeplastpage > 0 or audacityflag > 0:
headbytes = b'\x55\xaa\x60\x06'
databytes = int2short(-50)
gifname = tspgetdopfile(gifiddim[0])
tspimagesetstring(gifname, headbytes+databytes)
#--------------------------------------------------------
lastfilename = ''
firstfilename = ''
for gifid in gifiddim:
if pictureflag > 0:
filename = tspgetdopfile(gifid)
lastfilename = filename
if len(firstfilename) == 0:
firstfilename = filename
img = cv2.imread(filename)
mpegfile.append(filename)
height,width,layers=img.shape
size = (width, height)
img_array.append(img)
continue
filedir = tspgetdoppath(gifid)
gifpage = tspgetgifpage(gifid)
filename = tspgetdopfile(gifid)
nameonly, ext = os.path.splitext(filename)
pagedim.append(gifpage)
for i in range(gifpage):
filename = os.path.join(filedir, '%04d%s'%(i, ext))
lastfilename = filename
if len(firstfilename) == 0: firstfilename = filename
img = cv2.imread(filename)
mpegfile.append(filename)
height,width,layers=img.shape
size = (width, height)
img_array.append(img)
#--------------------------------------------------------
filename = '%s_%d_%d.MPG'%(outfile, width, height)
gifdir = '%s_%d_%d'%(outfile, width, height)
outfilename = os.path.join(microvideo_dir, filename)
out = cv2.VideoWriter(outfilename, cv2.VideoWriter_fourcc(*'MPEG'), frameps, size, True)
for id,img in enumerate(img_array):
out.write(img)
tspshowinfor('%d '%id)
out.release()
#--------------------------------------------------------
keeplastfilename = ''
if keeplastpage > 0:
if os.path.isfile(lastfilename):
numstr = int(time.time())
keeplastfilename = r'd:\temp\BM%d.%s'%(numstr, lastfilename.split('.')[-1])
shutil.copyfile(lastfilename, keeplastfilename)
#--------------------------------------------------------
if keeplastpage == 3:
if os.path.isfile(firstfilename):
changeimgrect(firstfilename)
image = Image.open(firstfilename)
output = BytesIO()
image.convert('RGB').save(output, 'BMP')
data = output.getvalue()[14:]
output.close()
send_to_clipboard(win32clipboard.CF_DIB, data)
fname = os.path.basename(firstfilename)
tspimagesetstring(0, fname)
time.sleep(.2)
clipboard.copy("")
#--------------------------------------------------------
if addhidegifpage > 0:
#----------------------------------------------------
fname = os.path.basename(outfilename)
#----------------------------------------------------
if os.path.isfile(firstfilename):
changeimgrect(firstfilename)
image = Image.open(firstfilename)
output = BytesIO()
image.convert('RGB').save(output, 'BMP')
data = output.getvalue()[14:]
output.close()
send_to_clipboard(win32clipboard.CF_DIB, data)
tspimagesetstring(0, fname)
time.sleep(.2)
clipboard.copy("")
printf(fname)
else:
id = int(tspimagesetstring(0, fname))
gifname = tspgetdopfile(id)
tspimagesetstring(gifname, fname)
#----------------------------------------------------
if not os.path.isdir(r'd:\temp'):
os.mkdir(r'd:\temp')
if not os.path.isdir(r'd:\temp\GIF'):
os.mkdir(r'd:\temp\GIF')
gifcopydir = fname.split('.')[0]
outgifdir = r'd:\temp\GIF\%s'%gifcopydir
if not os.path.isdir(outgifdir):
os.mkdir(outgifdir)
for id,fn in enumerate(mpegfile):
extstr = fn.split('.')[-1]
outfile = os.path.join(outgifdir, '%04d.%s'%(id, extstr))
shutil.move(fn, outfile)
#----------------------------------------------------
printf('\a')
tspdeletedop(gifiddim)
tsprv(-1)
#----------------------------------------------------
if audacityflag != 0:
rect = tspgetwindowrect(AUDACITY_TITLE)
if sum(rect) != 0:
mp3file = outfilename.split('.')[0] + '.MP3'
AudacitySave(mp3file)
#----------------------------------------------------
if keeplastpage > 0:
if os.path.isfile(keeplastfilename):
changeimgrect(keeplastfilename)
tspacceptfile(keeplastfilename)
os.remove(keeplastfilename)
iddim = tspgetdopidall()
if len(iddim) > 0:
lastid = iddim[-1]
infor = tspgetinfor(lastid)
if 'type' in infor.keys():
type = infor['type']
if type == 11:
ratio = infor['ratio']
range1 = infor['range']
width = int((range1[2]-range1[0])/ratio[0])
height = int((range1[3]-range1[1])/ratio[1])
rect = tspgetviewdcrange()
if abs(width - rect[4]) < 10 and abs(height - rect[5]) < 10:
setratio = (rect[2]-rect[0])/width
tspsetdopxy(lastid, rect[:4])
tspsetresratio(lastid, int(setratio*100))
tsprv(-3)
if keeplastpage > 1:
headbytes = b'\x55\xaa\x60\x06'
databytes = int2short(1)
id = int(tspimagesetstring(0, 15))
gifname = tspgetdopfile(id)
tspimagesetstring(gifname, headbytes+databytes)
tsprv(-3)
#----------------------------------------------------
tsprv()
tspfocuswindow('TEASOFT:1')
exit()
#--------------------------------------------------------
if microvideo_flag == 2:
clipboard.copy(filename + '\n')
tspsendwindowkey(csdn_title, "v", control=1, noreturn=1)
else:
tspsendwindowkey(csdn_title,"c", control=1, noreturn=1)
originstr = clipboard.paste()
if len(originstr) > 0:
tspsendwindowkey(csdn_title, " ")
#----------------------------------------------------
headfilename = mpegfile[0]
printf(headpageid)
if headpageid != 0:
headfilename = mpegfile[headpageid]
image = Image.open(headfilename)
output = BytesIO()
image.convert('RGB').save(output, 'BMP')
data = output.getvalue()[14:]
output.close()
send_to_clipboard(win32clipboard.CF_DIB, data)
tspsendwindowkey(csdn_title, 'v', control=1, noreturn=1)
for i in range(40):
time.sleep(.5)
readdata = tspread()
if readdata[2] == 1: break
if readdata[7] != 0: break
if readdata[8] != 0: exit()
if readdata[9] != 0: exit()
tspsendwindowkey(csdn_title, 'c', control=1, noreturn=1)
if clipboard.paste().find('在这里插入图片描述') >= 0:
tspbeep(1500, 200)
time.sleep(.25)
break
printf('\a')
for i in range(20):
readdata = tspread()
if readdata[7] == 0 and readdata[8] == 0 and readdata[9] == 0: break
tspbeep(2500, 15)
time.sleep(.25)
tspsendwindowkey(csdn_title, 'ac', control=1, noreturn=1)
pastestr = clipboard.paste().split('![在这里插入图片描述](')
if len(pastestr) < 2:
printf("Can not find the ![Insert picture] discriptor !\a")
exit()
tspsendwindowkey(csdn_title, 'z', control=1)
pastestr = pastestr[1].split(')')[0]
pastestr = pastestr.split('?')[0]
#----------------------------------------------------
if pictureflag == 0 and leftwidth > 0:
if len(pagedim) > 1:
dimstr = '-'.join([str(n) for n in pagedim])
leftstring = leftstring + '_=%s'%dimstr
#----------------------------------------------------
insertstr = '![%s](%s#pic_center =%dx)'%(filename, pastestr, picwidth)
if leftwidth > 0:
if leftstring.find('c') < 0 and leftstring.find('C') < 0:
insertstr = '![%s|%s](%s#pic_left =%dx) '%(filename, leftstring, pastestr, leftwidth)
else:
leftstring = leftstring.replace('c', '').replace('C', '')
insertstr = '![%s|%s](%s#pic_center =%dx)\n\n'%(filename, leftstring, pastestr, leftwidth)
if len(originstr) > 0:
clipboard.copy(insertstr+'\n'+originstr)
else: clipboard.copy(insertstr)
tspsendwindowkey(csdn_title, "v", control=1, noreturn=1)
# printf(pastestr)
clipboard.copy("")
#--------------------------------------------------------
if copy_flag > 0:
if not os.path.isdir(r'd:\temp'):
os.mkdir(r'd:\temp')
if not os.path.isdir(r'd:\temp\GIF'):
os.mkdir(r'd:\temp\GIF')
outgifdir = r'd:\temp\GIF\%s'%gifdir
if not os.path.isdir(outgifdir):
os.mkdir(outgifdir)
for id,fn in enumerate(mpegfile):
extstr = fn.split('.')[-1]
outfile = os.path.join(outgifdir, '%04d.%s'%(id, extstr))
shutil.move(fn, outfile)
else:
for id,fn in enumerate(mpegfile):
os.remove(fn)
tspdeletedop(gifiddim)
tsprv(-1)
#----------------------------------------------------
if audacityflag != 0:
rect = tspgetwindowrect(AUDACITY_TITLE)
if sum(rect) != 0:
mp3file = outfilename.split('.')[0] + '.MP3'
AudacitySave(mp3file)
tspfocuswindow('TEASOFT:1')
exit()
#------------------------------------------------------------
avifile = r'd:\temp\1.avi'
wavfile = r'd:\temp\1.wav'
mp3file = r'd:\temp\1.mp3'
mp4file = r'd:\temp\1.mp4'
avinumstr = 'AV%d'%(int(time.time()))
wavnumstr = 'WA%d'%(int(time.time()))
mp3numstr = 'MP%d'%(int(time.time()))
mp4numstr = "MP4%d"%(int(time.time()))
if avimove_flag > 0:
for i in range(100):
avifile = r'd:\temp\%d.avi'%(i+1)
wavfile = r'd:\temp\%d.wav'%(i+1)
mp3file = r'd:\temp\%d.mp3'%(i+1)
mp4file = r'd:\temp\%d.mp4'%(i+1)
flag = 0
avinumstr = 'AV%d'%(int(time.time()))
wavnumstr = 'WA%d'%(int(time.time()))
mp3numstr = 'MP%d'%(int(time.time()))
mp4numstr = "MP4%d"%(int(time.time()))
if os.path.isfile(avifile):
newfile = os.path.join(microvideo_dir, '%s.AVI'%avinumstr)
shutil.copy(avifile, newfile)
avi2csdn(avifile, '%s.AVI'%avinumstr)
os.remove(avifile)
printf("Copy file : %s"%avifile)
flag += 1
if os.path.isfile(wavfile):
filename = '%s.WAV'%wavnumstr
newfile = os.path.join(microvideo_dir, filename)
shutil.copy(wavfile, newfile)
clipboard.copy("【%s】"%(filename))
printf("Copy file : %s"%filename)
tspsendwindowkey(csdn_title, "v", control=1, noreturn=1)
os.remove(wavfile)
flag += 1
if os.path.isfile(mp3file):
filename = '%s.MP3'%mp3numstr
newfile = os.path.join(microvideo_dir, filename)
shutil.copy(mp3file, newfile)
clipboard.copy("【%s】"%(filename))
printf("Copy file : %s"%filename)
tspsendwindowkey(csdn_title, "v", control=1, noreturn=1)
os.remove(mp3file)
flag += 1
if os.path.isfile(mp4file):
filename = '%s.MP4'%mp4numstr
newfile = os.path.join(microvideo_dir, filename)
shutil.copy(mp4file, newfile)
avi2csdn(mp4file, '%s.MP4'%mp4numstr)
# clipboard.copy("【%s】"%(filename))
# tspsendwindowkey(csdn_title, "v", control=1, noreturn=1)
os.remove(mp4file)
printf("Copy file : %s"%filename)
flag += 1
if flag > 0:
time.sleep(1.0)
printf('\a')
else: break
printf('\a')
tspfocuswindow('TEASOFT:1')
exit()
#------------------------------------------------------------
width = 480
height = 320
if len(sys.argv) == 7:
filename, ext = os.path.splitext(sys.argv[1])
filedir = os.path.dirname(sys.argv[1])
gifpage = int(sys.argv[2])
outfile = r'd:\temp\%s_%s_%s'%(sys.argv[5], sys.argv[3], sys.argv[4])
framems = int(sys.argv[6])
frameps = int(1000 / framems)
printff(filedir, ext, outfile, gifpage, frameps)
for i in range(gifpage):
filename = os.path.join(filedir, '%04d%s'%(i, ext))
img = cv2.imread(filename)
mpegfile.append(filename)
height,width,layers=img.shape
size = (width, height)
img_array.append(img)
else:
gifiddim = tspgetgifid()
iddim = []
if len(gifiddim) == 0:
iddim = tspgetselectid()
if len(iddim) == 0:
iddim = hideiddim
if len(iddim) == 0:
printf('DOP has no GIF dop .\a')
exit()
#------------------------------------------------------------
outfile = 'GM%d'%(int(time.time()))
if len(sys.argv) > 1:
if len(sys.argv[1]) > 0:
outfile = sys.argv[1]
frameps = 20
if len(sys.argv) > 2:
framems = int(sys.argv[2])
frameps = int(1000 / framems)
if len(iddim) > 0:
for iidd in iddim:
filename = tspgetdopfile(iidd)
img = cv2.imread(filename)
mpegfile.append(filename)
height,width,layers=img.shape
size = (width, height)
img_array.append(img)
else:
#-----------------------------------------------------
for gifid in gifiddim:
filedir = tspgetdoppath(gifid)
gifpage = tspgetgifpage(gifid)
filename = tspgetdopfile(gifid)
nameonly, ext = os.path.splitext(filename)
for i in range(gifpage):
filename = os.path.join(filedir, '%04d%s'%(i, ext))
img = cv2.imread(filename)
mpegfile.append(filename)
height,width,layers=img.shape
size = (width, height)
img_array.append(img)
#------------------------------------------------------------
outfilename = r'd:\temp\%s_%d_%d.MPG'%(outfile, width, height)
if outfile.find(':') > 0:
outfilename = r'%s.MPG'%(outfile)
out = cv2.VideoWriter(outfilename, cv2.VideoWriter_fourcc(*'MPEG'), frameps, size, True)
#------------------------------------------------------------
if not os.path.isdir(r'd:\temp'):
os.mkdir(r'd:\temp')
if not os.path.isdir(r'd:\temp\GIF'):
os.mkdir(r'd:\temp\GIF')
if not os.path.isdir(r'd:\temp\GIF\MPEG'):
os.mkdir(r'd:\temp\GIF\MPEG')
mpegdir = r'd:\temp\GIF\MPEG'
mpegfiledim = os.listdir(mpegdir)
for f in mpegfiledim:
os.remove(os.path.join(mpegdir, f))
#------------------------------------------------------------
#for i in range(gifpage):
# out.write(img_array[i])
# tspshowinfor('%d '%i)
for id,img in enumerate(img_array):
out.write(img)
tspshowinfor('%d '%id)
newfile = os.path.join(mpegdir, os.path.basename(mpegfile[id]))
# printf(newfile)
shutil.copyfile(mpegfile[id], newfile)
out.release()
#------------------------------------------------------------
printf('\r\nAVI:%s\a'%outfilename)
printf('\a')
#------------------------------------------------------------
# END OF FILE : GIF2MPG.PY
#============================================================