推荐安卓开发神器(里面有各种UI特效和android代码库实例)
public class ex04_22 extends Activity{ private ImageView mImageView; private Button btn1,btn2; private TextView mTextView; private AbsoluteLayout layout1; private Bitmap bmp; private int id=0; private int displayWidth,displayHeight; private float scaleWidth=1,scaleHeight=1; private final static String filename="/data/data/ex04_22.lcs/ex04_22_2.png"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //取得屏幕分辨率 DisplayMetrics dm=new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); displayWidth=dm.widthPixels; displayHeight=dm.heightPixels-80; bmp=BitmapFactory.decodeResource(this.getResources(),R.drawable.ex04_22_1); layout1=(AbsoluteLayout)findViewById(R.id.layout1); mImageView=(ImageView)findViewById(R.id.myImageView); btn1=(Button)findViewById(R.id.myButton1); btn1.setOnClickListener(new OnClickListener(){ public void onClick(View v){ small(); } }); btn2=(Button)findViewById(R.id.myButton2); btn2.setOnClickListener(new OnClickListener(){ public void onClick(View v){ big(); } }); } private void small(){ //获得Bitmap的高和宽 int bmpWidth=bmp.getWidth(); int bmpHeight=bmp.getHeight(); //设置缩小比例 double scale=0.8; //计算出这次要缩小的比例 scaleWidth=(float)(scaleWidth*scale); scaleHeight=(float)(scaleHeight*scale); //产生resize后的Bitmap对象 Matrix matrix=new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap resizeBmp=Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true); if(id==0){ layout1.removeView(mImageView); } else{ layout1.removeView((ImageView)findViewById(id)); } id++; ImageView imageView=new ImageView(this); imageView.setId(id); imageView.setImageBitmap(resizeBmp); layout1.addView(imageView); setContentView(layout1); btn2.setEnabled(true); } private void big(){ //获得Bitmap的高和宽 int bmpWidth=bmp.getWidth(); int bmpHeight=bmp.getHeight(); //设置缩小比例 double scale=1.25; //计算出这次要缩小的比例 scaleWidth=(float)(scaleWidth*scale); scaleHeight=(float)(scaleHeight*scale); //产生resize后的Bitmap对象 Matrix matrix=new Matrix(); matrix.postScale(scaleWidth, scaleHeight); Bitmap resizeBmp=Bitmap.createBitmap(bmp, 0, 0, bmpWidth, bmpHeight, matrix, true); if(id==0){ layout1.removeView(mImageView); } else{ layout1.removeView((ImageView)findViewById(id)); } id++; ImageView imageView=new ImageView(this); imageView.setId(id); imageView.setImageBitmap(resizeBmp); layout1.addView(imageView); setContentView(layout1); if(scaleWidth*scale*bmpWidth>displayWidth||scaleHeight*scale*scaleHeight>displayHeight){ btn2.setEnabled(false); } } }
xml文件
<?xml version="1.0" encoding="utf-8"?> <AbsoluteLayout android:id="@+id/layout1" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > <ImageView android:id="@+id/myImageView" android:layout_width="200px" android:layout_height="150px" android:src="@drawable/ex04_22_1" android:layout_x="0px" android:layout_y="0px" > </ImageView> <Button android:id="@+id/myButton1" android:layout_width="90px" android:layout_height="60px" android:text="缩小" android:textSize="18sp" android:layout_x="20px" android:layout_y="372px" > </Button> <Button android:id="@+id/myButton2" android:layout_width="90px" android:layout_height="60px" android:text="放大" android:textSize="18sp" android:layout_x="210px" android:layout_y="372px" > </Button> </AbsoluteLayout>
相关推荐
本文实例为大家分享了android Matrix图片随意放大缩小和拖动的具体代码,供大家参考,具体内容如下 step1:新建一个项目DragAndZoom,并准备一张照片放在res/drawable-hdpi目录下,如下图所示: step2: 设置应用的UI...
flex实现鼠标滚动放大缩小(以鼠标的位置为中心放大缩小)源码奉上
一个简单的demo。使用android中的matrix属性,实现图片的放大、缩小、以及左旋转、右旋转。
此工程专门针对Android应用中实现手势控制图片缩放的完全攻略,更可多张图片分别切换详细查看,采用了Matrix矩阵的方法,实例讲解了包括触摸点设置与各种冲突的处理等方面,相当全面,需要的朋友可以参考下
Android开发之ImageView通过matrix实现两点缩放和图片拖动,内有较为详细的注释
该资源主要是结合博客http://blog.csdn.net/eastmount/article/details/40457273完成,主要是点击“选择图片”按钮从相册中打开图片,并显示两张图片,在底部有缩小、放大、旋转、对比、饱和,分别是对图像进行处理. ...
图片的放大缩小翻转MatrixTest,很好的资源,即通过测试,可以直接加入到项目中,适合学习。
本文实例介绍了Android实现ImageView图片双击放大及缩小的相关技巧,分享给大家供大家参考,具体内容如下 public class DoubleScaleImageView extends ImageView implements OnTouchListener, ...
1)设置图片放大缩小效果 第一步:将标签中的android:scaleType设置为fitCenter android:scaleType=fitCenter 第二步:获取屏幕的宽度 DisplayMetrics dm=new DisplayMetrics(); getWindowManager()....
本文实例讲述了C#使用Matrix执行缩放的方法。分享给大家供大家参考。具体实现方法如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing...
通过 Matrix 实现图片放大缩小。希望能帮到您们
使用C#开发的页面直接生成DataMatrix二维条码源代码,可以直接放入Aspx页面中使用。开发包使用DataMatix.Net,全部是源代码,非DLL,可以直接生成条码,并可以放大和缩小,运行环境:.Net Framework 4.0。
手势控制图片缩放,采用了Matrix矩阵的方法,实例讲解了包括触摸点设置与各种冲突的处理等方面.rar [注:本内容来自网络,在此分享仅为帮助有需要的网友,如果侵犯了您的权利,麻烦联系我,我会第一时间删除,谢谢您...
先来看一个很简单的核心图片缩放方法: public static Bitmap scale(Bitmap bitmap, float scaleWidth, float scaleHeight) { int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix...
android中图像在画布上放大缩小时,图像的边框大小没有改变! 原图如下: 放大后:原来图片的边框没有改变,位置依旧! 所以如果要放置图片的位置的话,就需要做相应的位置移动才可以! 采用如下代码(全屏放置...
该程序实现的是通过手势来缩放图片,从左向右挥动图片时图片被放大,从右向左挥动图片时图片被缩小,挥动速度越快,缩放比越大。程序思路如下:在界面中定义一个ImageView来显示图片,使用一个GestureDetector来检测...
CircleAnimation是自定义动画组件,重写了Animation.applyTransformation, 此方法根据interpolatedTime形参变量实时的计算圆周运动坐标,计算后通过Matrix对象平移控件达到圆周运动动画。
********************************************************************** android 实现图片的翻转 ********************************************************************** ... Matrix matrix = new Matrix();
想必图片的拖动和放大缩小是每个人都使用过的功能,最常见于手机相册里,你可以通过一个手指拖动你的照片,同样也可以使用双指通过缩放手势对图片进行相应的缩放。那么这是如何实现的呢? 先来看效果图: 实现原理...