|

点击上方蓝字和“好玩的MATLAB”一起快乐玩耍吧!
1 m5 j: n& h( t* `9 V- S# \& a) ]* S
b3u2jmtoti26403006909.jpg
; @; d5 Z1 M$ q i6 }好玩的matlab
* ?/ K) t1 e0 s带你解锁不一样的matlab新玩法
7 p5 G. u7 y; |* W* F2 x. U; V: ^' f! P" H$ L- @" ^
今天介绍一下怎么利用Matlab制作圣诞节专属头像,喜欢此推文的小伙伴们记得点赞+关注+分享!【尊重作者劳动成果,转载请注明推文链接和公众号名】
. d) v( O D# j效果图
6 @3 ]+ h- t' S' A0 ?5 Q
2wt0qpylbec6403007009.png
; ^+ J2 C R& y. f8 R
9 d+ H b6 g- q: n4 y
ce5le3hpmln6403007110.gif
' a3 e5 E s& N( R; o6 j
: j- ^8 ?# N& a5 Z: z0 J程序介绍0 ^7 n( k0 Y# }# X* t
主界面9 w3 N) L" m2 F9 S. ?
function addHatmFig = figure('units', 'pixels', 'position', [400 300 400 600], ... 'Numbertitle', 'off', 'menubar', 'none', 'resize', 'on', ... 'name', '公众号:好玩的Matlab');axes('parent', mFig, 'position', [0 0 1 1], ... 'XLim', [0 400], ... 'YLim', [-200 400], ... 'NextPlot', 'add', ... 'YDir', 'reverse', ... 'XTick', [], ... 'YTick', [],... 'layer', 'bottom', ... 'Visible', 'on');[avatar, ~, ~] = imread('tx1.jpg');[decorImg, ~, alphaImg] = imread('./img/2.png');ImgResult=image([0 400], [0 400], avatar);添加帽子hatPos = [200, 40];[n, m, ~] = size(decorImg);enlarge=0.08;DrawHatHdl = image([hatPos(1) - m* enlarge hatPos(1) + m* enlarge], ... [hatPos(2) - n* enlarge hatPos(2) + n* enlarge], decorImg, 'AlphaData', alphaImg);DrawHatHdl.HitTest = 'on';鼠标监听代码set(gcf,'WindowButtonDownFcn', @clickBoat); function clickBoat(~, ~) clickType = get(gcf, 'SelectionType'); XY = get(gca, 'CurrentPoint'); if strcmp(clickType, 'normal') Y = XY(1, 2); X = XY(1, 1); set(DrawHatHdl, 'XData', [X - m* enlarge X + m* enlarge], 'YData', [Y - n* enlarge Y + n* enlarge]); elseif strcmp(clickType, 'alt') Y = XY(1, 2); X = XY(1, 1); enlarge=enlarge*1.1; set(DrawHatHdl, 'XData', [X - m*enlarge X + m*enlarge], 'YData', [Y - n*enlarge Y + n*enlarge]); end endend
; V( B* L3 F% u: T- g# k操作方法:鼠标右击放大帽子鼠标左击移动帽子位置全部代码* @; m+ N' l7 @) V4 g
function addHatmFig = figure('units', 'pixels', 'position', [400 300 400 600], ... 'Numbertitle', 'off', 'menubar', 'none', 'resize', 'on', ... 'name', '公众号:好玩的Matlab');axes('parent', mFig, 'position', [0 0 1 1], ... 'XLim', [0 400], ... 'YLim', [-200 400], ... 'NextPlot', 'add', ... 'YDir', 'reverse', ... 'XTick', [], ... 'YTick', [],... 'layer', 'bottom', ... 'Visible', 'on');[avatar, ~, ~] = imread('tx1.jpg');[decorImg, ~, alphaImg] = imread('./img/2.png');ImgResult=image([0 400], [0 400], avatar);hatPos = [200, 40];[n, m, ~] = size(decorImg);enlarge=0.08;DrawHatHdl = image([hatPos(1) - m* enlarge hatPos(1) + m* enlarge], ... [hatPos(2) - n* enlarge hatPos(2) + n* enlarge], decorImg, 'AlphaData', alphaImg);DrawHatHdl.HitTest = 'on';4 ?5 _' A& Q0 X1 D+ i: P8 |
set(gcf,'WindowButtonDownFcn', @clickBoat); function clickBoat(~, ~) clickType = get(gcf, 'SelectionType'); XY = get(gca, 'CurrentPoint'); if strcmp(clickType, 'normal') Y = XY(1, 2); X = XY(1, 1); set(DrawHatHdl, 'XData', [X - m* enlarge X + m* enlarge], 'YData', [Y - n* enlarge Y + n* enlarge]); elseif strcmp(clickType, 'alt') Y = XY(1, 2); X = XY(1, 1); enlarge=enlarge*1.1; set(DrawHatHdl, 'XData', [X - m*enlarge X + m*enlarge], 'YData', [Y - n*enlarge Y + n*enlarge]); end endend
3 K5 @5 w# C' N k$ P
23bhmawuxnl6403007210.png
' V4 v/ |5 c. b* H; S) N) M' K
, o. T/ ?1 C! \9 G5 J4 J* M小编根据原理又做了APP操作界面
7 m K* d3 o" ?
15mbqeegkg56403007311.png
6 A4 }- t- k6 Q i8 K T
# S' _- E2 V! e4 q: x2 W
- -THE END- -
/ V0 b! f: C+ q6 q' P& X0 `) y0 {' t5 W
源码下载:gitee下载:https://gitee.com/LoveMatlab/addHat4 J, X0 Y' s/ F) i; N
xucswocmzni6403007411.png
9 g3 M& `7 r+ }8 V& ^! D# t: h" d" n9 K% j7 o
QQ 群下载:0 p( t' w7 K% x( G. S( x
j4vd2pnzccr6403007511.png
, R4 H+ [ p+ { e
7 k& L) d! p$ M! W e* c; O参考资料:; m; n6 z: N. V% x; m4 f0 N# J' V
【1】https://slandarer.blog.csdn.net/article/details/118368777【2】https://mp.weixin.qq.com/s/mRIImZK-bLJWrZwVtkrhfw |
|