1.将图片拷贝到以下目录: app\src\main\res\mipmap-hdpi
2.AndroIDManifest.xml
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="com.glsite.girl"> <application androID:allowBackup="true" androID:icon="@mipmap/ic_launcher" androID:label="@string/app_name" androID:roundIcon="@mipmap/ic_launcher_round" androID:supportsRtl="true" androID:theme="@style/Apptheme"> <activity androID:name=".MainActivity"> <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
3.activity_main.xml
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" tools:context=".MainActivity"> <ImageVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_centerInParent="true" androID:src="@mipmap/after19"/> <ImageVIEw androID:ID="@+ID/iv" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_centerInParent="true" androID:src="@mipmap/pre19"/></relativeLayout>
4.MainActivity.java
package com.glsite.girl;import androID.graphics.Bitmap;import androID.graphics.BitmapFactory;import androID.graphics.Canvas;import androID.graphics.color;import androID.graphics.Matrix;import androID.graphics.Paint;import androID.support.v7.app.AppCompatActivity;import androID.os.Bundle;import androID.vIEw.MotionEvent;import androID.vIEw.VIEw;import androID.Widget.ImageVIEw;public class MainActivity extends AppCompatActivity implements VIEw.OntouchListener { private ImageVIEw mIv; private int mStartX; private int mStartY; private Bitmap mNewBitmap; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initVIEw(); initData(); initEvent(); } /** * 初始化事件 */ private voID initEvent() { mIv.setontouchListener(this); } /** * 初始化数据 */ private voID initData() { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.pre19); // 得到原图的拷贝 mNewBitmap = bitmap.createBitmap(bitmap.getWIDth(), bitmap.getHeight(), bitmap.getConfig()); Canvas canvas = new Canvas(mNewBitmap); Paint paint = new Paint(); paint.setcolor(color.BLACK); canvas.drawBitmap(bitmap, new Matrix(), paint); } /** * 初始化界面 */ private voID initVIEw() { setContentVIEw(R.layout.activity_main); mIv = findVIEwByID(R.ID.iv); } @OverrIDe public boolean ontouch(VIEw v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mStartX = (int) event.getX(); mStartY = (int) event.getY(); System.out.println("按下:" + mStartX + ", " + mStartY); mNewBitmap.setPixel(mStartX, mStartY, color.transparent); mIv.setimageBitmap(mNewBitmap); break; case MotionEvent.ACTION_MOVE: int newX = (int) event.getX(); int newY = (int) event.getY(); System.out.println("移动:" + newX + ", " + newY); for (int i = -3; i < 4; i++) { for (int j = -3; j < 4; j++) { mNewBitmap.setPixel(newX + i, newY + j, color.transparent); } } mIv.setimageBitmap(mNewBitmap); break; case MotionEvent.ACTION_UP: break; default: break; } return true; }}
总结
以上是内存溢出为你收集整理的简易撕衣服游戏android全部内容,希望文章能够帮你解决简易撕衣服游戏android所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)