开发者社区> 问答> 正文

关于C++6.0的图像水平镜像变换

关于C++6.0的图像水平镜像变换

头文件
#ifdef MYDLL_EXPORTS
#define MYDLL_API __declspec(dllexport)
#else
#define MYDLL_API __declspec(dllimport)
#endif
#ifndef LIB_H
#define LIB_H
struct image
{
unsigned char * ptr;
int numcolors;//3---彩色(排序方式RGB);1----灰度或者黑白图像
int width; /* image width in pixels /
int height; / image height in pixels */
};
#ifdef __cplusplus
extern "C"
{

#endif
//函数声明
MYDLL_API int imgfiletomat(char *filename,struct image *pimage);//-1表示读取图像文件错误;1表示读取正常
MYDLL_API void mattoimgfile(char *filename,struct image *pimage);
MYDLL_API void imgshow(char *windowname,struct image *pimage);

MYDLL_API int wait(int delay);//延迟delay毫秒数。若等于0,则无限制的等待按键事件
MYDLL_API int createwindow(char *windowname);//窗口的名字,它被用来区分不同的窗口,并被显示为窗口标题。 
MYDLL_API void destroywindow(char *windowname);//要被销毁的窗口的名字。 
MYDLL_API void destroyallwindows(void);//销毁所有窗口
#ifdef __cplusplus

}
#endif
#endif
** 运行主程序 ** 
#include "mydll.h"
#include 
#include 
#include
#include
void main()
{
struct image img1;
FILE *fp1;
unsigned char *pdata;
int temp;
int i,j,k=0;
int height,wide;
fp1=fopen("D:\\学习\\imagetest\\imagedsp\\Debug\\1.txt","w");


imgfiletomat("D:\\学习\\imagetest\\imagedsp\\Debug\\1.jpg", &img1);
createwindow("name1");
imgshow("name1",&img1);
wait(0); //等待按键

height=img1.height;
wide=img1.width;
pdata=img1.ptr;
for(i=0;i<height;i++)
for(j=0;j<wide /2*3;j++)
{          
     temp=*(pdata+j);
  *(pdata+j)=*(pdata+j+3*wide-j/3*3*2-3);
  *(pdata+j+3*wide-j/3*3*2-3)=temp;
} 

createwindow("name1");
imgshow("name1",&img1);
wait(0); //等待按键
}

没有错误,但不知道为什么图像没有发生变化

展开
收起
a123456678 2016-03-04 11:59:14 2203 0
1 条回答
写回答
取消 提交回答
  • 代码逻辑有问题,理清思路,从而去实现功能

    2019-07-17 18:52:06
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
使用C++11开发PHP7扩展 立即下载
GPON Class C++ SFP O;T Transce 立即下载
GPON Class C++ SFP OLT Transce 立即下载