Page 1 of 2

Base64Decode....again

Posted: Thu Feb 12, 2015 4:44 pm
by Thalor
I know this has been hashed and rehashed, but I cannot get this to work at all.

I have

Two image areas (Image1, Image2)
Two Buttons (Button1, Button2)
One Text field (text)

I'm trying a proof of concept for future development. (I NEED to store images in a DB)

At any rate the way it is supposed to go is:

1. I load a picture into Image1 (using the properties inspector)
2. Pushing button1 it will base64encrypt the imagedata of Image1 and store it in field "text"
3. Pushing button2 it will base64decrypt field "text" and place it into Image2


What I have for script:

Button1

Code: Select all

on mouseUp
   put base64encode(the imagedata of image "Image1") into field "text"
end mouseUp
Button2

Code: Select all

on mouseUp
   local decodedBinData
   put base64decode (field "text") into decodedBinData
   put decodedBinData into img "Image2"
end mouseUp
What happens:

When I push button1 it does put what appears to be a text string into field "text"
When I push button2 it doesnt put the image back into Image2

I've searched and read, re-read and copied all I can. Now I make an impassioned plea for some help.

Thanks in advance.

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 4:57 pm
by Klaus
Hi Thalor,

1. welcome to the forum! :D

2. I think when saving the IMAGEDATA, then you will also have to set it again!

Try this:

Code: Select all

on mouseUp
   local decodedBinData
   put base64decode (field "text") into decodedBinData
   set the imagedata of img "Image2" to decodedBinData
end mouseUp
Hint:
Using and setting imagedata requires that both images (source and target) have the SAME (sic!) dimensions (width and height)!
If that is not the case, you will get some more or less colorful garbage :D


Best

Klaus

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 5:04 pm
by Thalor
One word. D'oh

Thank you so much. I can't believe how I missed that.

Thanks for the quick reply. I can get back to regrowing the hair that I pulled out.

T

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 5:27 pm
by Klaus
Thalor wrote:I can get back to regrowing the hair that I pulled out.
Good luck! :D

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 5:31 pm
by Thalor
Interesting thing.

It all works. I can select an image. Put it into Image1, encode it and store it in MYSQL. I can retrieve it from MYSQL, decode and put it in Image2

HOWEVER

If Image1 and Image2 are different sizes (Height and Width) the image gets messed up

Any ideas?

I've been looking at re-sizing but all the examples are going from larger to smaller. I need to make it larger from a smaller.

It messes the image when I attempt it.

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 5:54 pm
by FourthWorld
Odd: when I first ran your code I also got a blank img 2. But then I manually rewrote the handler, and now it works.

At first I thought perhaps there might be some odd non-printing character in the script, but then I went back and pasted your code again and now it works still.

At this point I can't find a way to get it to _not_ work, so I'm unable to be of further help.

You might try retyping the second handler just to see if it changes for you as it did for me.

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 5:59 pm
by FourthWorld
Thalor wrote:Interesting thing.

It all works. I can select an image. Put it into Image1, encode it and store it in MYSQL. I can retrieve it from MYSQL, decode and put it in Image2

HOWEVER

If Image1 and Image2 are different sizes (Height and Width) the image gets messed up

Any ideas?
I had thought that was the case too, but I found that when I delete image 2 and made a new one at a different size, it still works.

Still unable to reproduce the non-working state, though I did see it once so at least we know you're not imagining this. :)

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 6:09 pm
by Klaus
Hi all,
Using and setting imagedata requires that both images (source and target) have the SAME (sic!) dimensions (width and height)!
this is correct according to the dictionary, so why tempt fate unneccessarily? :D

If the two images do not have the same dimensions, or if you are no sure about this, then do not use the imagedata but:

Code: Select all

on mouseUp
   put base64encode(the TEXT of image "Image1") into field "text"
end mouseUp

Code: Select all

on mouseUp
   local decodedBinData
   put base64decode (field "text") into decodedBinData
   set the TEXT of img "Image2" to decodedBinData 
end mouseUp
I have to confess that "the TEXT of IMAGE..." is a bit mentally challenging to me :D


Best

Klaus

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 6:11 pm
by Thierry
Thalor wrote: If Image1 and Image2 are different sizes (Height and Width) the image gets messed up
Any ideas?
In your first Post, you are reading and encoding the imageData,
and then setting back the image, but not the imageData!

Are you still doing this?

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 6:19 pm
by Klaus
Bonjour Thierry,

I think we already solved this :D


Best

Klaus

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 6:26 pm
by Thierry
Klaus wrote: I think we already solved this :D
I didn't see your answer when typing mine,
you were faster :roll:

Best,

Thierry

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 6:35 pm
by Klaus
You needed almost one hour for typing this? :shock:

:D

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 6:40 pm
by Thierry
Klaus wrote:You needed almost one hour for typing this? :shock:
It's winter here :)

But more seriously, somehow missed your 1st post.
Sorry about that...

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 6:45 pm
by Thalor
Thanks to all who helped. This has put me on the right path.

Thanks again!

Re: Base64Decode....again

Posted: Thu Feb 12, 2015 6:48 pm
by Klaus
Thierry wrote:
Klaus wrote:You needed almost one hour for typing this? :shock:
It's winter here :)
Ah, OK, that explains it :D
Thierry wrote:Sorry about that...
Hey, really no need for excuses, mon ami!
I just love joking around a bit :D