點(diǎn)擊上方藍(lán)字和“好玩的MATLAB”一起快樂玩耍吧!
mcgvn00vhm264015135611.jpg (236.67 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
mcgvn00vhm264015135611.jpg
2024-9-9 17:21 上傳
好玩的matlab
帶你解鎖不一樣的matlab新玩法
今天介紹一下怎么利用Matlab制作圣誕節(jié)專屬頭像,喜歡此推文的小伙伴們記得點(diǎn)贊+關(guān)注+分享!【尊重作者勞動(dòng)成果,轉(zhuǎn)載請(qǐng)注明推文鏈接和公眾號(hào)名】
效果圖
55rlfsfevak64015135711.png (219.1 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
55rlfsfevak64015135711.png
2024-9-9 17:21 上傳
hlddyhowqfm64015135812.gif (3.92 MB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
hlddyhowqfm64015135812.gif
2024-9-9 17:21 上傳
程序介紹
主界面
function addHatmFig = figure('units', 'pixels', 'position', [400 300 400 600], ... 'Numbertitle', 'off', 'menubar', 'none', 'resize', 'on', ... 'name', '公眾號(hào):好玩的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';鼠標(biāo)監(jiān)聽代碼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
操作方法:鼠標(biāo)右擊放大帽子鼠標(biāo)左擊移動(dòng)帽子位置全部代碼
function addHatmFig = figure('units', 'pixels', 'position', [400 300 400 600], ... 'Numbertitle', 'off', 'menubar', 'none', 'resize', 'on', ... 'name', '公眾號(hào):好玩的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
0z05kwep1kg64015135912.png (342.04 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
0z05kwep1kg64015135912.png
2024-9-9 17:21 上傳
小編根據(jù)原理又做了APP操作界面
khiysbrv2td64015136012.png (396.34 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
khiysbrv2td64015136012.png
2024-9-9 17:21 上傳
- -THE END- -
源碼下載:gitee下載:https://gitee.com/LoveMatlab/addHat
yvrrjuklmoe64015136113.png (69.13 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
yvrrjuklmoe64015136113.png
2024-9-9 17:21 上傳
QQ 群下載:
kdhxrh0gbao64015136213.png (514.09 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
kdhxrh0gbao64015136213.png
2024-9-9 17:21 上傳
參考資料:
【1】https://slandarer.blog.csdn.net/article/details/118368777【2】https://mp.weixin.qq.com/s/mRIImZK-bLJWrZwVtkrhfw |