Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-29-2008, 09:29 AM   #1
maani786
Senior Member
 
Join Date: Apr 2008
Posts: 125
Default problem with bitmapdata and bytearray

hi to all
i have a movieclip name container which contains a UILoader named ldr and i am loading dynamic image to ldr. then i want some changes to that image like ldr.blendmode="difference" and "flip horizontal and vertical".
all things are going smooth and i also view changes but when i am going to save the movieclip content as jpg image through php script. the same original images saved.
here is flash script that collects bitmap data and pass it to php script
ActionScript Code:
function saveImage(img:MovieClip, q:Number, fileName:String="image.jpg") {     var jpg:BitmapData = new BitmapData(m.width, m.height);     jpg.draw(img);     var jpegEncoder:JPGEncoder = new JPGEncoder(q);     var jpgStream:ByteArray = jpegEncoder.encode(jpg);     var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");     var jpgURLRequest:URLRequest = new URLRequest ("saveImage.php?name=" + fileName);               jpgURLRequest.requestHeaders.push(header);            jpgURLRequest.method = URLRequestMethod.POST;                 jpgURLRequest.data = jpgStream;     var jpgURLLoader:URLLoader = new URLLoader();     jpgURLLoader.dataFormat = URLLoaderDataFormat.VARIABLES;     jpgURLLoader.addEventListener( Event.COMPLETE, successHandler );     jpgURLLoader.addEventListener( IOErrorEvent.IO_ERROR, failureHandler );     jpgURLLoader.load( jpgURLRequest ); }

any idea or any suggestion will be highly appreciated.

Thanks
..maani
maani786 is offline   Reply With Quote
Old 08-29-2008, 09:41 AM   #2
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

>> jpg.draw(img);
You need to use the second argument (Matrix) to draw transformed clip into bitmapData, here's an example:
ActionScript Code:
var sourceBMP:BitmapData = new BitmapData(12, 12, false, 0xDDDDDD); sourceBMP.fillRect(new Rectangle(0, 0, 6, 6), 0xAAAAAA); sourceBMP.fillRect(new Rectangle(6, 6, 6, 6), 0xAAAAAA); var sourceSPR:Sprite = new Sprite(); sourceSPR.graphics.beginBitmapFill(sourceBMP); sourceSPR.graphics.drawRect(0, 0, 200, 200); sourceSPR.graphics.endFill(); sourceSPR.rotation = 45; addChild(sourceSPR); var resultBMP:BitmapData = new BitmapData(sourceSPR.width, sourceSPR.height, false, 0xFF); var mtx:Matrix = sourceSPR.transform.matrix.clone(); mtx.translate(sourceSPR.getBounds(sourceSPR).height * Math.sin(Math.PI / 4), 0); resultBMP.draw(sourceSPR, mtx); var bitmap:Bitmap = new Bitmap(resultBMP); bitmap.x = 200; addChild(bitmap);
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 08-29-2008, 10:37 AM   #3
maani786
Senior Member
 
Join Date: Apr 2008
Posts: 125
Default

dear wvxvw
thanks for your quick responce
sorry to say i didnot understand your code in my context..

try to understand my requirements:

1) my source is img:MovieClip (first argument to save Image method)
2) i need to draw it with bitmapdata.draw method.


let me send you some code in detail
there is rectangle converted into movieclip named container there is loader named ldr and then i add it to container
ActionScript Code:
var ldr:UILoader = new UILoader(); ldr.load(new URLRequest("flower.jpg"); container.addChild(ldr);

there are three buttons blendmode_diff, flip_horizantol and flip_vertical
ActionScript Code:
blendmode_diff.addEventListener(MouseEvent.CLICK, differenceBlendMode); flip_horizantol.addEventListener(MouseEvent.CLICK, flipHorizontal); flip_vertical.addEventListener(MouseEvent.CLICK, flipVertical); function differenceBlendMode(evt:MouseEvent):void {     container.blendMode = "difference"; } function flipHorizontal(evt:MouseEvent):void {     var matrix:Matrix = container.transform.matrix;     matrix.a=-matrix.a;     matrix.tx=container.x+container.width;     container.transform.matrix=matrix; }       function flipVertical(evt:MouseEvent):void {         var matrix:Matrix = container.transform.matrix;     matrix.d=-matrix.d;     matrix.ty=container.y+container.height;     container.transform.matrix=matrix; }
then i have a save button
ActionScript Code:
save_Image.addEventListener(MouseEvent.CLICK, saveImageListener); function saveImageListener(evt:MouseEvent):void { saveImage(container, 85); } function saveImage(img:MovieClip, q:Number, fileName:String="image.jpg") {     var jpg:BitmapData = new BitmapData(m.width, m.height);     jpg.draw(img);     var jpegEncoder:JPGEncoder = new JPGEncoder(q);     var jpgStream:ByteArray = jpegEncoder.encode(jpg);     var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");     var jpgURLRequest:URLRequest = new URLRequest ("saveImage.php?name="+fileName);           jpgURLRequest.requestHeaders.push(header);            jpgURLRequest.method = URLRequestMethod.POST;                 jpgURLRequest.data = jpgStream;     var jpgURLLoader:URLLoader = new URLLoader();     jpgURLLoader.dataFormat = URLLoaderDataFormat.VARIABLES;     jpgURLLoader.addEventListener( Event.COMPLETE, successHandler );     jpgURLLoader.addEventListener( IOErrorEvent.IO_ERROR, failureHandler );     jpgURLLoader.load( jpgURLRequest ); }


now kindly tell me how to make changes in saveImage function. write your saveImage function for this code.
thanks
..maani
maani786 is offline   Reply With Quote
Old 08-29-2008, 11:03 AM   #4
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

>> 2) i need to draw it with bitmapdata.draw method.
This is exactly where the problem is. When you execute draw() you don't pass it all the parameters that it needs to draw transformed clip.
The mandatory parameter for draw() is the drawable object, the rest goes like this:
matrix (the distortion you want to apply to the drawing before it is copied into bitmapdata)
colorTransform (the color transformation you want to apply to the pixels copied to the bitmapdata)
blendMode (the blendMode you want to use when adding new pixels to allready existing bitmapdata content)
rectangle what rectangular area from the drawable object you want to copy
smoothing the way Flash will calculate color values when resizing source drawable object before writting it into bitmapdata).
Unless you cpecify those the drawable object you pass to draw() method will be copied into bitmapdata as if it was not transformed (nor distortion neither color changes or blending mode will preserve).
If you had only distorted the object, then you could simply add it to container and draw the container instead, thus not having to recalculate transformation matrix. Unfortunately, you need to copy it and apply a different blendMode (it won't remain when drawing the container) so, you'll have to use drawable object blendMode when drawing it into bitmap.)
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it

