利用Android實(shí)現(xiàn)一個(gè)放大鏡功能-創(chuàng)新互聯(lián)

今天就跟大家聊聊有關(guān)利用Android實(shí)現(xiàn)一個(gè)放大鏡功能,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

成都創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站制作、網(wǎng)站建設(shè)、朝陽網(wǎng)絡(luò)推廣、小程序制作、朝陽網(wǎng)絡(luò)營銷、朝陽企業(yè)策劃、朝陽品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們大的嘉獎(jiǎng);成都創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供朝陽建站搭建服務(wù),24小時(shí)服務(wù)熱線:18980820575,官方網(wǎng)址:muchs.cn

源碼分析

public class ShaderView extends View {
  private final Bitmap bitmap;
  private final ShapeDrawable drawable;
  // 放大鏡的半徑
  private static final int RADIUS = 80;
  // 放大倍數(shù)
  private static final int FACTOR = 3;
  private final Matrix matrix = new Matrix();
 
  public ShaderView(Context context) {
   super(context);
   Bitmap bmp = BitmapFactory.decodeResource(getResources(),R.drawable.demo);
   bitmap = bmp;
   BitmapShader shader = new BitmapShader(Bitmap.createScaledBitmap(bmp,
   bmp.getWidth() * FACTOR, bmp.getHeight() * FACTOR, true), TileMode.CLAMP, TileMode.CLAMP);
 
   // 圓形的drawable
   drawable = new ShapeDrawable(new OvalShape());
   drawable.getPaint().setShader(shader);
   drawable.setBounds(0, 0, RADIUS * 2, RADIUS * 2);
 }
 
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   final int x = (int) event.getX();
   final int y = (int) event.getY();
 
   // 這個(gè)位置表示的是,畫shader的起始位置
   matrix.setTranslate(RADIUS - x * FACTOR, RADIUS - y * FACTOR);
   drawable.getPaint().getShader().setLocalMatrix(matrix);
 
   // bounds,就是那個(gè)圓的外切矩形
   drawable.setBounds(x - RADIUS, y - RADIUS, x + RADIUS, y + RADIUS);
   invalidate();
   return true;
 }
 
 @Override
 public void onDraw(Canvas canvas) {
   super.onDraw(canvas);
   canvas.drawBitmap(bitmap, 0, 0, null);
   drawable.draw(canvas);
 }
}

分享文章:利用Android實(shí)現(xiàn)一個(gè)放大鏡功能-創(chuàng)新互聯(lián)
瀏覽地址:http://muchs.cn/article8/dejdip.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、定制網(wǎng)站、用戶體驗(yàn)、網(wǎng)站制作、外貿(mào)建站、手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)