Android image processing technology (implementing PS in Android) (5), image processing android

Source: Internet
Author: User

Android image processing technology (implementing PS in Android) (5), image processing android

Today is the fifth blog on Android image processing technology. It is a bit more, mainly to take care of the students with weak foundations. However, we all use a coherent example to explain, and provide a Demo with a detailed comment. Through the first four blog posts, we must have some knowledge about image processing technology, starting from this blog post, only key code segments are pasted. Other irrelevant codes (such as xml layout files) are not pasted. I will attach a Demo for you to download and reference. (PS: it is hoped that everyone will cherish the downloaded code to receive a credit value. After all, it is written in one line. It is also a respect for my own work, please forgive me ...)

Let's start with today's explanation: Use the paint brush style Xfermode and Shader to process images.

First, the effect is displayed:

First, we will introduce Xfermode:

Then we will introduce Shader:

Below we will post the main code for changing the image using Xfermode:

Custom XfermodeView:

Public class XfermodesView extends View {private Bitmap mBitmap, mOutBitmap; private Paint mPaint; public XfermodesView (Context context, AttributeSet attrs) {super (context, attrs); initView ();} private void initView () {// disable hardware acceleration, otherwise it will not achieve the expected results; setLayerType (LAYER_TYPE_SOFTWARE, null); // load the image mBitmap = BitmapFactory from the resource. decodeResource (getResources (), R. drawable. a); mOutBitmap = Bitmap. createBitmap (mBitmap. g EtWidth (), mBitmap. getHeight (), Config. ARGB_8888); // Config. ARGB_8888 anti-sawtooth Canvas canvas = new Canvas (mOutBitmap); mPaint = new Paint (Paint. ANTI_ALIAS_FLAG); // Dst // these are all very simple .. Canvas. drawRoundRect (new RectF (50, 50, mBitmap. getWidth (), mBitmap. getHeight (), 50, 50, mPaint); // Src // set mode: mPaint. setXfermode (new porterduduxfermode (Mode. SRC_IN); canvas. drawBitmap (mBitmap, 0, 0, mPaint); // restore mPaint. setXfermode (null) ;}@ Override protected void onDraw (Canvas canvas) {super. onDraw (canvas); canvas. drawBitmap (mOutBitmap, 0, 0, null );}}

I think this code is not difficult if I have read the previous blog posts.

Then let's see how to customize ShaderView:

Public class BitmapShaderView extends View {private Bitmap mBitmap; private Paint mPaint; private BitmapShader mShader; public BitmapShaderView (Context context, AttributeSet attrs) {super (context, attrs ); mPaint = new Paint (); mBitmap = BitmapFactory. decodeResource (getResources (), R. drawable. a); // set the Shader mode: mShader = new BitmapShader (mBitmap, Shader. tileMode. CLAMP, Shader. tileMode. CLAMP); // bind the preset shader to the mPaint of the paint brush. setShader (mShader) ;}@ Override protected void onDraw (Canvas canvas) {super. onDraw (canvas); canvas. drawCircle (200,200, 50, mPaint );}}

OK.

Finally, Demo address: http://download.csdn.net/detail/nsgsbs/8538579

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.