Last edited by wvxvw; 08-29-2008 at 11:07 AM.
wvxvw is offline   Reply With Quote
Old 08-29-2008, 11:07 AM   #5
maani786
Senior Member
 
Join Date: Apr 2008
Posts: 125
Default

got your point..
thanks a lot for your responce.
take care

..maani

Last edited by maani786; 08-29-2008 at 11:19 AM.
maani786 is offline   Reply With Quote
Old 08-29-2008, 11:29 AM   #6
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

ActionScript Code:
var avatar:BitmapData = new Avatar(300, 321); var avatarBMP:Bitmap = new Bitmap(avatar); avatarBMP.blendMode = BlendMode.MULTIPLY; var avatarSPRT:Sprite = new Sprite(); avatarSPRT.graphics.beginFill(0xFF0000); avatarSPRT.graphics.drawRect(0, 0, 300, 321); avatarSPRT.graphics.endFill(); avatarSPRT.addChild(avatarBMP); avatarSPRT.rotation = 45; avatarSPRT.width = 321; avatarSPRT.x = avatarSPRT.getBounds(avatarSPRT).height * Math.sin(Math.PI / 4); addChild(avatarSPRT); var resultBMPD:BitmapData = saveImage(avatarSPRT); var resultBMP:Bitmap = new Bitmap(resultBMPD); resultBMP.x = avatarSPRT.width; addChild(resultBMP); function saveImage(img:IBitmapDrawable):BitmapData {     var jpg:BitmapData = new BitmapData((img as DisplayObject).width, (img as DisplayObject).height);     var mtx:Matrix = (img as DisplayObject).transform.matrix.clone();     jpg.draw(img, mtx); // see the different result when you change     // it to be jpg.draw(img);     return jpg; }
Attached Files
File Type: zip Untitled-1.zip (24.1 KB, 157 views)
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 08-29-2008, 11:49 AM   #7
maani786
Senior Member
 
Join Date: Apr 2008
Posts: 125
Default

what is Avatar()?????
var avatar:BitmapData = new Avatar(300, 321);
maani786 is offline   Reply With Quote
Old 08-29-2008, 12:11 PM   #8
wvxvw
Holosuit User
 
wvxvw's Avatar
 
Join Date: Oct 2006
Location: Tel Aviv
Posts: 4,301
Send a message via ICQ to wvxvw
Default

I've attached FLA for this, it's the Class assigned to the bitmap in the library =)
__________________
The .NET open source editor for Flash and web developers
*This would be my contribution to the project*
couchsurfing if you need it
wvxvw is offline   Reply With Quote
Old 09-02-2008, 04:08 AM   #9
maani786
Senior Member
 
Join Date: Apr 2008
Posts: 125
Default

yes i got it
thanks
maani786 is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ByteArray to BitmapData conversion Chuck Taylor Projectors and CDs 12 06-24-2009 07:52 PM
bytearray question adamsnk ActionScript 3.0 3 08-24-2008 07:12 PM
Decoding image from a byteArray GagNet ActionScript 3.0 2 05-28-2008 03:35 PM
BitmapData capturing stage area tofu1080 ActionScript 3.0 0 05-14-2008 07:59 PM
How to scroll a bytemap (ByteArray)? AJ-D ActionScript 3.0 0 10-29-2007 05:36 PM


All times are GMT. The time now is 06:41 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.