Android Concise Development Tutorial 12: Guide Bee two-dimensional graphic library introduction and Color sample

Source: Internet
Author: User
Tags abstract java se

Androidgraphics2dtutorial defines the main activity of the application, and you can start writing each of the concrete two-dimensional drawing examples below. Different examples will try to adopt different UI controls: Menu,content Menu,dialog,custom Dialog,button, and so on. Example uses the Guide bee two-dimensional graphics library, the Guide Bee two-dimensional graphics library graphics 2D API implements the mobile platform (Java me,blackberry,iphone,android,windows Phone) on the graphics engine, it can be a unified Handles a variety of basic graphics (shape), path (path), text (texts), appropriate fonts, and images. Simply put, the Graphics 2D API implements a two-dimensional graphics library API similar to its corresponding Java se.

The main functions are as follows:

supports a variety of basic graphics: curves, rectangles, ellipses, etc; supports drawing arbitrary geometry

Supports collision detection on graphics, style, and image

Enhanced color support and color management

Controlling the quality of graphic drawing

padding, outer frame, various line drawing

Two-dimensional graphic transformation

Vector fonts

From left to right, from right to left, to display style from top to bottom

Anti-aliasing

Transparency support

icons, and image rendering

For more information, see examples of two-dimensional graphics library of Silverlight Guide Bees

We are in the Android Concise development Tutorial IX: Creating an application framework defines a base class Graphics2dactivity as the parent class for all sample activity:

Public abstract class Graphics2dactivity extends activity{
Protected graphics2d graphics2d =sharedgraphics2dinstance.graphics2d;
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
}
protected abstract void drawImage ();
public void OnStart () {
Super.onstart ();
DrawImage ();
}
}

Where Graphics2D is a graphical artboard object (Canvas) is represented by a two-dimensional integer array of width x height. Each value of this array is an integer of 32. The format is ARGB, representing transparency, red, green, and blue, respectively. The drawing operations on the artboard (dots, lines, polygons, fills, and so on) modify these color values.

Guidebeegraphics2dsurfaceview or Guidebeegraphics2dview can be used as the display result of the artboard in R.layout.main.

Abstract method protected abstract void DrawImage (), which is used to draw different content.

Modify Com.pstreets.graphics2d.example.Colors to use the Guide bee two-dimensional graphics library to draw different colors, if you have previously used Java SE or the. Net Framework, You'd think the guide bee. The two-dimensional graphics library provides APIs that are very similar to those of the code, which is well understood.

public class Colors extends graphics2dactivity{
protected void DrawImage () {
/**
* The solid (full opaque) red color on the ARGB space
*/
Color Redcolor = new color (0xffff0000);
/**
* The Semi-opaque green color in the ARGB spaces (Alpha is 0x78)
*/
Color Greencolor = new color (0x7800ff00,true);
/**
* The Semi-opaque blue color in the ARGB spaces (Alpha is 0x78)
*/
Color Bluecolor = new color (0x780000ff,true);
/**
* The Semi-opaque yellow color in the ARGB spaces (Alpha is 0x78)
* * Color Yellowcolor = new color (0x78ffff00,true);
/**
* The dash array
*/
int dasharray[] = {20, 8};
Graphics2d.clear (Color.White);
SolidBrush brush=new SolidBrush (Redcolor);
Graphics2d.filloval (brush,30,60,80,80);
Brush=new SolidBrush (Greencolor);
Graphics2d.filloval (brush,60,30,80,80);
Pen pen=new Pen (yellowcolor,10,pen.cap_butt,pen.join_miter,dasharray,0);
Brush=new SolidBrush (Bluecolor);
Graphics2d.setpenandbrush (Pen,brush);
Graphics2d.filloval (null,90,60,80,80);
Graphics2d.drawoval (null,90,60,80,80);
}
}

Colors activity is very simple, except view, there is no other UI. You can return to the sample list to display the UI when you press back.

See a full set of tutorials: http://www.bianceng.cn/OS/extra/201301/35252.htm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.