package qas_tool;
import android.graphics.Bitmap;
public class Resize_buffer {
private int []resize_buffer;
private int origin_w;
private int origin_h;
private int resize_w;
private int resize_h;
private int div_h;
private float scale_x;
private float scale_y;
private int neast_x;
private int neast_y;
public Resize_buffer(int orgin_w,int origin_h,int new_w,int new_h){
resize_buffer=new int[new_w*new_h];
this.origin_w=orgin_w;
this.origin_h=origin_h;
this.resize_w=new_w;
this.resize_h=new_h;
resize_buffer=new int[new_w*new_h];
scale_x=new_w/(float)orgin_w;
scale_y=new_h/(float)origin_h;
div_h=resize_h/4;
}
public int[]buffer; //point buffer
private Thread thread1,thread2,thread3;
public Bitmap resize_Bitmap(){
thread1=new Thread(new Runnable() {
@Override
public void run() {
process_resize(0,0,resize_w,div_h);
}
});
thread2=new Thread(new Runnable() {
@Override
public void run() {
process_resize(0,div_h,resize_w,2*div_h);
}
});
thread3=new Thread(new Runnable() {
@Override
public void run() {
process_resize(0,2*div_h,resize_w,3*div_h);
}
});
thread1.start();
thread2.start();
thread3.start();
process_resize(0,3*div_h,resize_w,resize_h);
while (thread1.isAlive() || thread2.isAlive() || thread3.isAlive());
return Bitmap.createBitmap(resize_buffer,resize_w,resize_h, Bitmap.Config.ARGB_8888);
}
private void process_resize(int left,int top,int right,int bottom){
for(int j=top;j<bottom;j++) {
for (int i = left; i < right; i++) {
neast_x=Math.round(i/scale_x);
neast_y=Math.round(j/scale_y);
resize_buffer[i+j*resize_w]=buffer[neast_x+neast_y*origin_w];
}
}
}
}
沒有留言:
張貼留言