![]() |
| | #1 |
| Registered User Join Date: Jun 2009
Posts: 14
| Char [] to Image File (JPEG) Thank you |
| TranT is offline | |
| | #2 |
| Guest Join Date: Aug 2001
Posts: 4,922
| Post the code that's giving you trouble. |
| Sebastiani is offline | |
| | #3 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,943
| This works for me: Code: #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int size=0;
char image[250000] = {0};
FILE *in = fopen(argv[1],"r"), *out;
size = fread(image,1,250000,in);
fclose(in);
out = fopen("test.jpg","w");
fwrite(image,1,size,out);
return 0;
}
while (fread(image,1,1,in)) size++; ie, call it multiple times, the jpg does not come out.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is online now | |
| | #5 |
| Guest Join Date: Aug 2001
Posts: 4,922
| >> I tried writing into a file with fwrite You're should be checking the return value of fwrite. I've never used that library so I have no idea if you're using it correctly. Double check the documentation and make sure you are calling all of the functions properly, but IMO, this is probably not an fwrite issue... |
| Sebastiani is offline | |
| | #6 |
| Registered User Join Date: Jun 2009
Posts: 14
| I am getting the things from the structure correctly because i checked the "piclength" and it is the same as the written file but i don't see the image at all :s |
| TranT is offline | |
| | #7 |
| Guest Join Date: Aug 2001
Posts: 4,922
| >> I am getting the things from the structure correctly because i checked the "piclength" and it is the same as the written file but i don't see the image at all :s How are you loading the image? |
| Sebastiani is offline | |
| | #8 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,943
| Quote:
You may have to start with a method that you can get to work and slowly adapt it to your needs.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS | |
| MK27 is online now | |
| | #9 |
| Registered User Join Date: Jun 2009
Posts: 14
| How are you loading the image? The image is stored in a smartcard and I think that the image data is in that unsigned char picture[PTEID_MAX_PICTUREH_LEN]! You may have to start with a method that you can get to work and slowly adapt it to your needs. What method :x? |
| TranT is offline | |
| | #10 | ||
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,943
| Quote:
./a.out somepicture.jpg and it will copy this to "test.jpg". The two files will be identical. Quote:
But you have to be certain about the source you are dealing with. Have you been able to view the jpeg on the smart card using normal means? A smart card is just a small filesystem (generally). What kind of file is the image in? A .jpg? There is more than one kind of image file, so if it is not already explicitly a jpeg, of course writing it to "somefile.jpg" will not work...
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS | ||
| MK27 is online now | |
| | #11 |
| Registered User Join Date: Jun 2009
Posts: 14
| From what I've read i know that the picture is compressed in JPEG/JPEG2000 and in the PTEID API the only function I have is : long PTEID_GetPic(PTEID_PIC *PicData) - Read the picture PicData : OUT -> The address of the record PTEID_PIC |
| TranT is offline | |
| | #12 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,943
| Quote:
I was just looking at your pastebin code again. I don't think "wb" is a proper argument to fwrite() -- it is just for the lowest level write(). Anyway, going by my example, it is not necessary, so try with just "w". Another *possible* problem: Code: PTEID_PIC pic; ret= PTEID_GetPic(&pic);
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS | |
| MK27 is online now | |
| | #13 |
| Registered User Join Date: Jun 2009
Posts: 14
| I've tried fwrite() with "w" with no success and changed the PTEID_PIC pic to a pointer and got the same result :x. I've also tried chaging the fwrite(..,..,sizeof(pic->picture),..) and didn't work too :/ http://pastebin.com/m7017e58a Any more ideas? Last edited by TranT; 06-30-2009 at 07:15 AM. |
| TranT is offline | |
| | #14 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,943
| The only thing I can think of is that these two things: Code: unsigned char imageinfo[PTEID_MAX_IMAGEINFO_LEN]; unsigned char picture[PTEID_MAX_PICTUREH_LEN]; Here's a link I just found, not very promising I'm afraid: http://www.fastgraph.com/help/jpeg_header_format.html altho apparently the first two bytes are always "0xFFD8" Kinda sketchy tho. I guess you are "hacking" an interface of some sort here, as opposed to following an actual API?
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS Last edited by MK27; 06-30-2009 at 07:21 AM. |
| MK27 is online now | |
| | #15 | |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,943
| Quote:
Code: #include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
char buffer[128];
FILE *in = fopen(argv[1],"r");
fread(buffer,128,1,in);
printf("%x %x\n",buffer[0],buffer[1]);
return 0;
}
ffffffff ffffffd8
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS | |
| MK27 is online now | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Another syntax error | caldeira | C Programming | 31 | 09-05-2008 01:01 AM |
| C++ ini file reader problems | guitarist809 | C++ Programming | 7 | 09-04-2008 06:02 AM |
| Game Pointer Trouble? | Drahcir | C Programming | 8 | 02-04-2006 02:53 AM |
| Need help understanding info in a header file | hicpics | C Programming | 8 | 12-02-2005 12:36 PM |
| File Input / Output Help? | Unregistered | C Programming | 3 | 05-18-2002 10:20 AM |