因老師指導使用Jython,Chris兄有教jes4py,請大家踴躍參考Chris兄的筆記,本篇以紀錄觀念方式,節錄老師課堂重點

Chris兄筆記

Python 全攻略 - 第 16 章 與圖片共舞

2024/7/31 分享補充採用vscode + jes4py讀取照片寫法

Untitled

【Python 全攻略 第三屆】週三組 Week 27 - Jython and Images(中)

Brighter

把圖片調亮:把現有的R、G、B的值放大,顏色就會往白色走

def brighter(picture):
	for px in getPixels(picture):
		r= getRed(px)  #取得紅色
		g= getGreen(px) #取得綠色
		b= getBlue(px) #取得藍色
		new_color = makecolor(r*1.3, g*1.3, b*1.3) #數值增加
		setColor(px, new_color)
		
============

f = pickAFile() #當下選擇圖片
p = makePicture(f)
brighter(p) #按enter執行def brighter()
explore(p)  #按enter執行,顯示圖片

Untitled

Fake Sunset (調整顏色)

要讓整張圖片偏紅,要將綠色跟藍色值下降。

def make_sunset(picture):
	for px in getPixels(picture):
		g= getGreen(p)
		b= getBlue(p)
		setBlue(p, b*0.7)
		setGreen(p, g*0.7)
		
============

f = pickAFile() #當下選擇圖片
p = makePicture(f)
make_sunsetr(p) #按enter執行def make_sunset()
explore(p)  #按enter執行,顯示圖片

Untitled