Page 1 of 1
read / write EXIF data, simple, no modifications ???
Posted: Wed Aug 13, 2008 7:41 am
by wichtel
Hello,
I have searched the web and the boards to find a simple way to retain EXIF information in an image.
All tools and libs I have found so far har way too big.
I just want to load a jpeg image, and save it again without losing the exif information like:
-loadimage
-get exif block
-do something with the picture
-saveimage
-put exif block
Any ideas?
Posted: Wed Aug 13, 2008 8:01 am
by idle
Posted: Wed Aug 13, 2008 8:04 am
by pdwyer
Posted: Wed Aug 13, 2008 8:15 am
by dige
could you give us a hint? I could'nt find any commands that read / write
exif meta data with gdi :-\
Posted: Wed Aug 13, 2008 9:22 am
by idle
I didn't check to see if its been implemented for PB by Denis but I know that gdi+ does the business.
its as they say, google is your friend!
Posted: Wed Aug 13, 2008 10:04 am
by wichtel
Thanks for the answers.
This gets more complicated than expected.
gdi+ is way overpowerd for what I need. Certainly worth looking into it and learn how to use it, but I am more simple minded.
The exif file format link, seemed to be pretty good.
So reading the exif block would not be a problem.
But when you save an image using SaveImage and the UseJPEGImageEncoder you get a JFIF format. I know that EXIF can be in JFIF, but the trick would be now to insert the EXIF data in the JFIF file.
Still trying to make it as simple as possible:
-check for EXIF marker in image
-load the EXIF data block to memory
-load the image using loadimage
-do whatever with the image
-save the image using saveimage
-insert the EXIF block
Posted: Wed Aug 13, 2008 1:08 pm
by wichtel
Hey, I got a simple code working.
It consists of 3 blocks.
1. I open a file taken from my camera and read out the EXIF data block.
2. I open a file that has been created from the same image using the PB functions loadimage and saveimage and the JPEGencoder. There I read the entire file.
3. I create a new file and merge der EXIF data with the rest of the file.
Not sure if that is 100% correct, but all my graphic tool still can read the created file and the EXIf info is valid.
Code: Select all
#file=1
file$="D:\oppi\PB4\stempel\dscf0452_jfif.JPG"
If ReadFile(#file, file$)
length = Lof(#file)
If (ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF)=$FFD8 ;SOU
Debug "JPG"
APP=(ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF)
If APP=$FFE1 ;APP1
Debug "EXIF"
ssss=(ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF) ;SSSS
Debug Hex(ssss)
FileSeek(#file,4)
*memEXIF = AllocateMemory(ssss)
If *memEXIF
rrrr=ReadData(#file,*memEXIF,ssss)
Debug Hex(rrrr)
EndIf
ElseIf APP=$FFE0 ;APP0
Debug "JFIF"
FileSeek(#file,20)
If (ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF)=$FFE1 ;APP1
Debug "EXIF in JFIF"
ssss=(ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF) ;SSSS
Debug Hex(ssss)
FileSeek(#file,22)
*memEXIF = AllocateMemory(ssss)
If *memEXIF
rrrr=ReadData(#file,*memEXIF,ssss)
Debug Hex(rrrr)
EndIf
EndIf
Else
Debug "no EXIF, no JFIF"
EndIf
Else
Debug "no JPG"
EndIf
CloseFile(#file)
EndIf
file$="D:\oppi\PB4\stempel\dscf0452_ost.JPG"
If ReadFile(#file, file$)
If (ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF)=$FFD8 ;SOU
Debug "JPG"
If (ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF)=$FFE0 ;APP0
Debug "JFIF"
FileSeek(#file,20)
If (ReadByte(#file)&$FF)*256+(ReadByte(#file)&$FF)=$FFDB ;FFDB
FileSeek(#file,0)
Debug Hex(Lof(#file))
*memOst=AllocateMemory(Lof(#file))
If *memOst
rrrr=ReadData(#file,*memOst,Lof(#file))
Debug Hex(rrrr)
EndIf
EndIf
Else
Debug "no JFIF"
EndIf
Else
Debug "no JPG"
EndIf
CloseFile(#file)
EndIf
file$="D:\oppi\PB4\stempel\dscf0452_ost_exif.JPG"
If CreateFile(#file,file$)
WriteData(#file,*memOst,20)
WriteByte(#file,$FF)
WriteByte(#file,$E1)
WriteData(#file,*memEXIF,ssss)
WriteData(#file,*memOst+20,rrrr-20)
CloseFile(#file)
EndIf
edit: updated code for JFIF
Posted: Wed Aug 13, 2008 2:16 pm
by dige
Hmm, does not work here, coz the App1 marker in my jpg pictures is $FFE0.
But if I use the $FFE0 marker instead, only $10 Bytes will copied..
And what about intel & motorola byte order?
Posted: Wed Aug 13, 2008 2:46 pm
by wichtel
@DIGE:
I have updated the code. It is by no means final or perfect, but a simple trick that will probably work for me.
Most pictures right out of a camera are in JPEG-EXIF.
Some pictures are in JPEG-JFIF with EXIF info.
The new code will work with those as well.
I did not care about the byte order yet.
Posted: Thu Aug 14, 2008 7:35 am
by dige
thx, seems to work properly now

Posted: Sun Mar 08, 2009 1:21 pm
by Fangbeast
Wichtel, don't know if you are still around but...can you decode the bits of exif data?
Posted: Sun Mar 08, 2009 5:52 pm
by wichtel
@Fangbeast:
What do you mean with "can you decode exif"?
If you mean if I have written my own EXIF libary - No.
Way too much work. There are so many different info types in there plus vendor specific data...
I thought about extracting just the most needed values. That woul definitly be doable by having a look at the data format and the description in e.g. WiKi. But not yet...
But I could, and you as well, by using an EXIF library. There are several to be found in the net.
e.g.
http://www.gimp.org/~tml/gimp/win32/libexif-0.6.16.zip (from gimp)
Posted: Mon Mar 09, 2009 2:51 am
by Fangbeast
wichtel wrote:@Fangbeast:
What do you mean with "can you decode exif"?
If you mean if I have written my own EXIF libary - No.
Way too much work. There are so many different info types in there plus vendor specific data...
I thought about extracting just the most needed values. That woul definitly be doable by having a look at the data format and the description in e.g. WiKi. But not yet...
But I could, and you as well, by using an EXIF library. There are several to be found in the net.
Hadn't even thought of that, thanks.