Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to enlarge and reduce the size of a picture in C language

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

这篇文章主要介绍"C语言如何实现图片放大缩小",在日常操作中,相信很多人在C语言如何实现图片放大缩小问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"C语言如何实现图片放大缩小"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

最终项目描述和效果

鼠标按小图,左键图片缩小,右键图片放大。

代码如下

代码大致的思路就是,当鼠标点击指定的地方时。

将图片的长宽,变化,在贴图。

使用: 将图片命名为1.jpg,并将其放在和.cpp文件同一文件夹下。

#include#include#includeIMAGE maxImg;//大图IMAGE minImg;//小图struct picture{ int width;//宽 int langth;//长 int value;//比率};struct picture a={400,400,2};void jia()//加载图片{ loadimage(&maxImg,"1.jpg"); loadimage(&minImg,"1.jpg",60,60);}void show_p()//显示图片{ putimage(20,20,&minImg); putimage(100,0,a.width,a.langth,&maxImg,0,0);}void show(){ setbkcolor(WHITE);//设置窗口背景颜色 cleardevice();//刷新一下 setlinecolor(BLACK);//设置线的颜色 setlinestyle(PS_SOLID,5);//设置线的样式 //画矩形 rectangle(0,0,500,400); rectangle(0,0,100,400); rectangle(0,133,100,133*2); //显示文字 settextcolor(GREEN); settextstyle(20,0,"黑体"); outtextxy(10,180,"左键缩小"); outtextxy(10,320,"右键放大"); show_p();}void to_small(){ if(a.langth!=1&&a.width!=1) //不能让长宽等于1,如果等于1的话那么长宽就会变为0,再次变大就有问题了. { a.width/=a.value; a.langth/=a.value; } loadimage(&maxImg,"1.jpg",a.width,a.langth);}void to_big(){ a.width*=a.value; a.langth*=a.value; loadimage(&maxImg,"1.jpg",a.width,a.langth);}void mouse(){ MOUSEMSG m; while(1) { BeginBatchDraw();//双缓存绘图,解决闪屏问题 show(); m=GetMouseMsg(); switch(m.uMsg) { case WM_LBUTTONDOWN://左键 if(20

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report