I need help converting an image into a Uint8Array
for use in F5 steganography with the f5stego
package.
After trying to implement this, I encountered an issue where the imageArray
contains all zeroes when printed outside the function, but inside it holds the actual image data values.
var stegKey = [1, 2, 3, 4, 5, 6, 7, 8, 9];
var stegger = new f5stego(stegKey); // initialize stegger with key
var canvas = document.createElement('canvas');
ctx = canvas.getContext('2d'), base64 = 'cover.jpg';
canvas.width = 43;
canvas.height = 34;
var image = new Image();
var imageArray = new Uint8Array(4624);
image.onload = (function (canvas, ctx) {
return function () {
ctx.drawImage(this, 0, 0);
var imageData = ctx.getImageData(0, 0, 34, 34);
// console.log(imageData.data);
imageArray = imageData.data;
console.log(imageArray);
};
})(canvas, ctx);
image.src = base64;
console.log(imageArray);
// Data Array
var message = "something secret ";
dataArray = new Uint8Array(message.length);
for (var i = 0, j = message.length; i < j; ++i) {
dataArray[i] = message.charCodeAt(i);
}
console.log(dataArray);
//embed message into image
var secretImage = stegger.embed(imageArray, dataArray);
console.log(secretImage);
//extract message from image
var extractedMessage = stegger.extract(secretImage);
console.log(extractedMessage);