10 years ago by Donzo
Hello again:
I have been pulling my hair out about this issue.
I am using this awesome image picker class to pull an image off the user's phone.
It works great, but I want to store the photo that the user has selected.
I am attempting to do it like this:
1. Draw the image:
2. Get the image data:
3. Stringify the image data:
4. Store the string:
5. Retrieve the string and parse it:
6. Put the image in the desired location:
It all works great until the last step. For some reason, putImageData will not display the image regularly. Sometimes the image may flicker briefly, but it is not appearing as it should.
Here are the things that I've tried:
1. I read this github thread. I set .retinaResolutionEnabled and imageSmoothingEnabled to false. This did not help.
2. I tried using the getImageDataHD and putImageDataHD methods instead. The image still did not draw.
3. I tried removing all scaling of the images. It did not make a difference.
4. I tried running the game at a reduced frame rate. It did not matter.
I have reached the limits of my abilities and now turn to others for help.
How can I store an image and later retrieve it?
Thank you in advance for your consideration.
I have been pulling my hair out about this issue.
I am using this awesome image picker class to pull an image off the user's phone.
It works great, but I want to store the photo that the user has selected.
I am attempting to do it like this:
1. Draw the image:
ctx.drawImage(this.myImage, this.myImageDx, this.myImageDy, this.myImageDw, this.myImageDh);
2. Get the image data:
this.myImageData = ctx.getImageData(this.myImageDx,this.myImageDy,this.myImageDw,this.myImageDh);
3. Stringify the image data:
this.u1ImageString = JSON.stringify( this.myImageData );
4. Store the string:
localStorage.setItem("u1myImage", ig.game.u1ImageString );
5. Retrieve the string and parse it:
this.u1MyPic = JSON.parse(localStorage.getItem("u1myImage", ig.game.u1ImageString ));
6. Put the image in the desired location:
ctx.putImageData(this.u1MyPic , this.myImageDx, this.myImageDy, this.myImageDw, this.myImageDh);
It all works great until the last step. For some reason, putImageData will not display the image regularly. Sometimes the image may flicker briefly, but it is not appearing as it should.
Here are the things that I've tried:
1. I read this github thread. I set .retinaResolutionEnabled and imageSmoothingEnabled to false. This did not help.
2. I tried using the getImageDataHD and putImageDataHD methods instead. The image still did not draw.
3. I tried removing all scaling of the images. It did not make a difference.
4. I tried running the game at a reduced frame rate. It did not matter.
I have reached the limits of my abilities and now turn to others for help.
How can I store an image and later retrieve it?
Thank you in advance for your consideration.