Thank you very much for the response. Your code looked eerily similar to the code I was already using, but I plugged your code into a fresh project and it worked. It baffled my mind. I went back to my project and I got the same issue I was seeing before--the bitmap data would return 0 for both width and height. The flex debugger showed "Error #2015: Invalid BitmapData." for both getters. I assumed it was due to the 16.7 million limit (which doesn't seem to apply to bitmaps created by loaders) because I consistently saw the issue with images over that size. On a whim I tried our project without the debugger (just a normal run) and it worked! If that isn't crazy enough, I started noticing that the longer I used Flex builder the more common the issue became--that is, images at 13,000,000 pixels even started reporting 0 width and height (and the invalid bitmap error in the variables debugger view).
Thanks for taking the time to send your code and prompting me to look deeper. Aaron On Tue, Dec 15, 2009 at 11:43 AM, jamesfin <[email protected]>wrote: > > > > > This example refines the image down to 80x80. SmoothImage is derived from > Image. I tested it against a 7000x6000 8.5mb jpg with no problems. It also > scales to the smaller side if they aren't equal. > > main code... > > private var uploadReference:FileReference = new FileReference(); > > uploadReference.addEventListener(Event.SELECT, loadImage); > uploadReference.addEventListener(Event.CANCEL, cancelImage); > uploadReference.addEventListener(Event.COMPLETE, uploadCompleted); > > private function loadPicture(evt:MouseEvent):void{ > > var imageArray:Array = new Array(); > imageArray.push(new FileFilter("My Image", ".png;*.jpg;*.jpeg;*.gif")); > uploadReference.browse(imageArray); > } > > private function loadImage(evt:Event):void{ > > uploadReference.load(); > } > > private function uploadCompleted(e:Event):void{ > > if(FileReference(e.target).data.length == 0){ > return; > } > > var loader:Loader = new Loader(); > loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoad); > loader.loadBytes(FileReference(e.target).data); > } > > > private function onImageLoad(e:Event):void { > > var imageBitmapData:BitmapData = Bitmap(e.target.content).bitmapData; > > var loader:Loader = Loader(e.target.loader); > > var smoother:SmoothImage = new SmoothImage(); > smoother.load(new Bitmap(imageBitmapData, "auto", true)); > smoother.content.width = 80; > smoother.content.height = 80; > smoother.width = 80; > smoother.height = 80; > > if(imageBitmapData.width > 80 || imageBitmapData.height > 80){ > > var imageSmoothed:SmoothImage = new SmoothImage(); > imageSmoothed.maintainAspectRatio = true; > imageSmoothed.load(new Bitmap(imageBitmapData, "auto", true)); > > var maxSize:Number = Math.max(imageBitmapData.width, > imageBitmapData.height); > > if(maxSize == imageBitmapData.width){ > > var widthScale:Number = 80 / imageBitmapData.width; > var newWidth:Number = imageBitmapData.width * widthScale; > var newHeight:Number = imageBitmapData.height * widthScale; > > imageSmoothed.content.width = newWidth; > imageSmoothed.content.height = newHeight; > imageSmoothed.width = newWidth; > imageSmoothed.height = newHeight; > > var finalBitmap:BitmapData = new BitmapData(newWidth, newHeight); > finalBitmap.draw(imageSmoothed); > imageBitmapData = null; > imageBitmapData = finalBitmap; > > }else{ > > var heightScale:Number = 80 / imageBitmapData.height; > var newWidth2:Number = imageBitmapData.width * heightScale; > var newHeight2:Number = imageBitmapData.height * heightScale; > > imageSmoothed.content.width = newWidth2; > imageSmoothed.content.height = newHeight2; > imageSmoothed.width = newWidth2; > imageSmoothed.height = newHeight2; > > var finalBitmap2:BitmapData = new BitmapData(newWidth2, newHeight2); > finalBitmap2.draw(imageSmoothed); > imageBitmapData = null; > imageBitmapData = finalBitmap2; > } > > } > > // some image... > imageToDisplay.source = new Bitmap(imageBitmapData); > > } > > --- In [email protected] <flexcoders%40yahoogroups.com>, Aaron > Hardy <aaronius...@...> wrote: > > > > Hey flexers, > > > > We're working on a project currently where we would like to allow users > to > > add photos from their local drive to the stage. We also want to support > > gigantic photos. I understand the max bitmap size is 4095x4095 (or > > dimensions that equal the same number of pixels) in flash player 10. If > the > > user has a photo bigger than this, we'd be happy to size the image down > to > > this limit and allow the user to work with their image at the restricted > > size. However, I'm stuck trying to figure out how to size down the image > > before creating a bitmap object. I have a bytearray of the image data but > > now I need the image resized down to the bitmap limit before creating a > > bitmap from the bytearray. Somewhat a chicken-or-the-egg problem. Does > > anyone have a nice tool or method to accomplish this? Anyone know how > > Buzzword does this? > > > > Thanks. > > > > Aaron > > > > >

