Image select, resize and locally store (flex3 air example)

Hi there,
After a few days of struggling with images, resize functions
and file dialog boxes I created a nice example application that
shows how you can select an image, resize it and save the resized
image in the application storing directory.
I hope you can profit from it.
Greets, jacob
example code for flex 3 air.
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Script>
<![CDATA[
import mx.graphics.codec.PNGEncoder;
public var imageFile:File;
public var fileresultimage:Object;
public var fileresultlabel:Object;
// File.applicationStorageDirectory gets you to the local
storage dir
//On Windows, this is the "projectname" directory
//(for example, C:\Documents and Settings\application
data\projectname).
// On Mac OS, it is /Users/userName/Documents.
public var docsDir:File = File.applicationStorageDirectory;
public function
imageFileDialog(image:Object,label:Object):void
fileresultimage=image;
fileresultlabel=label;
var imagesFilter:FileFilter =
new FileFilter("Foto (*.jpg, *.gif, *.png)",
"*.jpg;*.gif;*.png");
if(imageFile==null)
imageFile = new File();
imageFile.addEventListener(Event.SELECT, imageSelected);
imageFile.browseForOpen("Select an Image",[imagesFilter]);
// if there is a file selected
public function imageSelected(event:Event):void
var newFile:File = event.target as File;
//if there is a file object on the screen
if(fileresultimage!=null)
fileresultimage.source=imageFile.url;
//if there is a label object on the screen
if(fileresultlabel!=null)
fileresultlabel.text=imageFile.url;
if (newFile.exists==true)
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
handleImageComplete);
loader.load(new URLRequest(imageFile.url));
// when load of the selected image is complete we save a
smaller version of it.
public function handleImageComplete(event:Event):void
var loader:Loader = Loader(event.target.loader);
// width and heigt of selected image
var originalimgwidth:Number=event.target.width;
var originalimgheight:Number=event.target.height;
//put original image into bitmapdata
var bitmapje:BitmapData;
bitmapje=new BitmapData(originalimgwidth, originalimgheight,
true, 0x00000000);
//bitmapje.draw(loaderInfo.loader.content,null,null,null,null,true);//null
object reference
bitmapje.draw(loader.content,null,null,null,null,true);
// call the resize function and give the original
image,maxx,and maxy with it.
var thumb:BitmapData=resizeimage(bitmapje,150,150);
var newimagefile:File=new File();
// T = Thumbnail
// 1 = next id in the db
// for now we use a random number
var random:Number= Math.random();
random = Math.ceil(random*100);// to get a positive number
var filenameForSave:String="T"+random; //new filename;
newimagefile=docsDir.resolvePath("Thumbs/" + filenameForSave
+ ".png"); //image path
var stream:FileStream = new FileStream; // create new
filestream
stream.open(newimagefile, FileMode.WRITE); // open
filestream
var data:ByteArray = encodeToPng(thumb); // convert
bitmapdata to a png bytearry
stream.writeBytes(data, 0, data.length); // writing the
image
stream.close();
// show the saved thumb
savedthumb.source=newimagefile.nativePath;
bitmapje=null;
thumb=null;
// resize function
private function
resizeimage(image:BitmapData,maxx:Number,maxy:Number):BitmapData
var bmp:BitmapData =image;
var true_width:Number = bmp.width;
var true_height:Number = bmp.height;
var resize:Boolean=false;
if (true_width>maxx) resize=true;
if (true_height>maxy) resize=true;
if (resize==true)
var width:Number=maxx;
var height:Number = (width / true_width) * true_height;
true_width=width;
true_height=height;
if (true_height>maxy)
height=maxy;
width = (height/true_height)*true_width;
else
width=true_width;
height=true_height;
else
width=true_width;
height=true_height;
//new calculated width and heigt relative to the given maxx
and maxy.
width=Math.ceil(width);
height=Math.ceil(height);
//create a new image object with the calculated widht and
height for the smaller image
var mysmallimage:Image=new Image();
mysmallimage.width=width;
mysmallimage.height=height;
//new matrix for smaller image
var m : Matrix = new Matrix() ;
//scale the matrix to the correct sizes.
m.scale( mysmallimage.width / bmp.width, mysmallimage.height
/ bmp.height ) ;
//draw the image into the image object
mysmallimage.graphics.beginBitmapFill( bmp, m, false, true )
mysmallimage.graphics.drawRect( 0, 0, mysmallimage.width,
mysmallimage.height ) ;
mysmallimage.graphics.endFill();
//put the smaller image into bitmapdata so it can be
returned.
var littlebitmapdata:BitmapData=new
BitmapData(mysmallimage.width,mysmallimage.height,true,0x00000000);
littlebitmapdata.draw(mysmallimage);
// set the temporary small image to null so the GC can
remove it from the memmory.
mysmallimage=null;
bmp=null;
//returning the small image.
return littlebitmapdata;
// encoder to png
private function encodeToPng(bmd:BitmapData):ByteArray
var png:PNGEncoder= new PNGEncoder();
return png.encode(bmd);
]]>
</mx:Script>
<!--<mx:Image id="tempimage" x="404" y="36"
complete="temploadcomplete()"/>-->
<mx:Image id="myimg" x="10" y="55" width="314"
height="227" verticalAlign="middle" horizontalAlign="center"/>
<mx:TextInput id="imageurl" x="53" y="303" width="160"
maxWidth="160"/>
<mx:Button x="221" y="303" label="Bladeren"
click="imageFileDialog(myimg,imageurl)"/>
<mx:Image x="346" y="55" id="savedthumb"/>
<mx:Text x="23" y="0" text="Original image with limit
width and height to show it on the screen." height="47"
width="177"/>
<mx:Text x="346" y="0" text="Local stored thumbnail"/>
</mx:WindowedApplication>
To bad the attach code button still isn't fixed :(

