controlr
asked on
image to hex and hex to image
hello experts!
can someone help me with converting image to hexadecimal and hexadecimal to image?
like at the .dfm..
thanks
can someone help me with converting image to hexadecimal and hexadecimal to image?
like at the .dfm..
thanks
ASKER
nice but i cant put an image on it :(
i want to convert image to hexdecimal..
put an image on a form (with a pic inside) and save it then open the .dfm file
go to picture.data and you will understand what im looking for.
and thanks for the comment :)
i want to convert image to hexdecimal..
put an image on a form (with a pic inside) and save it then open the .dfm file
go to picture.data and you will understand what im looking for.
and thanks for the comment :)
if you are trying to read from a dfm, why not use the delphi standard component streaming mechanism?
you read up the dfm, extract the image part, save it into a stringstream and then load the timage from it.
is this what you are trying to accomplish? if not, what? because you said "like dfm". I need to know exactly in order to give exact code.
you read up the dfm, extract the image part, save it into a stringstream and then load the timage from it.
is this what you are trying to accomplish? if not, what? because you said "like dfm". I need to know exactly in order to give exact code.
ASKER
yeah something like that but i want to do it at the code.
for example:
i have a pick a jpg file with the open dialog
and then in the code i convert it to hexadecimal (all the jpg is now just a big block of numbers)
for example:
i have a pick a jpg file with the open dialog
and then in the code i convert it to hexadecimal (all the jpg is now just a big block of numbers)
Uhh like this?
function FileToHex(FileName: String): String;
var
F : DWORD;
Buffer : PChar;
FileSize : DWORD;
BytesRead : DWORD;
I : DWORD;
begin
Result := '';
F := CreateFile(PChar(FileName),GENERIC_READ,0,nil,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN);
If F = INVALID_HANDLE_VALUE Then Exit;
Try
FileSize := SetFilePointer(F,0,nil,FILE_END);
If FileSize = 0 Then Exit;
SetFilePointer(F,0,nil,FILE_BEGIN);
Buffer := AllocMem(FileSize);
If Buffer = nil Then Exit;
Try
ReadFile(F,Buffer^,FileSize,BytesRead,nil);
If BytesRead <> FileSize Then Exit;
For I := 0 To BytesRead Do
begin
Result := Result + IntToHex(Byte(Buffer^),2);
Inc(Buffer);
end;
Finally
FreeMem(Buffer);
end;
Finally
CloseHandle(F);
end;
end;
and what do you do with that "hexadecimal" string? (because I have the feeeling that you don't really want that delphi streaming thing, but that base64 thing I posted earlier)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window