public class MainActivity extends Activity { RelativeLayout mainLayout; ImageView immagine; Bitmap bitmap; ScaleGestureDetector detector; float scala=1.f; int bmpWidth, bmpHeight; TextView textView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mainLayout=(RelativeLayout) findViewById(R.id.mainLayout); detector=new ScaleGestureDetector(this,new listener()); immagine=(ImageView)findViewById(R.id.imageView1); textView=(TextView)findViewById(R.id.textView1); bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.calcestruzzo); bmpWidth=bitmap.getWidth(); bmpHeight=bitmap.getHeight(); drawMatrix(); } public void drawMatrix(){ bmpWidth=(int) (bmpWidth*scala); bmpHeight=(int) (bmpWidth*scala); Bitmap resizedBitmap=Bitmap.createScaledBitmap(bitmap, bmpWidth, bmpHeight, false); immagine.setImageBitmap(resizedBitmap); textView.setText(bmpWidth+" - "+bmpHeight); } @Override public boolean onTouchEvent(MotionEvent event){ detector.onTouchEvent(event); return true; } class listener extends ScaleGestureDetector.SimpleOnScaleGestureListener{ @Override public boolean onScale(ScaleGestureDetector detector){ scala=detector.getScaleFactor(); drawMatrix(); return true; } } }Me lo annoto prima di giocherellarci sopra...
Miei appunti liberi, senza pretesa di dire necessariamente sempre cose giuste o sensate, durante l'apprendimento e la pratica della programmazione
JavascriptProva
martedì 29 marzo 2016
Annotazione di codice per il pinch zoom
Ecco un codice che sembra funzionare, per il pinch zoom di una bitmap:
Iscriviti a:
Commenti sul post (Atom)
Nessun commento:
Posta un commento