I already tried.But no use.Please help .
On Fri, Dec 16, 2011 at 7:33 PM, New Developer <[email protected]> wrote:
> Look at the setRotationX() setRotationY() and setScaleX() setScaleY()
> They sure make the work much easier
>
>
>
> On 12/16/2011 08:59 AM, chowdary nani wrote:
>
>
> Hi All,
> I need help on Image zoom and Image rotate in android with in the same
> screen
> I am developing using below code.
>
> public class ImageRotateActivity extends Activity {
> /** Called when the activity is first created. */
> private ImageView img;
> private Button rotate;
> private Button zoom;
> float degrees =0;
>
> @Override
> protected void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
>
> zoom=(Button)findViewById(R.id.button2);
> zoom.setOnClickListener(new OnClickListener() {
> public void onClick(View v) {
> // TODO Auto-generated method stub
>
> setContentView(new Zoom(this));
> }
> });
> rotate = (Button) findViewById(R.id.button1);
> rotate.setOnClickListener(new OnClickListener() {
>
> public void onClick(View v) {
> // TODO Auto-generated method stub
> setContentView(R.layout.main);
> make(degrees);
> }
> });
>
> }
>
>
>
> public void make(float x){
>
> android.util.Log.i("INSIDE MAKE", "inside make");
>
> LinearLayout linLayout = new LinearLayout(this);
>
>
>
> // load the origial BitMap (500 x 500 px)
>
> Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
>
> R.drawable.honeycomb);
>
>
>
> int width = bitmapOrg.getWidth();
>
> int height = bitmapOrg.getHeight();
>
> int newWidth = 200;
>
> int newHeight = 200;
>
>
>
> // calculate the scale - in this case = 0.4f
>
> float scaleWidth = ((float) newWidth) / width;
>
> float scaleHeight = ((float) newHeight) / height;
>
>
>
> // createa matrix for the manipulation
>
> Matrix matrix = new Matrix();
>
> // resize the bit map
>
> matrix.postScale(scaleWidth, scaleHeight);
>
> // rotate the Bitmap
>
> matrix.postRotate(x);
>
>
>
> // recreate the new Bitmap
>
> Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0,
>
> width, height, matrix, true);
>
>
>
> // make a Drawable from Bitmap to allow to set the BitMap
>
> // to the ImageView, ImageButton or what ever
>
> BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
>
>
>
> ImageView imageView = new ImageView(this);
>
>
>
> // set the Drawable on the ImageView
>
> imageView.setImageDrawable(bmd);
>
>
>
> // center the Image
>
> imageView.setScaleType(ScaleType.CENTER);
>
>
>
> // add ImageView to the Layout
>
> linLayout.addView(imageView,
>
> new LinearLayout.LayoutParams(
>
> LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT
>
> )
>
> );
>
>
>
> // set LinearLayout as ContentView
>
> setContentView(linLayout);
>
> android.util.Log.i("GOING OUT MAKE", "going out make");
>
> }
>
>
>
> public boolean onKeyDown(int keyCode, KeyEvent event) {
>
>
>
> if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// rotate clockwise
>
> // zoomControler+=10;
>
> {
>
> degrees=degrees+10;
>
> make(degrees);
>
> //make(10);
>
> android.util.Log.i("ONE","rotating clockwise by
> "+String.valueOf(degrees)+" degrees");
>
> android.util.Log.i("DEGREES","current value
> "+String.valueOf(degrees)+" degrees");
>
> }
>
>
>
>
>
> if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // rotate anti-clockwise
>
> {
>
> degrees=degrees-10;
>
> make(degrees);
>
> //make(10);
>
> android.util.Log.i("TWO","rotating anti-clockwise by
> "+String.valueOf(degrees)+" degrees");
>
> android.util.Log.i("DEGREES","current value
> "+String.valueOf(degrees)+" degrees");
>
>
>
> }
>
>
>
> // invalidate();
>
> return true;
>
> }
>
> }
>
>
> public class Zoom extends View {
> private Drawable image;
> private ImageView img;
> float degrees = 0;
>
> private int zoomControler = 20;
>
> public Zoom(Context context) {
> super(context);
> image = context.getResources().getDrawable(R.drawable.honeycomb);
> setFocusable(true);
>
> }
>
> @Override
> protected void onDraw(Canvas canvas) {
> // TODO Auto-generated method stub
> super.onDraw(canvas);
> // here u can control the width and height of the images........ this
> // line is very important
> image.setBounds((getWidth() / 2) - zoomControler, (getHeight() / 2)
> - zoomControler, (getWidth() / 2) + zoomControler,
> (getHeight() / 2) + zoomControler);
> image.draw(canvas);
> }
>
> @Override
> public boolean onKeyDown(int keyCode, KeyEvent event) {
>
> if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)// zoom in
> zoomControler += 10;
> if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) // zoom out
> zoomControler -= 10;
> if (zoomControler < 10)
> zoomControler = 10;
>
> invalidate();
> return true;
> }
> }
>
>
>
>
> Here any one i.e, either zoom or image rotation is getting well but when
> trying to use both getting error
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en