完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
您好,我想用FSRead将位图写入动态分配的数组,但是它不起作用。程序停止在FuffFyRead(&文件,和BITMAPIMAGE,BI.BISIZIMAGE,和大小)中,而不是AHEAD。IbI.BISIZEIMAGE是192。当我向静态表写入数据时,它正在工作。
以上来自于百度翻译 以下为原文 Hello, I want to write bitmap by the F_read to the table with dynamic allocated array but it's dosen't work. The program stop in function f_read(&file,&bitmapImage,Bi.biSizeImage,&size) and don't go to ahead. In Bi.biSizeImage is 192. int readBitMap(char *FileName) { FRESULT result; FIL file; UINT size; uint8_t *bitmapImage; int a=0,j=0; if((result = f_open(&file,FileName,FA_READ))==FR_OK) { /*Reading the BitMap*/ printf("File opened ! n"); f_read(&file,&Bf,sizeof(Bf),&size); f_read(&file,&Bi,sizeof(Bi),&size); bitmapImage = malloc(Bi.biSizeImage); printf("size image: %dn",Bi.biSizeImage); f_lseek(&file,138); f_read(&file,&bitmapImage,Bi.biSizeImage,&size); f_close(&file); return 1; }else printf("Error in 'Open': %dn",result); return 0; } When I was writing data to the static table, it was working. |
|
相关推荐
8个回答
|
|
“不起作用”是什么意思?您没有检查从MalCube()返回的内容。
以上来自于百度翻译 以下为原文 What does “doesn’t work” mean? You are not checking the return from malloc() |
|
|
|
嗨,哪个处理器?XC32的哪种版本?你使用和声吗?哪个版本?当做
以上来自于百度翻译 以下为原文 Hi, Which processor ? Which version of XC32 ? Do you use Harmony ? which version ? Regards |
|
|
|
因为我没有完整的源程序,所以我不知道你所显示的代码中是否有任何错误(或者,尤其是在你没有显示的代码中),但是我认为这里有一个很大的问题:fxRead()的第二个参数是一个指向无符号字符的指针,对吗?它的值将是存储器中存储信息的区域的地址。[编辑](也许函数是用这个参数定义为一个空指针,但是函数将在拷贝时把它的值作为一个指向char的指针。[/Ed])无论如何,第二个参数应该是BITMAPIMAGE,而不是和BITMAPMAIZIZE。BITMAP映像的值是你的“动态分配的数组”中第一个元素的地址,但是,BITMAPIMAGE是变量BITMAP映像的地址,而不是内存中分配区域开始的地址。现在……如果使用类似的Co,你可能会侥幸逃脱它的原因。对于一个已声明的数组,de是,如果你有下面这样的东西。假设你有一个表达式(没有[]括号)本身使用的x,它是指向uut88t的指针,它的值是数组的第一个元素的地址。调用fxRead()中的第二个参数应该是x,而不是& x;然而实际上,因为&和x是指向数组的指针,所以碰巧的是,数组的第一个元素的地址是。由于x和x具有与x相同的数值,这个特殊函数“工作”。我认为,即使在数组的情况下显然是“工作”的,也会养成使用不当的习惯。如果使用char数组中的地址,则使用一个指向char的指针,一些编译器会发出警告。但是,如果函数的参数定义是一个空指针,编译器可能不会把你保释出来。当然,正如NKurzman指出的,你应该总是检查MalCube()和它的兄弟姐妹的返回值以确保它是成功的(虽然我不知道如果失败了,你应该怎么做)。这就是为什么我尽量避免动态分配的原因。我的意思是,如果你要分配一次并且从不释放它,为什么不使用一个声明的数组呢?如果你要释放它,那么,为了上帝的缘故,返回Maloc给你的价值,这样你就可以解除它了!顺便说一下,因为你在阅读之后回来了,但是从来没有对存储的图像做任何事情,而且在那个函数之外什么也不可能知道它在哪里,有什么意义?最后,我注意到,在不同的微芯片分布(以及来自其他来源的代码的许多例子)中,源代码使用了和数组X,其中应该使用X。代码“工作”,但作为一个很坏的例子,人们不应该复制。问候,戴夫
以上来自于百度翻译 以下为原文 Since I don't have your entire source program, I don't know whether anything else is wrong in the code that you show (or, especially, in the code that you don't show), but I think there is a Very Big Problem here: The second parameter of f_read() is a pointer to unsigned char, right? Its value will be the address of a region in memory where the information will be stored. [Edit](Maybe the function is defined with that parameter as a void pointer, but the function will use its value as a pointer to char when it copies the stuff.)[/Edit] Anyhow, the second argument should be bitmapImage, not &bitmapImage. See? the value of bitmapImage is the address of the first element in your "dynamically allocated array," but &bitmapImage is the address of the variable bitmapImage, not the address of the beginning of the allocated region in memory. Now... The reason you might 'get away with it' if you use similar code for a declared array is that if you have something like the following. Suppose you have uint8_t x[80]; Then... x used by itself in an expression (without [] brackets), is a pointer to uint8_t, and its value is the address of the first element of the array. The second argument in the call to f_read() should be x, not &x. However... In fact, since &x is the pointer to an array, it happens that the value of &x is the address of the first element of the array. Since &x has the same numerical value as x, this particular function "works." I think it's a Very Bad Thing to get into the habit of improper usage even though it apparently "works" in the case of arrays. Some compilers give a warning if you use the address of an array of char where a pointer to char should be used. If, however, the function's definition of the parameter was a void pointer, the compiler might not bail you out. You have to do it right. And, of course, as NKurzman pointed out, you should always check the return value of malloc() and its siblings to make sure it was successful (although I don't know what you should/can do about it if it fails). That's why I try to avoid dynamic allocation where possible. I mean, if you are going to allocate this once and never free it, why not just use a declared array? And if you are going to free it, then, for goodness sake, return the value that malloc gave you so that you can deallocate it! And, by the way, since you return after reading, but never do anything with the stored image and nothing outside that function can possibly know where it is, what's the point? Finally... I have noted, from time to time, that source code in various Microchip distributions (as well as many examples of code from other sources) uses &x for array arguments where x should have been used. The code "works," but serves as a Very Bad Example that people should not copy. Regards, Dave |
|
|
|
谢谢大家的关心!首先,我检查了从MalROCK返回,我发现我必须增加堆大小。接下来,像SaDaveKW7xSead参数必须BeBAPMMAIL图像没有“&”。我必须制作动态数组,因为我想加载不同分辨率的照片。我将添加我不能使用PrRor,因为我得到:是的,我已经定义了包含和ltSdio.h & gt;而不是这一点,我使用了:PrtTf(“%s n”,SrrError(ErrNO));FasRelo.h库,非常感谢您的响应;
以上来自于百度翻译 以下为原文 Thanks everyone for interest ! For first I check returned from malloc and I found out that I must increase Heap size. Next that like said davekw7x second argument must be bitmapImage without "&". I must make dynamic array because I want to load photo with different resolution. I will add that I can't use perror because I get: liblega-c.a(perror.o): In function `perror': perror.c:(.text.perror+0xb4): undefined reference to `writev' Yes, I have defined #include Instead of this, I used: printf("%sn",strerror(errno)); from errno.h library Very thanks for response ;) |
|
|
|
如果MalCube()失败,它返回一个空指针,所以你可以检查它。(而不是依赖于全局Erro变量)戴夫
以上来自于百度翻译 以下为原文 If malloc() fails, it returns a null pointer, so you can check that. (Rather than depending on the global errno variable.) Regards, Dave |
|
|
|
AAK OK,我理解:但是我认为这个程序不起作用,我把所有位图读入缓冲区,然后把它发送到LCD。当我的文件将大于58KB(自由内存),那么它就不工作了。所以我必须读取一些位图,把它发送到LCD,重新读取内存并再次发送??
以上来自于百度翻译 以下为原文 Aaa ok I understandLoL: But I think this program dosen't work, I reading all bitmap to the buffer and next sent it to the LCD. When my file will by larger than 58kB (free memory), then it's dosen't work. So I must read some block of bitmap sending it to the LCD, read again memory and send again ?? |
|
|
|
难道不需要分配()MalCube()分配的内容吗?我在你发布的代码中没有看到这一点。
以上来自于百度翻译 以下为原文 Don't you need to free() what malloc() allocates? I don't see that in the code you posted. |
|
|
|
是的,我需要,但我必须改变程序,因为我不能读取大照片,所以我改变程序读取512字节,发送到LCD,并再次读取。
以上来自于百度翻译 以下为原文 Yes I need, but I must change program because I can't read large photo, so I change program to read 512 byte, send to LCD and again read. |
|
|
|
只有小组成员才能发言,加入小组>>
5204 浏览 9 评论
2016 浏览 8 评论
1942 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3188 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2244 浏览 5 评论
754浏览 1评论
641浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
549浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
653浏览 0评论
553浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-5 10:33 , Processed in 1.418300 second(s), Total 60, Slave 54 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号