처음에 안 드 로 이 드 는 방금 만 든 그림 크기 조정 프로그램 을 기록 했다.
8587 단어 그림 크기 조정
레이아웃 코드:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="clip_vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom|center_horizontal"
android:orientation="horizontal" >
<Button
android:id="@+id/bsx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
<Button
android:id="@+id/bfd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" " />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ImageView>
</LinearLayout>
</FrameLayout>
자바 코드:
package com.example.myscalepic;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener {
ImageView imgView;
Bitmap bmp;
int screenWidth; //
int screenHeight;//
float scaleWidth = 1f; //
float scaleHeight = 1f;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.feng);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
screenWidth = dm.widthPixels;
screenHeight = dm.heightPixels - 80;
imgView = (ImageView) this.findViewById(R.id.img);
Button b1 = (Button) this.findViewById(R.id.bsx);
Button b2 = (Button) this.findViewById(R.id.bfd);
//
imgView.setImageBitmap(bmp);
b1.setOnClickListener(this);
b2.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.bfd) {//
scaleWidth *= 1.2;
scaleHeight *= 1.2;
} else { //
scaleWidth *= 0.8;
scaleHeight *= 0.8;
}
//
imgView.setImageBitmap(scaleToFit());
}
/**
*
* @return
*/
private Bitmap scaleToFit() {
int width = bmp.getWidth();
int height = bmp.getHeight();
Matrix ma = new Matrix();
ma.postScale(scaleWidth, scaleHeight);
Bitmap tewmpmap;
if (width * scaleWidth > screenWidth|| height * scaleHeight > screenHeight) {
scaleWidth=1f;
scaleHeight=1f;
return bmp;
} else {
//
tewmpmap = Bitmap.createBitmap(bmp, 0, 0, width, height, ma, true);
return tewmpmap;
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JS 이미지 크기 조정 처리페이지 내 호출: 이 방법은 인터넷에서 찾아서 실천할 수 있고 이미 프로젝트에 사용되어 간단하고 편리하다.가독성이 강하다...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.