| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
10年前发布

Andriod SeekBar以及实现图片旋转平移放大缩小

首先通过ddms把图片导入模拟器    package com.example.testimageview;    import java.io.FileNotFoundException;  import java.io.IOException;    import android.net.Uri;  import android.os.Bundle;  import android.provider.MediaStore;  import android.app.Activity;  import android.content.Intent;  import android.graphics.Bitmap;  import android.graphics.Canvas;  import android.graphics.Matrix;  import android.graphics.Paint;  import android.support.v4.widget.SimpleCursorAdapter.ViewBinder;  import android.view.Menu;  import android.view.View;  import android.view.View.OnClickListener;  import android.widget.Button;  import android.widget.ImageView;  import android.widget.SeekBar;  import android.widget.SeekBar.OnSeekBarChangeListener;    public class MainActivity extends Activity implements OnClickListener  {     private Button bclick;   private ImageView imageView;   private SeekBar sBar;   private Bitmap bmp;      protected void onCreate(Bundle savedInstanceState)   {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);        bclick = (Button) findViewById(R.id.bclick);    bclick.setOnClickListener(this);    imageView = (ImageView) findViewById(R.id.image_view);    sBar = (SeekBar) findViewById(R.id.sb);    sBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()    {          @Override     public void onStopTrackingTouch(SeekBar seekBar)     {      // TODO Auto-generated method stub           }          @Override     public void onStartTrackingTouch(SeekBar seekBar)     {      // TODO Auto-generated method stub           }          @Override     public void onProgressChanged(SeekBar seekBar, int progress,       boolean fromUser)     {      // TODO Auto-generated method stub      //创建一个与取出来的图片大小一致的位图文件      Bitmap alterBmp = bmp.createBitmap(bmp.getWidth(), bmp.getHeight(), bmp.getConfig());            //画布      Canvas  canvas = new Canvas(alterBmp);      //画笔      Paint paint = new Paint();      paint.setStrokeWidth(5f);      //矩阵....      Matrix matrix = new Matrix();       // scale 缩放    rotate  旋转translate 平移      //matrix.setRotate((float) 0.9*progress);      //matrix.setScale(0.1f*progress,0.1f*progress);      matrix.setTranslate(-0.1f*progress,-0.1f*progress);      canvas.drawBitmap(bmp, matrix, paint);      imageView.setImageBitmap(alterBmp);           }    });       }     @Override   public void onClick(View v)   {    // TODO Auto-generated method stub    Intent intent = new Intent();    intent.setAction(Intent.ACTION_PICK);    intent.setType("image/*");    //startActivity(intent);       startActivityForResult(intent, 1);       }      @Override   protected void onActivityResult(int requestCode, int resultCode, Intent data)   {    // TODO Auto-generated method stub    if(requestCode==1)    {     if(resultCode == RESULT_OK)     {      try      {       Uri uri = data.getData();       bmp =MediaStore.Images.Media.getBitmap(getContentResolver(), uri);       imageView.setImageURI(uri);      } catch (FileNotFoundException e)      {       // TODO Auto-generated catch block       e.printStackTrace();      } catch (IOException e)      {       // TODO Auto-generated catch block       e.printStackTrace();      }     }    }   }    }
 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1418476183698.html
Andriod Android开发 移动开发