0
votes

In Flash, I have an external image and i loaded that image using a sprite for the user to edit the image.

var bitmapData:BitmapData = Bitmap(event.currentTarget.content).bitmapData;
var bitmap:Bitmap = new Bitmap(bitmapData);

bitmap.smoothing = true;
bitmap.width=500
bitmap.height=300
photoHolder = new Sprite()
photoHolder.addChild(bitmap);

After the edit, i would like to save the same image but with different width and height for example 800x480. In saving the image, i did this.

**var myBitmapData:BitmapData = new BitmapData(photoHolder.width, photoHolder.height);**//photoHolder.width, photoHolder.height
myBitmapData.draw(photoHolder);

THen later save it using FileStream.

private function F_saveImageActions():void{
        //get Bimapdata from file
        var myBitmapData:BitmapData = selectedFile.photo_bitmapData
        //encode, turn into byeArray
        var jpgEncoder:JPGEncoder = new JPGEncoder(100);
        var imgByteData:ByteArray = jpgEncoder.encode(myBitmapData);
        //
        var folder:File = File.documentsDirectory.resolvePath("Myproject/myImage.jpg");

        imageFileStream = new FileStream();  
        imageFileStream.addEventListener(Event.CLOSE, FS_imageFileClosed);
        imageFileStream.addEventListener(Event.COMPLETE, FS_imageCompleteHandler); 
        imageFileStream.addEventListener(ProgressEvent.PROGRESS, FS_imageProgressHandler); 
        imageFileStream.addEventListener(IOErrorEvent.IO_ERROR, FS_imageErrorHandler); 
        imageFileStream.openAsync(folder, FileMode.UPDATE);  
        imageFileStream.writeBytes(imgByteData);

} I tried changing the size by editing the bold line above to this.. var myBitmapData:BitmapData = new BitmapData(800,480);

But it didnt work. it had a different outcome than i expected and the quality was affected.. So to be precise here is my question

How do i change the size of an image from a sprite on stage and export it without losing its quality?(AS3)

1
Am I right that you first load a 500x300 bitmap from somewhere, then edit it by overlaying something or altering pixels, then you want to make it into a bitmap of 800x480 without scale adjustment? Upscaling a bitmap will always pixelate it somehow.Vesper
"How do i change the size of an image from a sprite on stage and export it without losing its quality?(AS3)" really .... you can't, there's no existing program or code out there that can add missing pixels at the right place when you scale up a bitmap. If you scale down or keep at same size then just draw it to a bitmapdata using a matrix.BotMaster
My first problem is resizing the image to 800x480. The size of the output is 800x480, but the resolution of the image itself is still 500x300.. and the rest of the image is just white..Right now lets ignore the quality, lets focus on the resizing of the image..Darvlaskie
Are you still interested in an answer?VC.One
Yes i am still interestedDarvlaskie

1 Answers

0
votes

Ok, I found it!

var matrix:Matrix = new Matrix();
matrix.scale(scaleX_var, scaleY_var);

and pass it in drawWithQuality(); parameter.