Copy link to clipboard
Copied
Hey folks,
I need to make a way for a user to save a sample of an image once a user uploaded image is uploaded onto it.
This means I have to use multiple loaders, right?
So, I can get the bacround image to save just fine. but when I add the container for the logo, I get a reference error. More specifically-
ReferenceError: Error #1069: Property FileName.jpg not found on flash.utils.ByteArray and there is no default value.
Here is my script-
[CODE]
sampleSaveBTN.addEventListener(MouseEvent.CLICK, saveSampleImage);
function saveSampleImage (evt: MouseEvent)
{
var bitmapData:BitmapData = new BitmapData(BGContain.width, BGContain.height);
var logoBitmapData:BitmapData = new BitmapData(logoContain.width, logoContain.height);
bitmapData.draw(BGContain);
logoBitmapData.draw(logoContain);
var jpg:JPGEncoder = new JPGEncoder(100);
var ba:ByteArray = jpg.encode(bitmapData);
var la:ByteArray = jpg.encode(logoBitmapData);
file = new FileReference();
file.save[ba,la, 'FileName.jpg'];
[/CODE]
save is a method (that takes one or two parameters). you're using it as if it were an array?
Copy link to clipboard
Copied
save is a method (that takes one or two parameters). you're using it as if it were an array?
Copy link to clipboard
Copied
Thanks for the response!
I changed this to use the byte array as an array. Still getting the same error though. If I leave out all the logoContain script, it works just fine.
function saveSampleImage (evt: MouseEvent)
{
var bitmapData:BitmapData = new BitmapData(BGContain.width, BGContain.height);
var logoBitmapData:BitmapData = new BitmapData(logoContain.width, logoContain.height);
bitmapData.draw(BGContain);
logoBitmapData.draw(logoContain);
var jpg:JPGEncoder = new JPGEncoder(100);
var ba:ByteArray = jpg.encode[bitmapData, logoBitmapData];
file = new FileReference();
file.save(ba,'FileName.jpg');
}
Copy link to clipboard
Copied
the encode method accepts one bitmapdata object.
what are you trying to do? are you trying to create one image from two?
Copy link to clipboard
Copied
Yes. I have an external background image that loads into a container and then another image that the user can load in. I can't load both images into the same container because the user loaded image has a filter that needs to be applied.
I just tried gathering the 2 loaders into a sprite, but now when I save an image, it's blank.
Thanks for the help!
Copy link to clipboard
Copied
you have two different images and you're trying to combine them into one image? if yes, in what way do you want to combine them?
Copy link to clipboard
Copied
I was able to get it to roughly work with the following:
Here is the code- I added the children from the previous containers. Their loader positions are gone, but I feel like I'm on the right track now!
function saveSampleImage (evt: MouseEvent)
{
var gatherSample: Sprite = new Sprite();
gatherSample.addChild(bgImgLoader);
gatherSample.addChild(loadLogo);
matrix = color.CalculateFinalFlatArray();
colorMatrix = new ColorMatrixFilter (matrix);
filterBW = [colorMatrix];
loadLogo.filters = filterBW;
var sampleData: BitmapData = new BitmapData(gatherSample.width, gatherSample.height);
sampleData.draw(gatherSample);
var jpg:JPGEncoder = new JPGEncoder(100);
var ba:ByteArray = jpg.encode(sampleData);
file = new FileReference();
file.save(ba,'FileName.jpg' + ".jpg");
}
Thanks again!
Copy link to clipboard
Copied
that's what i keep asking: how do you want to combine them? right now you have them overlapping on top of each other.
Copy link to clipboard
Copied
Yes, They overlap. loadLogo has to be in a specific location. Haven't quite figured that one out though.
Copy link to clipboard
Copied
assign their positions:
function saveSampleImage (evt: MouseEvent)
{
var gatherSample: Sprite = new Sprite();
gatherSample.addChild(bgImgLoader);
gatherSample.addChild(loadLogo);
bgImgLoader.y=0;
loadLogo.y=bgImgLoader.height; // if you want them vertically oriented, for example
matrix = color.CalculateFinalFlatArray();
colorMatrix = new ColorMatrixFilter (matrix);
filterBW = [colorMatrix];
loadLogo.filters = filterBW;
var sampleData: BitmapData = new BitmapData(gatherSample.width, gatherSample.height);
sampleData.draw(gatherSample);
var jpg:JPGEncoder = new JPGEncoder(100);
var ba:ByteArray = jpg.encode(sampleData);
file = new FileReference();
file.save(ba,'FileName.jpg' + ".jpg");
}
Thanks again!
Copy link to clipboard
Copied
awesome thanks!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now