请教:Matrix 的缩放(Bitmap)
Android Bitmap图片缩放优化,用canvas替代Matrix进行缩放,解决一些错我 Android Bitmap图片缩放优化,用cavans替代Matrix进行缩放,解决一些错我 阅读详情
package com.Feier.android.Matrix;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.view.KeyEvent;
import android.view.View;
public class GameView extends View implements Runnable{
private Bitmap mBitmapQQ=null;
int mBitmapQQ_Width=0;
int mBitmapQQ_Height=0;
float Angle=0.0f;
Matrix mMatrix=new Matrix();
public GameView(Context context){
super(context);
//装载资源
mBitmapQQ=((BitmapDrawable)getResources().getDrawable(R.drawable.button1)).getBitmap();
mBitmapQQ_Width=mBitmapQQ.getWidth();
mBitmapQQ_Height=mBitmapQQ.getHeight();
new Thread(this).start();
}
public void onDraw(Canvas canvas){
super.onDraw(canvas);
//重置mMatrix
mMatrix.reset();
//设置旋转
mMatrix.setRotate(Angle);
//按mMatrix的旋转构建新的Bitmap
Bitmap mBitmapQQ2=Bitmap.createBitmap(mBitmapQQ,0,0,mBitmapQQ_Width,mBitmapQQ_Height,mMatrix,true);
//绘制旋转之后的图像
GameView.drawImage(canvas,mBitmapQQ2,(320-mBitmapQQ_Width)/2,10);
mBitmapQQ2=null;
}
public boolean onKeyDown(int keyCode,KeyEvent event){
if (keyCode==KeyEvent.KEYCODE_DPAD_LEFT){
Angle--;
}
else if(keyCode==KeyEvent.KEYCODE_DPAD_RIGHT){
Angle++;
}
return true;
}
public void run(){
while(!Thread.currentThread().isInterrupted()){
try{
Thread.sleep(100);
}
catch(Exception e){
Thread.currentThread().interrupt();
}
postInvalidate();
}
}
/**
* 绘制一个Bitmap
* @param canvas画布
* @param btimap画布
* @param x 屏幕上的x坐标
* @param y 屏幕上的y坐标
*/
public static void drawImage(Canvas canvas, Bitmap bitmap,int x,int y){
canvas.drawBitmap(bitmap, x,y,null);
}
}package com.Feier.android.Matrix;
import android.app.Activity;
import android.os.Bundle;
public class Activity01 extends Activity {
private GameView mGameView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGameView=new GameView(this);
setContentView(mGameView);
//setContentView(R.layout.main);
}
}请问,代码附上,麻烦大虾看下。
显示是肯定不会出问题。但是,在GameView中设置好的界面,按键按下事件,在主活动中,没有显示。求解。
...全文
相关推荐
Bitmap位图缩放范例
**使用Matrix进行缩放**:通过创建一个Matrix对象并设置其ScaleToFill或ScaleToFit属性,然后应用到Bitmap上进行缩放。
Android-使用Matrix对Bitmap进行处理
例如,将Bitmap按比例放大或缩小:```javamatrix.setScale(2f, 2f); // 缩放2倍Bitmap scaledBitmap = Bitmap.createBitmap(originalBitmap
Android Matrix处理ImageView中图片缩放,平移
总的来说,Android中的Matrix类提供了丰富的图像变换功能,结合ImageView和Bitmap,我们可以实现各种复杂的图像操作,如缩放和平移。
Android中Bitmap常见的一些操作:缩放、裁剪、旋转和偏移
在Android开发中,Bitmap是一个重要的数据结构,常用于处理图像相关操作。本文将深入探讨Bitmap在Android中进行的四个常见操作:缩放、裁剪、旋转和偏移。这些操作通常依赖于Matrix
android缩放/旋转图片Matrix代码
- `preScale(float sx, float sy)`:该方法会将之前所有的缩放操作都乘以前一个缩放因子,即新的缩放操作会叠加在原有的基础上。


