|
-
as3corelib Saving image wrong
Hey,
I have a game where you can throw snowballs, get a score, and a accuracy at the end.
I want to be able to let the use save the score to a jpg.
The code works fine, image saves right to the computer.
it get the movieclip.height and movieclip.width (which is about 300x 100 px)
But when I look at the image it makes a 300x100 jpg image but puts every data thats being written in the top left corner.
like this:
-
post code.
It looks like the problem might be that you are not passing the correct transformation matrix to bitmapdata.draw.
Why do you think the problem is with saving specifically, and not creating the image in the first place? How have you narrowed the problem down to as3corelib instead of your use of bitmapdata.draw?
-
seeing as I use the exact same code style as the example ive been working with...
anyway here is the code
Actionscript Code:
saveImg_mc.addEventListener(MouseEvent.CLICK, saveImgFire); saveImg_mc.buttonMode = true;
function saveImgFire(event:MouseEvent):void { saveImg(saveImg_mc, 100, "score") }
function saveImg(m:MovieClip, q:Number, fileName:String) { var jpgSource:BitmapData = new BitmapData(m.width, m.height); jpgSource.draw(m); var jpgEncoder:JPGEncoder = new JPGEncoder(q); var jpgStream:ByteArray = jpgEncoder.encode(jpgSource); var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream"); //Make sure to use the correct path to jpg_encoder_download.php var jpgURLRequest:URLRequest = new URLRequest ("jpg_encoder_download.php?name=score.jpg"); jpgURLRequest.requestHeaders.push(header); jpgURLRequest.method = URLRequestMethod.POST; jpgURLRequest.data = jpgStream; var jpgURLLoader:URLLoader = new URLLoader(); navigateToURL(jpgURLRequest, "_blank"); }
-
Okay, that code is not passing any argument for the transformation matrix. It will draw the m MovieClip with m's 0,0 point in the top left of the bitmapdata. If 0,0 is not the top-left of m, you will get a cut-off effect like you've seen.
This code also does not prove that the saving is the problem. Just to debug, create a Bitmap with jpgSource and put it up on the stage. It will almost certainly show the same image that you see saved.
-
It saves the image as you can see in the first post, that image is a outpt.
But you talk about the transform matrix here, any idea how to pass that in the code
or how to fix this?
-
Yes, I know it saves the image as you posted the example. My point is that the image is like that even before saving, so the problem is not with as3corelib or the saving.
To pass a transformation matrix to draw:
Code:
var jpgSource:BitmapData = new BitmapData(m.width, m.height);
var matrix:Matrix = new Matrix();
matrix.translate(xoffset, yoffset);
jpgSource.draw(m, matrix);
Where xoffset is the amount (in pixels) you want to shift right, and yoffset is the amount to shift down. These should correspond to the upper-left coordinate of m. For instance if m's upper left is (-10, -30), you'd want to translate by 10, 30. I might have that backwards, in which case the translate would be -10,-30. You can play with it.
-
This works perfect Thanks..
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|