Android2.3使用BitmapRegionDecoder获取指定区域的图片
来源:互联网 发布:网络无武侠小说 编辑:程序博客网 时间:2024/06/05 15:33
public class DisplayImageRegionActivity extends Activity implements OnTouchListener {
private final Rect mRect = new Rect();
private BitmapRegionDecoder mDecoder;
private ImageView mView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mView = new ImageView(this);
mView.setAdjustViewBounds(true);
mView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
mView.setScaleType(ScaleType.CENTER);
mView.setOnTouchListener(this);
setContentView(mView);
try {
InputStream is = getResources().openRawResource(R.drawable.a);
mDecoder = BitmapRegionDecoder.newInstance(is, true);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
final int action = event.getAction() & MotionEvent.ACTION_MASK;
final int x = (int) event.getX();
final int y = (int) event.getY();
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
setImageRegion(x, y);
break;
}
return true;
}
private void setImageRegion(int left, int top) {
// BitmapFactory.Options opts = new BitmapFactory.Options();
final int width = mView.getWidth();
final int height = mView.getHeight();
final int imgWidth = mDecoder.getWidth();
final int imgHeight = mDecoder.getHeight();
int right = left + width;
int bottom = top + height;
if(right > imgWidth) right = imgWidth;
if(bottom > imgHeight) bottom = imgHeight;
if(left < 0) left = 0;
if(top < 0) top = 0;
mRect.set(left, top, right, bottom);
Bitmap bm = mDecoder.decodeRegion(mRect, null);
mView.setImageBitmap(bm);
}
}
private final Rect mRect = new Rect();
private BitmapRegionDecoder mDecoder;
private ImageView mView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mView = new ImageView(this);
mView.setAdjustViewBounds(true);
mView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
mView.setScaleType(ScaleType.CENTER);
mView.setOnTouchListener(this);
setContentView(mView);
try {
InputStream is = getResources().openRawResource(R.drawable.a);
mDecoder = BitmapRegionDecoder.newInstance(is, true);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
final int action = event.getAction() & MotionEvent.ACTION_MASK;
final int x = (int) event.getX();
final int y = (int) event.getY();
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
setImageRegion(x, y);
break;
}
return true;
}
private void setImageRegion(int left, int top) {
// BitmapFactory.Options opts = new BitmapFactory.Options();
final int width = mView.getWidth();
final int height = mView.getHeight();
final int imgWidth = mDecoder.getWidth();
final int imgHeight = mDecoder.getHeight();
int right = left + width;
int bottom = top + height;
if(right > imgWidth) right = imgWidth;
if(bottom > imgHeight) bottom = imgHeight;
if(left < 0) left = 0;
if(top < 0) top = 0;
mRect.set(left, top, right, bottom);
Bitmap bm = mDecoder.decodeRegion(mRect, null);
mView.setImageBitmap(bm);
}
}
0 0
- Android2.3使用BitmapRegionDecoder获取指定区域的图片
- Android使用BitmapRegionDecoder获取指定区域的图片
- MFC获取当前窗口指定区域的图片
- Android使用BitmapRegionDecoder加载超大图片方案
- Android使用BitmapRegionDecoder加载超大图片方案
- 拉伸图片的指定区域
- android2.3.3新类--BitmapRegionDecoder
- android2.3.3新类--BitmapRegionDecoder
- Android BitmapRegionDecoder截取图片
- 截取指定区域的并保存图片
- 指定区域显示图片
- Android获取图片指定大小的缩略图--inJustDecodeBounds的使用
- 如何使用谷歌地图api获取指定区域的经纬度
- ios 获取图片的一部分区域
- iOS获取图片的区域主色
- BitmapRegionDecoder分割超大分辨率图片
- 开发案例3——保存指定区域的图片的相机
- 截图图片中的指定区域
- linux 创建定时器运行sh命令
- Linux kernel Makefile
- 从零开始写PHP(零)
- Uva-11248-Frequency Hopping
- 虚函数与纯虚函数的作用和区别
- Android2.3使用BitmapRegionDecoder获取指定区域的图片
- static关键字的作用
- 由malloc等函数想到的一些问题
- C语言相关Warning。。。解决方案
- Validating rows when using LINQ to SQL
- php处理linux配置文件问题
- DWR入门实例(二)
- C# 中反射的介绍
- js 执行顺序