Hi there,
Will you be able to provide the backend script for saving the
file data?Will you be able to provide the backend script for saving
the file data?
This example is created for a desktop application. Saving the
file is included in this example, it saves in the application
storage directory.
// File.applicationStorageDirectory gets you to the local
storage dir
//On Windows, this is the "projectname" directory
//(for example, C:\Documents and Settings\application
data\projectname).
// On Mac OS, it is /Users/userName/Documents.
If you attempt to use certain functionality in a website, you
need other functionality for storing the image on the server. There
are lots of examples on that one.. Perhaps i need it in the future.
If i do i will post an example on the forum.
Also, may I post your link to other forums, so that others may
benefit?
Sure you may post the example on other websites and forums.
I found it difficult to find nice examples, so the more the
better ;)
Just put underneath the example something like:
Created By: Jacob Hingst From Holland
No copyright attached, so free for your use.

Similar Messages

  • When I use my iPhone and go into the iTunes  Store Search,  it clocks/gets-stuck in Loading.  Also if I select iTunes and App Store in Settings, nothing happens.  Any advice?  Thanks.

    When I use my iPhone and go into the iTunes Store Search, it clocks/gets-stuck in Loading.
    Also if I select iTunes and App Store in Settings, nothing happens.
    Any advice?
    Thanks.

    I guess no advice.  Thanks anyway.

  • OVD and Local Store Adapter

    Hi,
    Are there any samples for setting up a local store adapter for Oracle Virtual Directory?
    I have configured a local store adapter and when attempting to browse receive the message "Object Not Found". Obviously, the adapter isn't configured correctly.
    I suspect my text file is incorrect, but I can't find any information about the format of this file.
    Any help is most appreciated.
    Thanks,
    Ben

    Hi Ben,
    OVD is not creating root DN automatically. It means after creating Local Store Adapter, if you try to expand tree of root DN, it will say "No Such Object".
    You need to create domain object using any ldap client as your root dn.
    For example, if you have given rootDn as "dc=test,dc=com" in your local store adapter than
    using any ldap client (like I use Jexplorer ), connect to OVD over 389
    then first add a object which has objectclass = domain and dn= dc=com
    and than under dc=com, add another object which will have objectclass=domain and dc= dc=test,dc=com
    once you do this, you can add any other object and it will be store in local store adapter.
    regards,
    Nishidhdha

  • Selecting Multiple Keywords for an "AND" Images Selection

    When selecting images in iPhoto, one feature that I liked was the ability to fine-tune my image selection by choosing multiple Keywords. For example, I might have 50 images of Mary, either by herself or with other people, and one of the Keywords assigned to those 50 images is "Mary." I might also have 25 images of Joe, also either by himself or with other people, with one of the Keywords assigned of "Joe."
    Out of all my images, there might be 5 images that include both Mary and Joe together. In iPhoto, I could rapidly find those 5 images of Mary and Joe together by clicking and selecting the separate Keywords "Mary" and "Joe" from the list of all my iPhoto Keywords.
    Unless I'm missing something, the only way I have found to do this in Lightroom 1.0 is by typing both Mary and Joe in the FIND dialog box to find JUST the images of Mary and Joe together.
    It is my understanding that LR currently has an "OR" find command when I "COMMAND-click" (Mac) on the Mary and Joe keywords, LR displays ALL the images of Mary and Joe. I would like to see a feature in future versions of LR where I could "OPTION-click" on the Keywords that I had set up in LR that would then initiate an "AND" Find command for the Keywords selected so that LR displays images where Mary AND Joe appear together in the images.

    I did go to the LR Extras FAQ. However, I didn't find the specific references that you mention. I did notice a couple of topics that cover "intersections," but I don't think that addresses my specific request.
    For example, If I'm searching through ALL of my images and I want to DISPLAY only the images of that I've taken of rivers in California, I would like to be able to do it in LR in ONE keystroke(OPTION) and TWO mouse clicks (in iPhoto, you can do it in two mouse clicks).
    Currently, in LR 1.0, if I use the FIND panel, I would have to type in several keystrokes. If I don't have any COLLECTIONS for rivers or California, but do have KEYWORDS of "rivers" and "California," is there anyway I can select from the Keywords to have JUST the rivers in California displayed? To just have them highlighted only would force me to scroll through hundreds of pictures taken in California, when I might only have twenty photos of California rivers.
    I appreciate your offer of help and please point me in the right direction if I am missing something. I do plan to re-visit the site again as I can see that it contains a lot of good insightful info about LR. Thanks.

  • Examples of Global, Universal, and Local naming convention

    I am stuck on the types of naming conventions for global, universal, and local groups.
    For example, I have Managers, Clinical, VC, BC, Councilors, Accounting, Nurses, Payroll, Benefits, Company Policies/Form
    Which ones would you make global, universal and local?
    I was thinking of making Clinical, Accounting and Managers the global groups. Then make VC, BC, Nurses, Payroll, Benefits and Company Policies/Forms, Councilors the local groups.
    Since this is only a single domain, I was going to omit the universal group.
    What are your thoughts? Would this work?

    Greetings!
    There is really no difference in your scenario. If you have a single domain with no other child domains simply go for Global. The differences between these groups are related to membership of
    the users. For example in Global groups, users from other domains are not allowed to be member of the group.
    More information at:
    Group scope
    Regards.
    Mahdi Tehrani   |  
      |  
    www.mahditehrani.ir
    Please click on Propose As Answer or to mark this post as
    and helpful for other people.
    This posting is provided AS-IS with no warranties, and confers no rights.
    How to query members of 'Local Administrators' group in all computers?

  • Local image resize and upload

    Hi guys,
    I've been checking around the net for a way to implement the following:
    user wants to upload a large image. the image is resized locally on their computer to a 60kb small image. this image is then uploaded and used.
    Is there a way to do this with flash? or what is the best method? (NB: I'm not interested in using Java)
    thanks for any info or links.
    Jeff

    Well in short, you need a second language to support that,
    e.g. PHP/ASP/CF.
    First you'll have to build a GUi in which you can upload the
    jpg, putting it to the server using php/asp/cf, then you'll need to
    make a call to that image, (importing it into your flex), then
    you'll have to set the parameters for the resizing, then you'll
    have to call a php/asp/cf script which does te resizing

  • When I try and print an "Approach Plate, or Departure" from ForeFlight to my Epson Stylus NX430 using AirPrint the image is resized. How can I print without it resizing. I want to have the plate print in the original size so I can use it.

    When I try and print an "Approach Plate, or Departure" from ForeFlight to my Epson Stylus NX430 using AirPrint the image is resized. How can I print without it resizing. I want to have the plate print in the original size so I can use it. Is this an Apple, Epson, or Foreflight Issue? I just purchased the printer so I can return it and get a different model or brand. I spoke to Epson and the suggestions given did not resolve the issue. I have cut the paper down to the size of the plate roughly 5.5x8 and it still try's to print at 8.5x11. I have also requested help through ForeFlights Tech help but have yet to receive an answer.
    Please help!

    It varies based on what you ordered and whether it is in stock or has to be assenbled and shipped from China. Your email conformation should give an estimate of when the items are expected to be shipped or available for pick up if you are having it sent to a local Apple Store.

  • We are currently looking for a way to link images to a design file within programs like InDesign and Illustrator using an HTML link instead of a local file.  We are hosting our images in SharePoint and need the design file to retain it's links, no matter

    We are currently looking for a way to link images to a design file within programs like InDesign and Illustrator using an HTML link instead of a local file.  We are hosting our images in SharePoint and need the design file to retain it's links, no matter who on our network opens the design file.

    The Cloud forum is not about using individual programs
    The Cloud forum is about the Cloud as a delivery & install process
    If you will start at the Forums Index https://forums.adobe.com/welcome
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says All communities) to open the drop down list and scroll

  • Resizing text and images with actions and keeping it resized for the next slides, how to?

    Hello everybody,
    I searched over the net and in this support section for a solution to my problem, but i didnt find any, so...here I am asking you experts.
    Through a particular use of different actions I make a logo "compose" in the first slide of my presentation (the logo is composed by text and images that interact), then in the second slide i make it resize so it goes 50% of its size and moves down like a TV logo, in the corner of the slide, and I want it to stay there for all the lenght of the presentation.
    It might be a stupid problem, but I didnt understand how to keep it there, 50% of its size and always in that position. If i duplicate the slide I obviously duplicate the 100%-size-logo, not its 50%-size-version, and if i shrink it in order to make it be 50% of its size the text size doesnt shrink so i have to change the text size manually, but the visual effect is imperfect.
    Lets summarize:
    slide 1: text appears, image appears, the text and the image move and "compose" the logo
    slide 2: the complete logo reduces its size to 50% and moves in the lower corner of the presentation, in the place I want it to be for, lets say, 20 slides
    slide 3: i want to have this logo already reduced in size and in its position, in the right lower corner, but if i try to group the different parts of the composed logo and i try to squeeze them the font doesnt change its size, I only squeeze the area that the text occupies.
    Some help please guys?
    Thanks in advance,
    Dom-
    (add: the problem is kind of similar to this: https://discussions.apple.com/message/9179367#9179367 . the idea of making a slide that contains the logo and text in the exact positions they would be after the move and scale actions is good and that was my first attempt, the probem is that it looks impossible to me to create a second "little" version of the logo that looks exactly the same of the first one that i reduced, so i hope there is some way to tell the app to use "the first logo, only resized the way i want", and thats the point where the problem with the size of the text comes out)

    Hi pritam,
    The “maintain proportions of window for different monitor
    resolutions” property will maintain the proportional size of the front panel
    (its x and y sizes) when opened in a different resolution. The front panel
    objects will not be resized and will appear larger (and may not fit inside the
    front panel) when saved in a higher resolution, and moved to a lower
    resolution. You can use the “Keep window proportions” property to achieve the
    same results.
    To have both the front panel dimensions and front panel
    controls scale, you need to have both the above property and the “scale all
    objects on front panel as the window resizes” selected. The labels will not be
    resized by this.
    I tried using both properties on two monitors and noticed
    that the change does not occur when the resolutions between the monitors are
    different. I had to lower both monitors’ resolution to see the change work
    properly.
    Please post back if you have any questions. Have a great day!
    Ryan D.
    District Sales Manager for Boston & Northern New England
    National Instruments

  • How do import an image into CS3 and resize it?

    Hi, let me say first I know very little of Illustrator C3.  I have a poster that was created by someone else.  I'm supposed to take that image and resize to fit on a pop up banner.  I created a new doc in Ill. with the correct dimensions and copied and pasted the image.  Now how to I get the original image with layers to conform to the new doc. sizing?  I need to take the image and enlarge it and make it fit within the confines of my new doc.  How do I do that without distorting the image.

    Shift, Ctrl and Alt modifier keys offer constraining options in all Adobe programs. Shift will retain proportions, Alt scale from the center etc. and when combined you can scale constrained from the center. anyway, the question is, what you are referring to by "image". Bitmaps as in photographs or other pixel images? Then AI is the wrong choice. You need to do such things in Photoshop. If its a PDF or another AI file, scaling should be no problem. you may just wish to group items before doing so to retain their relative placement within teh group and avoid unpleasant surprises when you only mass-select them.
    Mylenium

  • Image resizing and cropping

    Hi,
    I want to convert images to thumbnails with a 'standard' format - I need all images to have the same width and height.
    So I need to resize and then crop the images. Is this possibe with JAI? Are there other libraries which can do this better?
    I've read about ImageMagick - are the Java interfaces to ImageMagick good?
    /regards, Håkan Jacobsson

    Depending on the format of your files, you need not go into JAI. You may be able to do what you want with ImageIO.
    You just need to load the image, select the part you want, then check the length to width ratio to make sure it is appropriate, if not, then adjust it as such.
    If you want to get a 100, 100 thumb from a 1024, 768 image you can do this:
    BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bi.createGraphics();
    g.drawImage(my1024x768, 0, 12, 100, 75, Color.BLACK, null);
    g.dispose();please note, that to get 1024 shunk up to 100, you need to divide by 10.24, when you do the same to the height of the image, you get 75, this leaves 25 pixels--so I centered the image at 12.
    to save the thumb in JPG:
    File f = new File(myFileNameAndPath);
    f.createFile();
    ImageIO.write(bi, "JPEG", f);**WARNING** untested code.

  • How can i do a batch resize and watermark on an entire file of images

    I would like to resize and watermark all of the image in a particular file.  I understand that I can do this with Lightroom, but I do now know how.
    Can someone give me some helpful pointers.
    David Levin

    If you mean "entire folder of images" instead of "entire file of images", then select the desired folder, then select all images (Ctrl-A), then export the photos. In the export dialog box are the options that will allow you to set the desired size and set the desired watermark.

  • Please add "resize image before uploading" and "do...

    SOME of us do NOT want to send bothersome, huge images over mobile devices just to share a pointless moment with a friend - or an enemy.
    Wechat already has this AWESOME feature, so maybe Skype should have one too - as it is so cumbersome to go into another program to resize and save an image before sending it.
    Please add a button to have a possibility of sending a low resoluton version of all images and also before downloading an image to check out if it is worth the money and bandwidth.
    Sincerely, The Wrath of Diego

    You can resize some bitmap, or movieClip, etc. to a new size by making a new bitmapData at the desired size and drawing the source into the new bitmapData. When doing the draw use a Matrix to accomplish the scaling. Something like so:
    var newBitmapData:BitmapData = new BitmapData(320, 240);
    var m:Matrix = new Matrix();
    m.scale(newBitmapData.width / originalBitmapData.width, newBitmapData.height / originalBitmapData.height);
    newBitmapData.draw(originalBitmapData, m);

  • Could you please tell me why as a Brit resident in Japan therefore having a billing address that is Japanese is forced to only get service from the Japanese online store? Is there not some way of allowing me to select movies and music to buy and download

    Could you please tell me why as a Brit resident in Japan therefore having a billing address that is Japanese is forced to only get service from the Japanese online store? Is there not some way of allowing me to select movies and music to buy and download from other stores. Why do am i forced to try to nread Japanese when I have selected English as my language. The price for Downloads is no different and even if it was I am happy to pay. This also applies to Movie rental which is crazy and extremely restrictive. I a supposed GLOBAL community why does Apple do this.

    You can buy ONLY from the itunes store of your country of residence (As proven by valid billing address of credit card) and ONLY while inside the borders of that country.
    These are the terms of the itunes store.

  • How to get the data from mysql database which is being accessed by a PHP application and process the data locally in adobe air application and finally commit the changes back in to mysql database through the PHP application.

    How to get the data from mysql database which is being accessed by a PHP application and process the data locally in adobe air application and finally commit the changes back in to mysql database through the PHP application.

    If the data is on a remote server (for example, PHP running on a web server, talking to a MySQL server) then you do this in an AIR application the same way you would do it with any Flex application (or ajax application, if you're building your AIR app in HTML/JS).
    That's a broad answer, but in fact there are lots of ways to communicate between Flex and PHP. The most common and best in most cases is to use AMFPHP (http://amfphp.org/) or the new ZEND AMF support in the Zend Framework.
    This page is a good starting point for learning about Flex and PHP communication:
    http://www.adobe.com/devnet/flex/flex_php.html
    Also, in Flash Builder 4 they've added a lot of remote-data-connection functionality, including a lot that's designed for PHP. Take a look at the Flash Builder 4 public beta for more on that: http://labs.adobe.com/technologies/flashbuilder4/

Maybe you are looking for

  • How do I get rid of shadow Title boxes in idvd

    I have been making dvd's using idvd for some years and have had few problems. Current version is 7.1.2  When I have done so, if I add a title or any comments to a photograph they appear in a 'shadow box' and if I do not no 'shadow box' has appeared o

  • Photos not appearing in adobe reader

    I've created a pdf from a Pages document using the print dialog and and the photos contained in the pdf won't appear using Adobe Reader (I'm running Snow Leopard), but they do display using Quick Look and Preview.  My neighbor has a Mac (running Lion

  • How to save a word document to word on  ipad

    I opened a document from my emails on Microsoft word. I edited the document and now want to save it as the new edited version but how do i do that? If i press the back button i lose everything and i cannot see anything that can help me? Thank you ple

  • How to Export AAF in sections?

    Ok I have a 2 hour project with R3Ds. I don't want to export an AAF of the whole timeline. Can you export an AAF of just a section of the timeline? In AVID this is possible. Thanks!

  • TS1368 How to I get out of Spanish store & into US one?

    Trying to download apps on my iphone and it says I'm connected to the Spanish store & need to switch back to US one. I'm in Spain at the moment. How can I fix this problem?