Android and android

Source: Internet
Author: User

Android and android

This article mainly implements a small game project for opening beautiful clothes

The effect is as follows:

Project Layout Design:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity" >    <ImageView        android:id="@+id/iv_after"        android:layout_width="wrap_content"        android:layout_height="wrap_content" />    <ImageView        android:id="@+id/iv_pre"        android:layout_width="wrap_content"        android:layout_height="wrap_content" /></FrameLayout>

Logic code:

Public class MainActivity extends Activity {private ImageView iv_after; private ImageView iv_before; private Bitmap alterBitmap; private Canvas canvas; private Paint paint; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); BitmapFactory. options opts = new Options (); opts. inSampleSize = 2; iv_after = (ImageView) findViewById (R. id. iv_after); iv_before = (ImageView) findViewById (R. id. iv_pre); Bitmap after = BitmapFactory. decodeResource (getResources (), R. drawable. after19, opts); Bitmap before = BitmapFactory. decodeResource (getResources (), R. drawable. pre19, opts); // you can modify the blank bitmap alterBitmap = Bitmap. createBitmap (before. getWidth (), before. getHeight (), before. getConfig (); canvas = new Canvas (alterBitmap); paint = new Paint (); paint. setStrokeWidth (5); paint. setColor (Color. BLACK); canvas. drawBitmap (before, new Matrix (), paint); Evaluate (after); transform (alterBitmap); iv_before.setOnTouchListener (new OnTouchListener () {@ Override public boolean onTouch (View v, motionEvent) {switch (event. getAction () {case MotionEvent. ACTION_DOWN: break; case MotionEvent. ACTION_MOVE: int newX = (int) event. getX (); int newY = (int) event. getY (); for (int I =-6; I <6; I ++) {for (int j =-6; j <6; j ++) {alterBitmap. setPixel (I + newX, j + newY, Color. TRANSPARENT) ;}} iv_before.setImageBitmap (alterBitmap); break; case MotionEvent. ACTION_UP: break; default: break;} return true ;}});}}

 

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.