Page 1 of 1
Change a byte in memory
Posted: Thu Jun 23, 2011 3:32 pm
by SPH
Code: Select all
UseJPEGImageDecoder()
file$ = OpenFileRequester("Sélectionnez un fichier","","JPG (.jpg)|*.jpg|All files (*.*)|*.*",0)
If file$
If ReadFile(0, file$)
length = Lof(0) ; Lit la taille en octets du fichier
*MemoryID = AllocateMemory(length) ; alloue un bloc mémoire de la taille du fichier
If *MemoryID
bytes = ReadData(0, *MemoryID, length) ; Lit les données du fichier et les place dans le bloc mémoire
EndIf
CloseFile(0)
EndIf
EndIf
Resultat = CatchImage(0, *MemoryID, length)
I want to delete the first byte on the memoryID
What is the instruction ?
Re: Change a byte in memory
Posted: Thu Jun 23, 2011 3:44 pm
by Peyman
you can use pokeB to set the first byte null :
Re: Change a byte in memory
Posted: Thu Jun 23, 2011 3:55 pm
by STARGÅTE
Or you can use a Byte-Array like:
Code: Select all
Structure ByteArray
b.b[0]
EndStructure
Define Text.s = "Some Text"
Define *MemoryID.ByteArray = @Text
; change a byte
*MemoryID\b[4] = '!'
Debug Text
Re: Change a byte in memory
Posted: Thu Jun 23, 2011 4:01 pm
by tinman
Even if you set the first byte to null you'd have to change the address you use in the call to CatchImage() to be "*MemoryID + 1" and reduce length by 1, otherwise it would not be a correctly formatted JPEG image in memory.
Why not just read only what you need?
Code: Select all
UseJPEGImageDecoder()
file$ = OpenFileRequester("Sélectionnez un fichier","","JPG (.jpg)|*.jpg|All files (*.*)|*.*",0)
If file$
If ReadFile(0, file$)
length = Lof(0) - 1 ; Lit la taille en octets du fichier
*MemoryID = AllocateMemory(length) ; alloue un bloc mémoire de la taille du fichier
If *MemoryID
FileSeek(0, 1)
bytes = ReadData(0, *MemoryID, length) ; Lit les données du fichier et les place dans le bloc mémoire
EndIf
CloseFile(0)
EndIf
EndIf
Resultat = CatchImage(0, *MemoryID, length)
Re: Change a byte in memory
Posted: Thu Jun 23, 2011 4:14 pm
by SPH
Ho, thx

Re: Change a byte in memory
Posted: Fri Jun 24, 2011 5:10 pm
by epidemicz
STARGÅTE wrote:Or you can use a Byte-Array like:
Code: Select all
Structure ByteArray
b.b[0]
EndStructure
Define Text.s = "Some Text"
Define *MemoryID.ByteArray = @Text
; change a byte
*MemoryID\b[4] = '!'
Debug Text
Wow, that's a great example, much more elegant than what would have done :/
Code: Select all
Define Text.s = "Some Text"
Define *MemoryID = @Text
; change a byte
PokeC(*MemoryID+4, Asc("!"))
Debug Text