OpenHarmony Flutter长列表优化:ListView.builder实战
2026/10/1 3:46:10
# Image Optimizing# pip install PillowimportPIL# Cropingim=PIL.Image.open("Image1.jpg")im=im.crop((34,23,100,100))# Resizingim=PIL.Image.open("Image1.jpg")im=im.resize((50,50))# Flippingim=PIL.Image.open("Image1.jpg")im=im.transpose(PIL.Image.FLIP_LEFT_RIGHT)# Rotatingim=PIL.Image.open("Image1.jpg")im=im.rotate(360)# Compressingim=PIL.Image.open("Image1.jpg")im.save("Image1.jpg",optimize=True,quality=90)# Bluringim=PIL.Image.open("Image1.jpg")im=im.filter(PIL.ImageFilter.BLUR)# Sharpeningim=PIL.Image.open("Image1.jpg")im=im.filter(PIL.ImageFilter.SHARPEN)# Set Brightnessim=PIL.Image.open("Image1.jpg")im=PIL.ImageEnhance.Brightness(im)im=im.enhance(1.5)# Set Contrastim=PIL.Image.open("Image1.jpg")im=PIL.ImageEnhance.Contrast(im)im=im.enhance(1.5)# Adding Filtersim=PIL.Image.open("Image1.jpg")im=PIL.ImageOps.grayscale(im)im=PIL.ImageOps.invert(im)im=PIL.ImageOps.posterize(im,4)# Savingim.save("Image1.jpg")# Video Optimizer# pip install moviepyimportmoviepy.editoraspyedit# Load the Videovideo=pyedit.VideoFileClip("vid.mp4")# Trimmingvid1=video.subclip(0,10)vid2=video.subclip(20,40)final_vid=pyedit.concatenate_videoclips([vid1,vid2])# Speed up the videofinal_vid=final_vid.speedx(2)# Adding Audio to the videoaud=pyedit.AudioFileClip("bg.mp3")final_vid=final_vid.set_audio(aud)# Reverse the Videofinal_vid=final_vid.fx(pyedit.vfx.time_mirror)# Merge two videosvid1=pyedit.VideoFileClip("vid1.mp4")vid2=pyedit.VideoFileClip("vid2.mp4")final_vid=pyedit.concatenate_videoclips([vid1,vid2])# Add VFX to Videovid1=final_vid.fx(pyedit.vfx.mirror_x)vid2=final_vid.fx(pyedit.vfx.invert_colors)final_vid=pyedit.concatenate_videoclips([vid1,vid2])# Add Images to Videoimg1=pyedit.ImageClip("img1.jpg")img2=pyedit.ImageClip("img2.jpg")final_vid=pyedit.concatenate_videoclips([img1,img2])# Save the videofinal_vid.write_videofile("final.mp4")# PDF to Images# pip install PyMuPDFimportfitzdefpdf_to_images(pdf_file):doc=fitz.open(pdf_file)forpindoc:pix=p.get_pixmap()output=f"page{p.number}.png"pix.writePNG(output)pdf_to_images("test.pdf")# pip install urllib3importurllib3# Fetch API dataurl="https://api.github.com/users/psf/repos"http=urllib3.PoolManager()response=http.request('GET',url)print(response.status)print(response.data)# Post API dataurl="https://httpbin.org/post"http=urllib3.PoolManager()response=http.request('POST',url,fields={'hello':'world'})print(response.status)# Battery Notifier# pip instal plyerfromplyerimportnotificationimportpsutilfromtimeimportsleepwhileTrue:battery=psutil.sensors_battery()life=battery.percentiflife<50:notification.notify(title="Battery Low",message="Please connect to power source",timeout=10)sleep(60)# Grammer Fixer# pip install happytransformerfromhappytransformerimportHappyTextToTextasHappyTTTfromhappytransformerimportTTSettingsdefGrammer_Fixer(Text):Grammer=HappyTTT("T5","prithivida/grammar_error_correcter_v1")config=TTSettings(do_sample=True,top_k=10,max_length=100)corrected=Grammer.generate_text(Text,args=config)print("Corrected Text: ",corrected.text)Text="This is smple tet we how know this"Grammer_Fixer(Text)# Spell Fixer# pip install textblobfromtextblobimport*# Fixing Paragraph Spellsdeffix_paragraph_words(paragraph):sentence=TextBlob(paragraph)correction=sentence.correct()print(correction)# Fixing Words Spellsdeffix_word_spell(word):word=Word(word)correction=word.correct()print(correction)fix_paragraph_words("This is sammple tet!!")fix_word_spell("maangoo")08、# Python Downloader# pip install internetdownloadmanagerimportinternetdownloadmanagerasidmdefDownloader(url,output):pydownloader=idm.Downloader(worker=20,part_size=1024*1024*10,resumable=True,)pydownloader.download(url,output)Downloader("Link url","image.jpg")Downloader("Link url","video.mp4")# World News Fetcher# pip install requestsimportrequests ApiKey="YOUR_API_KEY"url="https://api.worldnewsapi.com/search-news?text=hurricane&api-key={ApiKey}"headers={'Accept':'application/json'}response=requests.get(url,headers=headers)print("News: ",response.json())# PySide 2# pip install PySide2fromPySide6.QtWidgetsimport*fromPySide6.QtGuiimport*importsys app=QApplication(sys.argv)window=QWidget()# Resize the Windowwindow.resize(500,500)# Set the Window Titlewindow.setWindowTitle("PySide2 Window")# Add Buttonsbutton=QPushButton("Click Me",window)button.move(200,200)# Add Label Textlabel=QLabel("Hello Medium",window)label.move(200,150)# Add Input Boxinput_box=QLineEdit(window)input_box.move(200,250)print(input_box.text())# Add Radio Buttonsradio_button=QRadioButton("Radio Button",window)radio_button.move(200,300)# Add Checkboxcheckbox=QCheckBox("Checkbox",window)checkbox.move(200,350)# Add Sliderslider=QSlider(window)slider.move(200,400)# Add Progress Barprogress_bar=QProgressBar(window)progress_bar.move(200,450)# Add Imageimage=QLabel(window)image.setPixmap(QPixmap("image.png"))# Add Message Boxmsg=QMessageBox(window)msg.setText("Message Box")msg.setStandardButtons(QMessageBox.Ok|QMessageBox.Cancel)window.show()sys.exit(app.exec())