Easy Tutorial
❮ Express 4 X Api Cloud Atlas Engineer Skills ❯

8.3.13 Paint API - Shader (Image Rendering)

Category Android Basic Tutorial

1. Detailed Constructor Methods


1) BitmapShader (Image Rendering)

BitmapShader(Bitmap bitmap, Shader.TileMode tileX, Shader.TileMode tileY)

>

Uses a bitmap as a texture to fill a region. Parameters are:

-bitmap: The bitmap used for filling;

-tileX: The tiling mode for the bitmap in the X-axis direction;

-tileY: The tiling mode for the bitmap in the Y-axis direction;

The Shader.TileMode has three types:

-CLAMP: If the renderer exceeds the original boundary, it will copy the edge color to shade the超出范围的区域

-REPEAT: Repeats the texture in a tiled manner

-MIRROR: Repeats the bitmap in a mirrored fashion both horizontally and vertically.


2) ComposeShader (Mixed Rendering)

ComposeShader(Shader shaderA, Shader shaderB, PorterDuff.Mode mode)

>

Overlays rendering effects. Seeing PorterDuff should give you a hint. For example, mixing BitmapShader with LinearGradient. Parameters are:

-shaderA: The first rendering effect

-shaderB: The second rendering effect

-mode: The mode for combining the two rendering effects


3) LinearGradient (Linear Rendering)

LinearGradient(float x0, float y0, float x1, float y1, int[] colors, float[] positions, Shader.TileMode tile);

>

Achieves a linear gradient effect within a region. Parameters are:

-x0: The starting x-coordinate of the gradient

-y0: The starting y-coordinate of the gradient

-x1: The ending x-coordinate of the gradient

-y1: The ending y-coordinate of the gradient

-colors: The array of gradient colors

-positions: The relative positions of the colors

-tile: The tiling mode


4) RadialGradient (Radial Rendering)

public RadialGradient (float x, float y, float radius, int[] colors, float[] positions, Shader.TileMode tile);

>

Achieves a radial gradient effect within a region. Parameters are:

-x: The center x-coordinate of the circle

-y: The center y-coordinate of the circle

-radius: The radius of the circle

-colors: The array of radial gradient colors

-positions: The relative positions of the colors

-tile: The tiling mode


5) SweepGradient (Gradient Rendering)

public SweepGradient (float cx, float cy, int[] colors, float[] positions)

>

Scans the rendering, creating an effect that forms by rotating around a central point. Parameters are:

-cx: The center x-coordinate of the scan

-cy: The center y-coordinate of the scan

-colors: The array of gradient colors

-positions: The relative positions of the colors


While the text might give a rough idea of their functions, it's better to write some code to verify their effects. After all, seeing is believing.


2. Example Code:

Output: -1.4 Genymotion Emulator Installation

-1.5.1 Git Tutorial: Basic Operations on Local Repositories

-1.5.2 Using Git to Set Up a Remote Repository on GitHub

-1.6 How to Use the 9(Nine Sisters) Image

-1.7 Interface Prototype Design

-1.8 Project Analysis (Various Files, Resource Access)

-1.9 Android App Signing and Packaging

-1.11 Decompiling APK to Obtain Code & Resources

-2.1 Concepts of View and ViewGroup

-2.2.1 LinearLayout (Linear Layout)

-2.2.2 RelativeLayout (Relative Layout)

-2.2.3 TableLayout (Table Layout)

-2.2.4 FrameLayout (Frame Layout)

-2.2.5 GridLayout (Grid Layout)

-2.2.6 AbsoluteLayout (Absolute Layout)

-2.3.1 Detailed Explanation of TextView (Text Field)

-2.3.2 Detailed Explanation of EditText (Input Field)

-2.3.3 Button and ImageButton

-2.3.4 ImageView (Image View)

-2.3.5 RadioButton (Radio Button) & Checkbox (Checkbox)

-2.3.6 ToggleButton and Switch

-2.3.7 ProgressBar (Progress Bar)

-2.3.8 SeekBar (Drag Bar)

-2.3.9 RatingBar (Star Rating Bar)

-2.4.1 ScrollView (Scroll Bar)

-2.4.2 Date & Time Components (Part 1)

-2.4.3 Date & Time Components (Part 2)

-2.4.4 Adapter Basics

-2.4.5 Simple Usage of ListView

-2.4.6 Optimization of BaseAdapter

-2.4.7 Focus Issues with ListView

-2.4.8 Solving Checkbox Misalignment in ListView

-2.4.9 Data Update Issues in ListView

-2.5.0 Building a Reusable Custom BaseAdapter

-2.5.1 Implementing Multi-Layout ListView Items

-2.5.2 Basic Usage of GridView (Grid View)

-2.5.3 Basic Usage of Spinner (List Spinner)

-2.5.4 Basic Usage of AutoCompleteTextView (Auto-Complete Text Field)

-2.5.5 Basic Usage of ExpandableListView (Expandable List)

-2.5.6 Basic Usage of ViewFlipper (Flip View)

-2.5.7 Basic Usage of Toast

-2.5.8 Detailed Explanation of Notification (Status Bar Notification)

-2.5.9 Detailed Explanation of AlertDialog (Dialog Box)

-2.6.0 Basic Usage of Other Common Dialogs

-2.6.1 Basic Usage of PopupWindow (Floating Box)

-2.6.2 Menu (Menu)

-2.6.3 Simple Usage of ViewPager

-2.6.4 Simple Usage of DrawerLayout (Official Side Sliding Menu)

-3.1.1 Event Handling Mechanism Based on Listeners

-3.2 Event Handling Mechanism Based on Callbacks

-3.3 Analysis of Handler Message Passing Mechanism

-3.4 TouchListener vs OnTouchEvent + Multi-Touch

-3.5 Listening for Content Changes in EditText

-3.6 Responding to System Setting Events (Configuration Class)

-3.7 AsyncTask Asynchronous Task

-3.8 Gestures (Gestures)

-4.1.1 Activity: Beginner Level

-4.1.2 Activity: Intermediate Level

-4.1.3 Activity: Advanced Level

-4.2.1 Introduction to Service

-4.2.2 Advanced Service

-4.2.3 Expert Service

-4.3.1 BroadcastReceiver: Beginner Level

-4.3.2 BroadcastReceiver: Intermediate Level

-4.4.1 Introduction to ContentProvider

-4.4.2 Deeper Look into ContentProvider – Document Provider

-4.5.1 Basic Usage of Intent

-4.5.2 Passing Complex Data with Intent

-5.1 Basic Overview of Fragment

-5.2.1 Fragment Example: Implementing Bottom Navigation Bar (Method 1)

-5.2.2 Fragment Example: Implementing Bottom Navigation Bar (Method 2)

-5.2.3 Fragment Example: Implementing Bottom Navigation Bar (Method 3)

-5.2.4 Fragment Example: Bottom Navigation Bar + ViewPager for Swiping Pages

-5.2.5 Fragment Example: Simple Implementation of News (Shopping) App List Fragment

-6.1 Data Storage and Access – File Storage and Reading

-6.2 Data Storage and Access – Saving User Preferences with SharedPreferences

-6.3.1 Data Storage and Access – Introduction to SQLite Database

-6.3.2 Data Storage and Access – Further into SQLite Database

WeChat Subscription

❮ Express 4 X Api Cloud Atlas Engineer Skills ❯