91在线视频播放|成人黄视频在线观看|在线视频福利|天天欲色成人综合网站|国产国语videosex护士

機構檔案
  • 機構級別:普通會員
  • 信用等級:

在線交談:點擊這里給我發消息

咨詢熱線:029-62258374

學校評價(我要提問/點評)

  • 學校被點評:0
  • 好評(0%)
  • 中評(0%)
  • 差評(0%)

資料認證

    未通過身份證認證 未通過身份證認證

    未通過辦學許可認證 未通過辦學許可認證

  • 學校瀏覽人次:
  • 加盟時間:2017年03月10日
新聞動態

西安尚學堂:android圖片處理代碼

發布者:西安尚學堂 發布時間:2017-03-18 來源:西安尚學堂

深圳尚學堂

/** 放大縮小

* @param bgimage

* @param newWidth

* @param newHeight

* @return

*/

public Bitmap ZoomImage(Bitmap src, Float newWidth, Float newHeight) {

int width = src.getWidth();

int height = src.getHeight();

Matrix matrix = new Matrix();

float scaleWidth = newWidth / width;

float scaleHeight = newHeight / height;

matrix.postScale(scaleWidth, scaleHeight);

Bitmap bitmap = Bitmap.createBitmap(src, 0, 0, width, height, matrix, true);

return bitmap;

}

/** 旋轉圖片返回傳入點旋轉后的位置

* @param 圖片大小/中點/旋轉角度

* @return 旋轉后中點位置

*/

public Vector2D rota(Vector2D bitmapSize, Vector2D midPoint, float angle){

float w = bitmapSize.x;

float h = bitmapSize.y;

angle = (float)Math.toRadians(angle);

Vector vec = new Vector();

//創建矩形的四個頂點

Vector2D point1 = new Vector2D(-midPoint.x,-midPoint.y);

Vector2D point2 = new Vector2D(-midPoint.x + w,-midPoint.y);

Vector2D point3 = new Vector2D(-midPoint.x + w,-midPoint.y + h);

Vector2D point4 = new Vector2D(-midPoint.x,-midPoint.y + h);

//旋轉后頂點位置

point1.setAngle(point1.getAngle()+angle);

point2.setAngle(point2.getAngle()+angle);

point3.setAngle(point3.getAngle()+angle);

point4.setAngle(point4.getAngle()+angle);

//取出左上頂點

vec.addElement(point1);

vec.addElement(point2);

vec.addElement(point3);

vec.addElement(point4);

Vector2D newOrigin = new Vector2D(0,0);

for (int i = 0; i < vec.size(); i++) {

Vector2D tmp = vec.elementAt(i);

if(newOrigin.getX()>tmp.getX()){

newOrigin.setX(tmp.getX());

}

if(newOrigin.getY()>tmp.getY()){

newOrigin.setY(tmp.getY());

}

return newOrigin;

}

//單張圖片旋轉

public Bitmap draw(){

float angle = (float)Math.toDegrees(velocity.getAngle())+90;

Matrix ma = new Matrix();

ma.setRotate(angle);

mid = GameView.img.rota(new Vector2D(imgSrc.getWidth(),imgSrc.getHeight()), new Vector2D(imgSrc.getWidth()/2,imgSrc.getHeight()/2), angle);

return Bitmap.createBitmap(imgSrc,0,0,imgSrc.getWidth(),imgSrc.getHeight(),ma,true);

}

Vector2D 向量類

public class Vector2D {

public float x;

public float y;

//-------------------------------------------------

public Vector2D() {

super();

}

public Vector2D(float x, float y) {

this.x = x;

this.y = y;

}

//-------------------------------------------------

public Vector2D clone() {

return new Vector2D(x, y);

}

//歸零

public Vector2D zero(){

x = 0;

y = 0;

return this;

}

//是否為0

public boolean isZero(){

return x == 0 && y == 0;

}

/** 取出兩點間距離*/

public float getLength(){

return (float)Math.sqrt(getLengthSQ());

}

/** 取出X Y的平方和*/

public float getLengthSQ(){

return x * x + y * y;

}

/** 設置長度*/

public void setLength(float value){

float a = getAngle();

x = (float)Math.cos(a) * value;

y = (float)Math.sin(a) * value;

}

/** 設置角度*/

public void setAngle(float value){

float len = getLength();

x = (float)Math.cos(value) * len;

y = (float)Math.sin(value) * len;

}

public float getAngle(){

return (float)Math.atan2(y, x);

}

/** 規范化*/

public Vector2D normalize(){

if (getLength() == 0) {

x = 1;

return this;

}

float len = getLength();

x /= len;

y /= len;

return this;

}

/** 取最小值*/

public Vector2D truncate(float max){

setLength(Math.min(max,getLength()));

return this;

}

/** 取負值*/

public Vector2D reverse(){

x = - x;

y = - y;

return this;

}

public boolean isNormalized(){

return getLength()==1.0;

}

public float dotProd(Vector2D v2){

return x * v2.getX() + y * v2.getY();

}

public float crossProd(Vector2D v2) {

return x * v2.getY() - y * v2.getX();

}

public static float angleBetween(Vector2D v1, Vector2D v2) {

if (! v1.isNormalized()) {

v1 = v1.clone().normalize();

}

if (! v2.isNormalized()) {

v2 = v2.clone().normalize();

}

return (float)Math.acos(v1.dotProd(v2));

}

public int sign(Vector2D v2) {

return getPerp().dotProd(v2) < 0 ? -1 : 1;

}

public Vector2D getPerp() {

return new Vector2D(-y, x);

}

public float dist(Vector2D v2) {

return (float)Math.sqrt(distSQ(v2));

}

public float distSQ(Vector2D v2) {

float dx = v2.getX() - x;

float dy = v2.getY() - y;

return dx * dx + dy * dy;

}

public Vector2D add(Vector2D v2) {

return new Vector2D(x + v2.getX(), y + v2.getY());

}

public Vector2D subtract(Vector2D v2){

return new Vector2D(x - v2.getX(), y - v2.getY());

}

public Vector2D multiply(float value) {

return new Vector2D(x * value, y * value);

}

/** 分份*/

public Vector2D divide(float value) {

return new Vector2D(x / value, y / value);

}

/** 查看兩點坐標是否相同*/

public boolean equals(Vector2D v2) {

return x == v2.getX() && y == v2.getY();

}

public String toString() {

return "[Vector2D (x:" + x + ", y:" + y + ")]";

}

//-------------------------------------------------

public float getX() {

return x;

}

public void setX(float x) {

this.x = x;

}

public float getY() {

return y;

}

public void setY(float y) {

this.y = y;

}

}