比好还早啊 大兄弟
package com.easyway.andorid.hello;
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.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout.LayoutParams;
/**
* Android实现图片的缩放功能
* @author longgangbai
* @date 2010-5-24
* @version 1.0
* @since JDK6.0
*/
public class ImageViewAndorid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置程序的标题
setTitle("缩放和旋转图片");
//实例化LinearLayout类的对象lly
LinearLayout lly=new LinearLayout(this);
//获取图片的信息 这里用的是icon.png ,图片存放的位置在res/drawable下,
//同时这里还方有itfunz.bmp,这就是应用程序的图标
Bitmap bmpOrg=BitmapFactory.decodeResource(getResources(), R.drawable.icon);
//获取图片的原始的大小
int width=bmpOrg.getWidth();
int height=bmpOrg.getHeight();
int newWidth=400;
int newheight=400;
//定义缩放的高和宽的尺寸
float sw=((float)newWidth)/width;
float sh=((float)newheight)/height;
//创建操作图片的用的Matrix对象
Matrix matrix=new Matrix();
matrix.postScale(sw,sh);
//缩放图片的动作
matrix.postRotate(30);
//旋转30*
Bitmap resizeBitmap=Bitmap.createBitmap(bmpOrg,0,0,width,height,matrix,true);
//创建一个新的图片
BitmapDrawable bmp=new BitmapDrawable(resizeBitmap);
//创建Bitmap转换为Drawable对象,使其可以使用在ImageView和ImageButton中
ImageView imageView=new ImageView(this);
//创建ImageView的对象
imageView.setImageDrawable(bmp);
//将图片设置到中间
imageView.setScaleType(ScaleType.CENTER);
//将图片填充之整个视图
lly.addView(imageView, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//添加ImageView到布局模板中
setContentView(lly);
}
} 网上随便找的 不知道对你有没有帮助
package com.easyway.andorid.hello;
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.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout.LayoutParams;
/**
* Android实现图片的缩放功能
* @author longgangbai
* @date 2010-5-24
* @version 1.0
* @since JDK6.0
*/
public class ImageViewAndorid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//设置程序的标题
setTitle("缩放和旋转图片");
//实例化LinearLayout类的对象lly
LinearLayout lly=new LinearLayout(this);
//获取图片的信息 这里用的是icon.png ,图片存放的位置在res/drawable下,
//同时这里还方有itfunz.bmp,这就是应用程序的图标
Bitmap bmpOrg=BitmapFactory.decodeResource(getResources(), R.drawable.icon);
//获取图片的原始的大小
int width=bmpOrg.getWidth();
int height=bmpOrg.getHeight();
int newWidth=400;
int newheight=400;
//定义缩放的高和宽的尺寸
float sw=((float)newWidth)/width;
float sh=((float)newheight)/height;
//创建操作图片的用的Matrix对象
Matrix matrix=new Matrix();
matrix.postScale(sw,sh);
//缩放图片的动作
matrix.postRotate(30);
//旋转30*
Bitmap resizeBitmap=Bitmap.createBitmap(bmpOrg,0,0,width,height,matrix,true);
//创建一个新的图片
BitmapDrawable bmp=new BitmapDrawable(resizeBitmap);
//创建Bitmap转换为Drawable对象,使其可以使用在ImageView和ImageButton中
ImageView imageView=new ImageView(this);
//创建ImageView的对象
imageView.setImageDrawable(bmp);
//将图片设置到中间
imageView.setScaleType(ScaleType.CENTER);
//将图片填充之整个视图
lly.addView(imageView, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
//添加ImageView到布局模板中
setContentView(lly);
}
} 网上随便找的 不知道对你有没有帮助
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.example.android.apis.graphics;import com.example.android.apis.R;import android.app.Activity;
import android.content.Context;
import android.graphics.*;
import android.graphics.drawable.*;
import android.util.Log;
import android.view.animation.*;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;public class AnimateDrawables extends GraphicsActivity {
public static final String TAG = "AnimateDrawables" ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View implements Runnable{
private AnimateDrawable mDrawable;
private AnimateDrawable mDrawable0;
public SampleView(final Context context) {
super(context);
setFocusable(true);
setFocusableInTouchMode(true);
Drawable dr = context.getResources().getDrawable(R.drawable.beach);
Thread mThread = new Thread(){
public void run(){
Drawable dr1 = context.getResources().getDrawable(R.drawable.animated_gif) ;
dr1.setBounds(0, 0, 100, 100);
int x =200 ;
int y =200 ;
Animation an0 = new TranslateAnimation(200, 0, 200, 0);
an0.setDuration(5000);
an0.setRepeatCount(-1);
mDrawable0 = new AnimateDrawable(dr1, an0);
an0.initialize(10, 10, 10, 10);
an0.startNow();
}
};
mThread.start();
for(int i=0;i<100;i++){
Log.d(TAG, "MAINthread:"+i);
}
dr.setBounds(0, 0, 200, 200);
Animation an = new TranslateAnimation(0, 200, 0, 200);
an.setDuration(5000);
an.setRepeatCount(-1);
an.initialize(10, 10, 10, 10);
mDrawable = new AnimateDrawable(dr, an);
an.startNow();
// Animation an1 = new TranslateAnimation(200, 0, 200, 0);
// an1.setDuration(5000);
// an1.setRepeatCount(-1);
// an1.initialize(10, 10, 10, 10);
// mDrawable = new AnimateDrawable(dr, an1);
// an1.startNow();
}
@Override protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.WHITE);
mDrawable.draw(canvas);
mDrawable0.draw(canvas);
invalidate();
} public void run() {
for(int i=0 ;i<100;i++){
Log.d(TAG, "0MyThread:"+i);
}
} }}