日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

是男人就下100层【第二层】——帮美女更衣(2)

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 是男人就下100层【第二层】——帮美女更衣(2) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前一篇《是男人就下100層【第二層】——幫美女更衣(1)》介紹了ImageSwitcher組件的使用,并完成了展示,這一篇我們來完成剩下的部分吧。

在點擊圖片的時候跳到另一個Activity并將該圖片的序號傳過去。

is.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v){Intent intent = new Intent();intent.putExtra("imagePosition", gallery.getSelectedItemPosition());intent.setClass(MainActivity.this, RemoveClothActivity.class);startActivity(intent);}});創建一個View對象,如下:

class MyView extends View {private Bitmap mBitmap;private Canvas mCanvas;private Paint mPaint;private Path mPath;private float mX, mY;private static final float TOUCH_TOLERANCE = 4;public MyView(Context context) {super(context);setFocusable(true);//獲取屏幕寬高setScreenWH();//設置背景圖片setBackGround();int drawableId = 0;try {drawableId = R.drawable.class.getDeclaredField("pre" + imagePosition).getInt(this);} catch (IllegalArgumentException e) {e.printStackTrace();} catch (SecurityException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();} catch (NoSuchFieldException e) {e.printStackTrace();}//獲取圖片資源并全屏顯示Bitmap bm = scaleBitmapFillScreen(BitmapFactory.decodeResource(getResources(), drawableId));seticon1Bitmap(bm);}private void setScreenWH() {//獲取屏幕信息DisplayMetrics dm = new DisplayMetrics();dm = this.getResources().getDisplayMetrics();//獲取屏幕寬度int screenWidth = dm.widthPixels;//獲取屏幕高度int screenHeight = dm.heightPixels;SCREEN_W = screenWidth;SCREEN_H = screenHeight;}private Bitmap createBitmapFromSRC() {return BitmapFactory.decodeResource(getResources(),R.drawable.icon1);}private Bitmap createBitmapFromARGB(int colorARGB, int width, int height) {int[] argb = new int[width * height];for (int i = 0; i < argb.length; i++) {argb[i] = colorARGB;}return Bitmap.createBitmap(argb, width, height, Config.ARGB_8888);}private Bitmap setBitmapAlpha(Bitmap bm, int alpha) {int[] argb = new int[bm.getWidth() * bm.getHeight()];bm.getPixels(argb, 0, bm.getWidth(), 0, 0, bm.getWidth(),bm.getHeight());for (int i = 0; i < argb.length; i++) {argb[i] = ((alpha << 24) | (argb[i] & 0x00FFFFFF));}return Bitmap.createBitmap(argb, bm.getWidth(), bm.getHeight(),Config.ARGB_8888);}private Bitmap scaleBitmapFillScreen(Bitmap bm) {return Bitmap.createScaledBitmap(bm, SCREEN_W, SCREEN_H, true);}private void setBackGround() {int drawableId = 0;try {drawableId = R.drawable.class.getDeclaredField("after" + imagePosition).getInt(this);} catch (IllegalArgumentException e) {e.printStackTrace();} catch (SecurityException e) {e.printStackTrace();} catch (IllegalAccessException e) {e.printStackTrace();} catch (NoSuchFieldException e) {e.printStackTrace();}setBackgroundResource(drawableId);}private void seticon1Bitmap(Bitmap bm) {// 設置畫筆mPaint = new Paint();//設置透明度為0mPaint.setAlpha(0);//設置兩張圖片相交時的模式//詳細請參考:http://trylovecatch.iteye.com/blog/1189452mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));mPaint.setAntiAlias(true);mPaint.setDither(true);mPaint.setStyle(Paint.Style.STROKE);//設置結合處為圓弧mPaint.setStrokeJoin(Paint.Join.ROUND);//設置畫筆為圓弧狀mPaint.setStrokeCap(Paint.Cap.ROUND);//畫筆寬度mPaint.setStrokeWidth(20);mPath = new Path();//創建一張圖片mBitmap = Bitmap.createBitmap(SCREEN_W, SCREEN_H, Config.ARGB_8888);mCanvas = new Canvas();//設置為畫布背景mCanvas.setBitmap(mBitmap);//繪制圖片到畫布mCanvas.drawBitmap(bm, 0, 0, null);}@Overrideprotected void onDraw(Canvas canvas) {canvas.drawBitmap(mBitmap, 0, 0, null);mCanvas.drawPath(mPath, mPaint);super.onDraw(canvas);}private void touch_start(float x, float y) {mPath.reset();mPath.moveTo(x, y);mX = x;mY = y;}private void touch_move(float x, float y) {float dx = Math.abs(x - mX);float dy = Math.abs(y - mY);if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);mX = x;mY = y;}}private void touch_up() {mPath.lineTo(mX, mY);// 開始繪制mCanvas.drawPath(mPath, mPaint);// 重新開始繪制路線mPath.reset();}@Overridepublic boolean onTouchEvent(MotionEvent event) {float x = event.getX();float y = event.getY();switch (event.getAction()) {case MotionEvent.ACTION_DOWN:touch_start(x, y);invalidate();break;case MotionEvent.ACTION_MOVE:touch_move(x, y);invalidate();break;case MotionEvent.ACTION_UP:touch_up();invalidate();playMusic();break;}return true;}}
具體請看代碼注釋

基本原理請看:http://blog.csdn.net/dawanganban/article/details/17439667


源代碼下載:http://download.csdn.net/detail/lxq_xsyu/7014889






轉載于:https://www.cnblogs.com/lanzhi/p/6469140.html

總結

以上是生活随笔為你收集整理的是男人就下100层【第二层】——帮美女更衣(2)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。