Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Importing bitmaps and vector graphics

From: EaselJS First Look

Video: Importing bitmaps and vector graphics

You don't always want to or need to create graphics with EaselJS. You may want create more complex graphics in a separate program and import them into your stage. EaselJS provides the bitmap class that lets you easily bring not just bitmap data, but most types of external graphics, so let's take a look. The bitmap class is a child of the DisplayObject. You may want to check out some of the methods and property of the DisplayObject class as well as the bitmap class in the EaselJS documentation. So I am starting off with a basic HTML template. If you haven't already, make sure you watch the video on creating a template and installing EaselJS.

Importing bitmaps and vector graphics

You don't always want to or need to create graphics with EaselJS. You may want create more complex graphics in a separate program and import them into your stage. EaselJS provides the bitmap class that lets you easily bring not just bitmap data, but most types of external graphics, so let's take a look. The bitmap class is a child of the DisplayObject. You may want to check out some of the methods and property of the DisplayObject class as well as the bitmap class in the EaselJS documentation. So I am starting off with a basic HTML template. If you haven't already, make sure you watch the video on creating a template and installing EaselJS.

To the basic template we've added a script file that already has a canvas, a stage, as well as an animation using the Ticker class. I've also added a few images in different formats in an images folder. Let's go ahead and add one of them to the stage. To the bitmap class we just need to pass along the location of the image we want to add, and then we need to add it as a child of the stage. So I am going to save this, and I will come over here and refresh my page and our graphic should appear right there at the top of the stage. We can import any type of valid HTML graphic format.

We could switch this to a GIF file--I'll save and refresh--or a JPEG, or any other graphic format our browser will handle. Let me go ahead and switch it back to PNG. Now let's add some variables that keep track of the center of our canvas, and let's go ahead and center our bitmap. I'll refresh my graphic, and it's not exactly centered. It is placing the graphic in the center of the screen. Because the graphic gets placed on the screen from the center position, we need to adjust the graphic's registration point. I know this graphic is 100x100 pixels tall because I drew it that way, so my registration is going to be adjusted by 50 pixels.

I'll save it and refresh and now our graphic is centered on screen. You always have to remember to set the registration point of any bitmap you bring in. So if the file is a vector, you can also use the SVG format, which stands for scalable vector graphics. The SVG format is a lot more resizable than PNG or other formats. So all you have to do is just specify that extension, SVG, save it, and the graphic comes along just fine. Now to save in SVG, you can use a program like Adobe Illustrator to save your graphic in the SVG format.

This is a vector file, one object that I drew, so I can take this graphic and go to the File menu and select Save As. Don't select Export or Save for Web. Save As will give you an option to save as an SVG graphic. You don't want to choose SVG Compressed, just regular SVG is fine. Let me go ahead and put this on the desktop. So once we do that just hit Save and just leave these options looking like this. The default are usually just fine. And I'll click OK and that saves my graphic as an SVG file.

I've already done that in my example, so you could see that it brought it in just fine. Now let's go ahead and scale this graphic by 400% to see how a vector graphic draws smoothly. I am going to save and then refresh the screen; you can see that in the bigger size this graphic looks awesome. Now what happens if we change to PNG? Save it and refresh, you'll see that our PNG looks a lot more pixelated and a little bit blurry. That's because PNG graphics are not vector graphics, they are bitmaps. So if you try the different formats, you are going to find that SVG is going to scale the best; however, because the graphics have to be recalculated and SVG is a vector, performance is going to be a little slower with SVG graphics.

So animating bitmaps is just like animating any other type of DisplayObjects. Since the bitmap class is a child of the DisplayObject, like a shape it's going to inherit properties like rotation and scaling. We've already done scaling here, let's try rotation. Go ahead and switch it back to the original size, I'll go ahead and use an SVG, I'll refresh, then I'll modify this ship's rotation in the animation section. Save this and it will rotate by 5 degrees on every frame. There's more to the bitmap class, so make sure you check out the documentation on the EaselJS page.

So importing graphics is super simple. The bitmap class is flexible enough it will let you import in many different formats. You may want to use SVG graphics when scaling is critical and the rest of the bitmap formats when performance is more important.

Show transcript

This video is part of

Image for EaselJS First Look
EaselJS First Look

21 video lessons · 4958 viewers

Ray Villalobos
Author

 

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed EaselJS First Look.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.