<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                下面這個代碼實現的是用通過雙指拉伸或者收縮實現圖片的放大或者縮小。這里面注意幾點: 1)多點觸控的那些常量,這里面的知識參考博客: http://blog.csdn.net/barryhappy/article/details/7392326 2)Bitmap的回收機制。這里面多次創建Bitmap會引起內存不足,下面并沒有解決這個問題,所以多次拉伸之后程序會掛掉。。 3)后記:這句話是后面加的。上面這個問題已經解決了,詳情請看我的另一篇博客: http://blog.csdn.net/hhysirius/article/details/21525105 ~~~ package com.example.mytest; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.os.Bundle; import android.util.FloatMath; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; import android.widget.ImageView; public class MainActivity extends Activity { private ImageView iv; private Bitmap bm; private Bitmap alterBm; private Bitmap temp; private Paint paint; private Matrix matrix; //舊的兩指距離 private float oldDis = 0.0f; //新的兩指距離 private float newDis = 0.0f; //判斷是否是雙指 private boolean flag = false; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); iv = (ImageView) this.findViewById(R.id.iv); bm = BitmapFactory.decodeResource(getResources(), R.drawable.xiamu); temp = bm.copy(bm.getConfig(), true); alterBm = bm.copy(bm.getConfig(), true); paint = new Paint(); paint.setColor(Color.BLACK); matrix = new Matrix(); iv.setImageBitmap(alterBm); iv.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub switch (event.getAction()&MotionEvent.ACTION_MASK) { //第一個手指按下 case MotionEvent.ACTION_DOWN: break; //第二個手指按下 case MotionEvent.ACTION_POINTER_DOWN: flag = true; oldDis = spacing(event); break; //手指移動 case MotionEvent.ACTION_MOVE: if (flag == false) { //僅有一個手指下不做反映 break; } newDis = spacing(event); //微小變化不作處理 if (newDis > (oldDis - 10.0f) && newDis < (oldDis + 10.0f)) { break; } float scale = newDis / oldDis; if (scale > 1) { float t = scale - 1.0f; t = t/2.0f; scale = scale - t; } if (scale < 1) { float t = 1.0f - scale; t = t/2.0f; scale = scale + t; } matrix.setScale(scale, scale); int newHeight = alterBm.getHeight(); int newWidth = alterBm.getWidth(); temp.recycle(); temp = Bitmap.createBitmap(alterBm, 0, 0, newWidth, newHeight, matrix ,true); iv.setImageBitmap(temp); alterBm.recycle(); alterBm = temp.copy(temp.getConfig(), true); newDis = oldDis; break; case MotionEvent.ACTION_POINTER_UP: flag = false; break; default: break; } return true; } }); } private float spacing(MotionEvent event) { float x = event.getX(0) - event.getX(1); float y = event.getY(0) - event.getY(1); return FloatMath.sqrt(x * x + y * y); } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看