Minimize picture size - javafx

I have a picture into JavaFX application which is loaded +30 times into chart. I use this code to load it and shrink the size.
ImageView livePerformIcon = new ImageView(MainApp.class.getResource("/images/Untitledwdwd.png").toExternalForm());
livePerformIcon.setFitHeight(100);
livePerformIcon.setFitWidth(100);
label.setGraphic(livePerformIcon);
Can you tell em how I can optimize this code for performance and memory is there a way to save resources during work.
Maybe livePerformIcon.setCache(true); can solve this?

Load the Image once and use the same Image instance for all the ImageViews. The example in the ImageView javadocs does this.

Related

Flex: how to flatten loaded swf and then apply alpha, rather than applying alpha and then flattening

I have a flex application and am trying to show some animated vector shapes on a google map. To do this I load an external SWF (the content is dynamic, so I have to load at runtime and SWF was the only loadable format supporting animation AFAIK) and place it on the map using an overlay.
I then need to control the alpha of the SWF. Setting it is straightforward, but for some reason the alpha appears to be applied to the sub-shapes inside the SWF, and only after that is the image composited onto the map. This makes the yellow blob that is on top of the green blob appear yellow-green rather than just yellow.
I need to somehow tell flex/flash to "render/flatten the SWF, then apply the alpha", rather than "apply the alpha to the individual sub-shapes, then flatten to the map". Ideally without going via e.g. a BitmapData object or similar.
The containment hierarchy is Map -> BlobManager -> Loader -> Loader.content (the SWF) and I've tried applying the alpha to the BlobManager, Loader, and Loader.content separately, but no difference. I've tried cacheAsBitmap on the lower layers and then applying alpha higher up to no avail.
Any suggestions for what to try next? Thanks!
Try BlendMode.LAYER, it saved many lives.
I don't think you can do that without drawing the loaded content on a Bitmap and using that to display with alpha.
It is quite easy though, although you might run into security violations if the loaded content is from another domain and won't let you create bitmapData from it.
// content is the loaded external swf, or the Loader itself?
var bitmapData:BitmapData = new BitmapData(content.width, content.height);
bitmapData.draw(content);
var bitmap:Bitmap = new Bitmap(bitmapData);
bitmap.alpha = .5;
addChild(bitmap);
It may not even be necessary to display the loaded content (although I haven't tried that) and you can also take only part of it to use as bitmapData using a Matrix.
EDIT: for animation, another option is to load an animated gif as described here: http://www.bytearray.org/?p=95 (I have no experience with it so I can't say if it'd really work for you), or use video.

Advanced Image cropping and image resizing in Flex

I have created a image cropping tool in flex using core copyPixel method.
croppedBitmapData.copyPixels(croppedBitmapData, clipCan, new Point(0, 0));
I have to crope area of dementions 20*20 and show this cropped area in an image of demention 250*350.
Every thing going well.
My problem is image distortion.
Even i am using this method for smoothing image contents on complete.
private function smoothImage(event:Event):void
{
var bitmap: Bitmap = ((event.target as Image).content as Bitmap);
if (bitmap != null)
{
bitmap.smoothing = true;
}
}
I want to get the result of this site. http://www.yourplayingcards.com/builder/
Please help me to get ride of image distortion.
Can we show bitmapdata of 20*20 into image of 250*350 without distotion?
What you call 'distortion' is probably what I think you mean by pixelation. The reason why that website can zoom in without pixelation is because it's using vector shapes, not bitmaps, to show the graphics. Vector shapes can be scale infinitely without loss of quality because it doesn't store pixel information, but spline information.
In essence, if you want to imitate the zooming of the the website you have shown, you will have to create your own vector shape. You can use Flex 4's built in FXG format or use something like Degrafa if you're still in Flex 3. You can also leverage Flash Catalyst to import vector graphics made in Illustration into Flex.
I am not sure about that but it is done in VectorMagic may be they are using server side too any ways, you may also interested in Actionscript SVG renderer
Hopes that helps

Is there a way to use Flex 9-slice scaling at runtime?

I haven't been able to find an answer to this online. Is there a way to use 9-slice scaling with images loaded at runtime?
To clarify, let's say that I build an application that lets a user skin a button with whatever image they want. This would be an image that's not embedded with the swf. Is there a way to set that runtime image as a background and use 9-scaling?
Thanks!
You can specify a rectangle as the scale9grid of a movieClip that contains your image art.
http://www.sephiroth.it/tutorials/flashPHP/scale9/
Now, to use a MovieClip in Flex (it's a Flash thingy) you have to load it into a UIComponent:
http://cookbooks.adobe.com/post_You_wish_to_add_a_Sprite_or_MovieClip_to_a_Flex_ap-7142.html

How do I get the position of a swf generated from an fla file that had a larger stage?

I have assets in external swfs which I load. I would like to know the exact size of the stage and the position of the asset in the fla that created it. If I try to ask the resulting MovieClip for it's size, it turns out it gives me the size when it is trimmed down to the tightest box around the non-transparent pixels. Looking at the contentLoaderInfo, I can get the original width/height that was used by the fla file, which is great. However, I still need to know where to place the asset within the stage.. basically I need an x/y offset for it.
The reason I need this is for a customizable avatar - it has many parts, which are placed in different areas on a stage to create the full avatar. I would like to be able to combine the individual swfs for each part to achieve this.
Thanks in advance for any help!
I don't believe you can get the stage size of a loaded swf, as there is only one stage in flash when you load a child swf in, it will use the parent stage. As you pointed out a loaded swf will collapse to the bounding box of the items within it.
Might I suggest that all assets have a MovieClip on the stage containing a block the dimensions of the stage, then change the alpha of this clip to 0 so it isn't visible.

Resize Sprite Flex/ActionScript

I am creating Sprite objects as simple shapes, and would like to know how to resize them dynamically.
my question:
How can I enable the Sprite to be re-sized on mouse drag(perhaps enabling a only a portion of the Sprite for this behavior)?
It might be important to note that I am using the Flex SDK, and therefore do not have full
access to the Flash libraries.
Thank you in advance.
You might want to check out the Flex Object Handles open source library. Check out the demo to see how it can be used to allow users to resize any object in a Flex app.
Doesn't the sprite always adapt itself to its contents to set its height and width? (like movieclips in as2). If you want to resize a sprite, I guess you'd have to draw something as background?
What do you mean by enabling a portion of the sprite to be re-sized?

Resources