import java.io.File;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class A10Activity extends Activity {
private Button b;
private ImageView iv;
private TextView tv;
private String fileName="sdcard/picture/红叶.jpg";
//private String fileName="sdcard/picture/红叶.jpg";这种写法是错误的,路径不是以
//设备开头
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
b=(Button)findViewById(R.id.button);
b.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
iv=(ImageView)findViewById(R.id.imageview);
tv=(TextView)findViewById(R.id.textview);
File f=new File(fileName);
//先判断图片文件是否存在
if(f.exists()){
//如果存在,通过Bitmap将图片放入ImageView中显示出来
/*BitmapFactory(Android.graphics.BitmapFactory)是Android API提供的对象,该对象
*的decodeFile()方法将手机中的图片文件转换成Bitmap对象。*/
Bitmap bm=BitmapFactory.decodeFile(fileName);
iv.setImageBitmap(bm);
tv.setText(fileName);
}
else{
tv.setText("文件不存在");
}
}
});
}
}
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class A11Activity extends Activity {
private ImageView iv;
private TextView tv;
private Button left,right;
private int times;
private int angle;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
times=1;
angle=1;
iv=(ImageView)findViewById(R.id.iv);
tv=(TextView)findViewById(R.id.tv);
left=(Button)findViewById(R.id.left);
left.setText("向左转");
right=(Button)findViewById(R.id.right);
right.setText("向右转");
final Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.a); //自己引入一张图片a.png
final int width=bmp.getWidth();
final int height=bmp.getHeight();
iv.setImageBitmap(bmp);
left.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
angle--;
if(angle<-20){ //设置最多旋转20度
angle=-20;
}
int width01=width*times;
int height01=height*times;
float width02=(float)(width01/width);
float height02=(float)(width02/height);
Matrix m=new Matrix();
m.postScale(width02, height02);
m.setRotate(5*angle);
Bitmap bmp01=Bitmap.createBitmap(bmp, 0, 0, width, height, m, true);
BitmapDrawable bd=new BitmapDrawable(bmp01);
iv.setImageDrawable(bd);
tv.setText(Integer.toString(5*angle));
}
});
right.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
angle++;
if(angle>20){
angle=20;
}
int width01=width*times;
int height01=height*times;
float width02=(float)(width01/width);
float height02=(float)(width02/height);
Matrix m=new Matrix();
m.postScale(width02, height02);
m.setRotate(5*angle);
Bitmap bmp01=Bitmap.createBitmap(bmp, 0, 0, width, height, m, true);
BitmapDrawable bd=new BitmapDrawable(bmp01);
iv.setImageDrawable(bd);
tv.setText(Integer.toString(5*angle));
}
});
}
}
<?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" >
<TextView
android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/left"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/right"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="@+id/iv"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有