android 图片的自由缩放和旋转android 图片的自由缩放和旋转android 图片的自由缩放和旋转

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <ImageView android:id="@+id/imageview"        android:layout_width="200dp"        android:layout_height="150dp"        android:src="@drawable/android1"        android:scaleType="fitCenter" />    <TextView android:id="@+id/textview1"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_margin="10dp"        android:text="图像宽度:240 图像高度:160"/><SeekBar android:id="@+id/seekbar1"    android:layout_width="200dp"    android:layout_height="20dp"    android:layout_margin="10dp"    android:max="240"    android:progress="120"/><TextView android:id="@+id/textview2"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_margin="10dp"        android:text="0度"/><SeekBar android:id="@+id/seekbar2"    android:layout_width="200dp"    android:layout_height="20dp"    android:layout_margin="10dp"    android:max="360"/></LinearLayout>

package com.android.imageview;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.Matrix;import android.graphics.drawable.BitmapDrawable;import android.os.Bundle;import android.util.DisplayMetrics;import android.view.View.OnClickListener;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.SeekBar;import android.widget.SeekBar.OnSeekBarChangeListener;import android.widget.TextView;public class Main extends Activity implements OnSeekBarChangeListener{    private int minWidth = 80;    private ImageView imageview;    private TextView textView1,textView2;    private Matrix matrix = new Matrix();//构建一个3*3的矩阵    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        imageview = (ImageView)this.findViewById(R.id.imageview);        SeekBar seekBar1 = (SeekBar)this.findViewById(R.id.seekbar1);        SeekBar seekBar2 = (SeekBar)this.findViewById(R.id.seekbar2);        textView1=(TextView)this.findViewById(R.id.textview1);        textView2=(TextView)this.findViewById(R.id.textview2);        seekBar1.setOnSeekBarChangeListener(this);        seekBar2.setOnSeekBarChangeListener(this);                DisplayMetrics dm = new DisplayMetrics();        getWindowManager().getDefaultDisplay().getMetrics(dm);        seekBar1.setMax(dm.widthPixels-minWidth);    }public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {// TODO Auto-generated method stubif(seekBar.getId()==R.id.seekbar1){//progress是seekBar的进度,拉伸进度,加minWidth是宽度,为了按比例缩放,所以高度是宽度的四分之三int newWidth = progress+minWidth;int newHight = (int)(newWidth*3/4);imageview.setLayoutParams(new LinearLayout.LayoutParams(newWidth, newHight));textView1.setText("图像的宽度:"+newWidth+" 图像的高度"+newHight);}else if(seekBar.getId()==R.id.seekbar2){Bitmap bitmap = ((BitmapDrawable)getResources().getDrawable(R.drawable.android1)).getBitmap();matrix.setRotate(progress);//设置翻转的角度bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(),matrix , true);//重做位图imageview.setImageBitmap(bitmap);//将位图添加到imageview里面textView2.setText(progress+"度");}}public void onStartTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}public void onStopTrackingTouch(SeekBar seekBar) {// TODO Auto-generated method stub}}

更多相关文章

  1. android Drawable 缩放
  2. android 自由缩放图片
  3. Android 设置百度地图最大最小缩放级别
  4. Android P系统输出图像镜像翻转实现
  5. android 调用相机拍照 并缩放切割图片
  6. 图片缩放设置
  7. Android 使用Matrix进行图像变换
  8. Android中图像和图像处理
  9. Android中图像变换Matrix的原理、代码验证和应用

随机推荐

  1. 超强汇总:学习Python列表,只需这篇文章就够
  2. 每日前端夜话(0x05):2018年JavaScript状态
  3. 排序算法 #4 再讲插入排序
  4. 数据结构 #1 浅谈数组
  5. 再谈文件读写:判断文件的几种方法及其优劣
  6. 从一篇Blog看两个并发编程错误
  7. 每日前端夜话(0x04):2018年JavaScript状态
  8. LeetCode #27 移除元素
  9. 以B站C语言视频为基础的课后总结(一)
  10. LeetCode #26 删除排序数组中的重复项