生活随笔
收集整理的這篇文章主要介紹了
项目: 图片放大缩小。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
最終項目描述和效果
鼠標按小圖,左鍵圖片縮小,右鍵圖片放大。
代碼如下
代碼大致的思路就是,當鼠標點擊指定的地方時。
將圖片的長寬,變化,在貼圖。
使用: 將圖片命名為1.jpg,并將其放在和.cpp文件同一文件夾下。
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
IMAGE 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){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<=m
.x
&&m
.x
<=80&&m
.y
>=20&&m
.y
<=80){to_small();}break;case WM_RBUTTONDOWN
:if(20<=m
.x
&&m
.x
<=80&&m
.y
>=20&&m
.y
<=80){to_big();}break;}EndBatchDraw();}
}
int main(void)
{initgraph(500,400);show();jia();mouse();return 0;
}
總結
以上是生活随笔為你收集整理的项目: 图片放大缩小。的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。