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();
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) {
int
mwidth = progress+minWidth;
int
mheight = (
int
)(
2
*mwidth/
3
);
imageView.setLayoutParams(
new
LinearLayout.LayoutParams(mwidth, mheight));
textView1.setText(
"图片宽度:"
+mwidth+
"\t图片高度:"
+mheight);
}
else
if
(seekBar.getId()==R.id.seekBar2) {
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) {
}
@Override
public
void
onStopTrackingTouch(SeekBar seekBar) {
}
}
"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"/
>