import android.support.v7.app.ActionBarActivity; import android.util.DisplayMetrics; import android.annotation.SuppressLint; import android.graphics.Bitmap; import android.graphics.Matrix; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.SeekBar; import android.widget.TextView; import android.widget.SeekBar.OnSeekBarChangeListener;   @SuppressLint ( "NewApi" ) public class MainActivity extends ActionBarActivity implements OnSeekBarChangeListener{      //最小的缩放宽度      private int minWidth = 80 ;      private ImageView imageView;      private SeekBar seekBar1;      private SeekBar seekBar2;      private TextView textView1;      private TextView textView2;      //矩阵类,用于对图像进行旋转      private Matrix matrix = new Matrix();      @Override      protected void onCreate(Bundle savedInstanceState) {          super .onCreate(savedInstanceState);          setContentView(R.layout.activity_main);          imageView = (ImageView)findViewById(R.id.imageView);          seekBar1 = (SeekBar)findViewById(R.id.seekBar1);          seekBar2 = (SeekBar)findViewById(R.id.seekBar2);          seekBar1.setOnSeekBarChangeListener( this );          seekBar2.setOnSeekBarChangeListener( this );          textView1 = (TextView)findViewById(R.id.textview1);          textView2 = (TextView)findViewById(R.id.textview2);          //创建一个空的展示矩阵,用于存储当前屏幕信息,如大小。          DisplayMetrics displayMetrics = new DisplayMetrics();          //把当前管理的屏幕尺寸传递给displayMetrics          getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);          //设置放大的最大值不超过屏幕大小          seekBar1.setMax(displayMetrics.widthPixels-minWidth);      }        @Override      public void onProgressChanged(SeekBar seekBar, int progress,              boolean fromUser) {          if (seekBar.getId()==R.id.seekBar1) {              //设置宽度为80到最大              int mwidth = progress+minWidth;              int mheight = ( int )( 2 *mwidth/ 3 );              //设置imageView的输出大小参数              //因为图片是fitcenter参数,所以图片会随着image框架的大小变化而变化              //从而改变image框架的大小会引起图片大小的变化,实现图片的放大缩小功能              imageView.setLayoutParams( new LinearLayout.LayoutParams(mwidth, mheight));              textView1.setText( "图片宽度:" +mwidth+ "\t图片高度:" +mheight);          } else if (seekBar.getId()==R.id.seekBar2) {             //imageView自身的setRotation方法是绕图的中心顺时针防线旋转             //同时该旋转不会改变imageView的输出大小,所超出imageView的部分会照常显示在所跨越视图的下方             //imageView.setRotation(progress);                           //如果想创建一个不超出imageView输出框架的旋转图像,那么需要把原图像取出,把原图像进行旋转,重新放入到imageView             //缺陷:占用系统较多的内存,会比较卡             Bitmap bitmap = ((BitmapDrawable)(getResources().getDrawable(R.drawable.photo))).getBitmap();             matrix.setRotate(progress);             bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);             imageView.setImageBitmap(bitmap);             textView2.setText("图片旋转"+progress+"度");          }                }        @Override      public void onStartTrackingTouch(SeekBar seekBar) {          // TODO Auto-generated method stub                }        @Override      public void onStopTrackingTouch(SeekBar seekBar) {          // TODO Auto-generated method stub                } }
"http://schemas.android.com/apk/res/android"  android:layout_width= "fill_parent"  android:layout_height= "fill_parent"  android:orientation= "vertical" >        android:id= "@+id/imageView"  android:layout_width= "300dp"  android:layout_height= "200dp"  android:scaletype= "fitCenter"  android:src= "@drawable/photo"/ >        android:id= "@+id/textview1"  android:layout_width= "wrap_content"  android:layout_height= "wrap_content"  android:text= "图片缩放"/ >        android:id= "@+id/seekBar1"  android:layout_width= "match_parent"  android:layout_height= "wrap_content"  android:max= "480"  android:progress= "300"/ >        android:id= "@+id/textview2"  android:layout_width= "wrap_content"  android:layout_height= "wrap_content"  android:text= "图片旋转"/ >

       android:id= "@+id/seekBar2"  android:layout_width= "match_parent"  android:layout_height= "wrap_content"  android:max= "360"  android:progress= "0"/ >  



更多相关文章

  1. Android(安卓)TextView 丰富多彩的字体样式代码
  2. Android获取SD卡大小
  3. Android(安卓)项目中常用到的第三方组件
  4. 使用HttpURLConnection请求数据、上传文件、图片等
  5. 自定义对话框 位置 大小等
  6. android 断点下载---XUtils
  7. android手势缩放
  8. android后台打水印,并进行压缩
  9. Android之handle异步加载图片

随机推荐

  1. 面试阿里Android研发岗,已拿到offer,这些知
  2. android中ADB server didn't ACK * faile
  3. Android内嵌unity
  4. Android(安卓)反编译(使用Android(安卓)s
  5. Android(安卓)多渠道打包之混淆文件ProGu
  6. 深入理解Android消息处理系统——Looper
  7. 利用Android回调机制打造简单的Dialog调
  8. Android中的矩阵(Matrix)变换
  9. Android自定义动画三-SVG动画
  10. AndroidManifest.xml 详解 (四) 之uses-p