编译没有问题但是运行错误 求帮助

学C新手上路 2013-06-22 11:07:56
#include "mydll.h"
#include<stdlib.h>
#include <stdio.h>
#include<math.h>
void main()
{
struct image img1,img2;
FILE *fp1,*fp2;
unsigned char *pdata;unsigned char *pdata1;unsigned char r,b,g;
int i,j,k,sum=0,a[3];

fp1=fopen("G:\\imgest\\Debug\\1.txt","w");
fp2=fopen("G:\\imgest\\Debug\\2.txt","w");
imgfiletomat("G:\\imgest\\Debug\\1.jpg", &img1);
img2.height=img1.height;img2.width=img1.width;img2.numcolors=1;
pdata1=(unsigned char*)malloc(img1.height*img1.width*sizeof(unsigned char));


for(i=0;i<img1.height;i++)
for(j=0;j<img1.width;j++)
for(k=0;k<img2.numcolors;k++){
*pdata1=rand()%255;
pdata1++;
}
img2.ptr=pdata1;

for(i=0;i<img1.height;i++)
{for(j=0;j<img1.width;j++)
for(k=0;k<img2.numcolors;k++)
{
fprintf(fp2,"%5d",*pdata1);
pdata1++;
}
fprintf(fp2,"\n");

}


createwindow("name1");
imgshow("name1",&img2);
wait(0);


mattoimgfile("G:\\imgest\\Debug\\c1.jpg",&img2);

destroywindow("name1");
destroyallwindows();






}
...全文
74 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
学C新手上路 2013-06-22
  • 打赏
  • 举报
回复
太感谢了 改了一下成功了
学C新手上路 2013-06-22
  • 打赏
  • 举报
回复
头文件 #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 关于图像的
hugett 2013-06-22
  • 打赏
  • 举报
回复
缺少了些文件。。有些定义没看到。。 粗略看了一下。。第一个for循环的时候移动了pdata1指针。。循环结束的时候它已经不是指向数组的开始了。。后边第二个for循环fprintf的时候是从数组的末尾开始的。。应该会数组越界。。 应该在第一个循环前保存一下pdata1指针的值。。第二个循环开始前再重新赋值一下。。
  • 打赏
  • 举报
回复
可以结贴了

69,364

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