好玩的MATLAB 发表于 2023-12-22 21:49:00

MATLAB|制作圣诞节专属头像

点击上方蓝字和“好玩的MATLAB”一起快乐玩耍吧!

好玩的matlab
带你解锁不一样的matlab新玩法

今天介绍一下怎么利用Matlab制作圣诞节专属头像,喜欢此推文的小伙伴们记得点赞+关注+分享!【尊重作者劳动成果,转载请注明推文链接和公众号名】
效果图




程序介绍
主界面
[*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*]function addHatmFig = figure('units', 'pixels', 'position', , ...    'Numbertitle', 'off', 'menubar', 'none', 'resize', 'on', ...    'name', '公众号:好玩的Matlab');axes('parent', mFig, 'position', , ...    'XLim', , ...    'YLim', [-200 400], ...    'NextPlot', 'add', ...    'YDir', 'reverse', ...    'XTick', [], ...    'YTick', [],...    'layer', 'bottom', ...    'Visible', 'on'); = imread('tx1.jpg'); = imread('./img/2.png');ImgResult=image(, , avatar);添加帽子[*][*][*][*][*][*]hatPos = ; = size(decorImg);enlarge=0.08;DrawHatHdl = image(, ...    , 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', , 'YData', );      elseif strcmp(clickType, 'alt')            Y = XY(1, 2);            X = XY(1, 1);            enlarge=enlarge*1.1;            set(DrawHatHdl,'XData', , 'YData', );      end    endend
操作方法:[*]鼠标右击放大帽子[*]鼠标左击移动帽子位置全部代码
[*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*][*]function addHatmFig = figure('units', 'pixels', 'position', , ...    'Numbertitle', 'off', 'menubar', 'none', 'resize', 'on', ...    'name', '公众号:好玩的Matlab');axes('parent', mFig, 'position', , ...    'XLim', , ...    'YLim', [-200 400], ...    'NextPlot', 'add', ...    'YDir', 'reverse', ...    'XTick', [], ...    'YTick', [],...    'layer', 'bottom', ...    'Visible', 'on'); = imread('tx1.jpg'); = imread('./img/2.png');ImgResult=image(, , avatar);hatPos = ; = size(decorImg);enlarge=0.08;DrawHatHdl = image(, ...    , 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', , 'YData', );      elseif strcmp(clickType, 'alt')            Y = XY(1, 2);            X = XY(1, 1);            enlarge=enlarge*1.1;            set(DrawHatHdl,'XData', , 'YData', );      end    endend


小编根据原理又做了APP操作界面


- -THE END- -

源码下载:gitee下载:https://gitee.com/LoveMatlab/addHat


QQ 群下载:


参考资料:
【1】https://slandarer.blog.csdn.net/article/details/118368777【2】https://mp.weixin.qq.com/s/mRIImZK-bLJWrZwVtkrhfw
页: [1]
查看完整版本: MATLAB|制作圣诞节专属头像