Search This Blog

Showing posts with label Image And Video In android. Show all posts
Showing posts with label Image And Video In android. Show all posts

Saturday, 6 April 2013

Update Pinch to zoom example and tutorial for android ImageView with zoom limit

I wrote on the same topic Pinch to zoom in android ImageView while i just started blogging. And that still is my one of the popular article, despite that it has many complication and limitation with it. So i am working to improve it. After reading most comment, I feel some problems while implementing pinch to zoom with android ImageView using previous post
  • How to implement that pinch to zoom in their project? 
  • Determining Zoom limit in pinch to zoom ImageView! 
  • Does not work properly as i told in post !! 

So now i come up with a solution in which every drawback avoided and pinch to zoom image in android seems quite simple and work perfect
Follows thes easy steps

1) Create a new project and Download this library , add this Jar to libs folder of your project 

2) Create one layout with one ImageView (Which need to be zoom)

3) Create one Activity and change to following code. This will handle all attributes required for pinch to zoom ImageView


import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.RectF;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.imagezoom.ImageAttacher;
import com.imagezoom.ImageAttacher.OnMatrixChangedListener;
import com.imagezoom.ImageAttacher.OnPhotoTapListener;

public class SampleZoom extends Activity {
    ImageView mImaView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pinch_sample);
        mImaView = (ImageView) findViewById(R.id.simple);

        Bitmap bimtBitmap = BitmapFactory.decodeResource(getResources(),
                R.drawable.a);
        mImaView.setImageBitmap(bimtBitmap);

        /**
         * Use Simple ImageView
         */
        usingSimpleImage(mImaView);

    }

    public void usingSimpleImage(ImageView imageView) {
        ImageAttacher mAttacher = new ImageAttacher(imageView);
        ImageAttacher.MAX_ZOOM = 2.0f; // Double the current Size
        ImageAttacher.MIN_ZOOM = 0.5f; // Half the current Size
        MatrixChangeListener mMaListener = new MatrixChangeListener();
        mAttacher.setOnMatrixChangeListener(mMaListener);
        PhotoTapListener mPhotoTap = new PhotoTapListener();
        mAttacher.setOnPhotoTapListener(mPhotoTap);
    }

    private class PhotoTapListener implements OnPhotoTapListener {

        @Override
        public void onPhotoTap(View view, float x, float y) {
        }
    }

    private class MatrixChangeListener implements OnMatrixChangedListener {

        @Override
        public void onMatrixChanged(RectF rect) {

        }
    }
}

Implementing Zoom Limit. 


See inside function usingSimpleImage(), below two line decide zoom limit ImageAttacher.MAX_ZOOM = 2.0f;  // Double the current Size ImageAttacher.MIN_ZOOM = 0.5f; // Half the current Size

Note : Work perfect for the image with fit width (either in Landscape or portrait)

Sunday, 3 March 2013

Video Chat API in android provide Group Video Chat, Peer to peer and Mobile to Web

Video chat in android is the hot topic in every mobile either Android or iPhone. While making application based on social networking, including Video chat option can raise your application standard. Even though android does not provide directly anything related to video chat, but there are lots of work around for this.
Challenge while implement Video chat are

  • Video Quality on internet 
  • Video Delay while streaming
  • And implementing between cross platform
So looking for API considering all possibilities is quite difficult before OpenTok comes in to scene.
Before implementing into your project see the pricing which is very crucial to your project nature and scale


OpenTok Pricing

I have been touch with them since last one month, They have launch the early beta version of android version and working hard to launch it completely in April 2013

Current Support for android device

Nexus 4, Nexus 7 and S3

Full Version is expected to launch in next month

How to start implementing 




Sunday, 6 May 2012

Taking picture and Video from Camera and displaying or playing in android

Taking picture in android has two way to achieve it

1) Using  Surface view with Camera integration
2)Starting Default Camera Activity that will return an intent with picture

first way i have discussed in How to take picture with surface View and camera .Now i am going to discuss second way of taking picture from android camera. And In code you will also know how to take Video in android and Playing it. I will display taken image in ImageView and video will be start paying in a videoview. User Interface will be similar to this when you will run code


Source code and screen shot are available at the end of article

private void dispatchTakePictureIntent(int actionCode) {

        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            File f = null;
            try {
                f = setUpPhotoFile();
                mCurrentPhotoPath = f.getAbsolutePath();
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
            } catch (IOException e) {
                e.printStackTrace();
                f = null;
                mCurrentPhotoPath = null;
       } // switch
startActivityForResult(takePictureIntent, actionCode);
    }

This method will dispatch a intent and will start an Camera Activity . In my code i have two option weather you want to take big picture or small one (to avoid memory error ). So you will get a switch case there. actioncode is decide, we will have to handle big Image or small Image.

Here are the step to create file path to save image

setUpPhotoFile() this method is used to create a file for saving image

 mCurrentPhotoPath = f.getAbsolutePath(); // this will save the file path and will pass into intent so that it will take it to save image later on

finally we will start activity

startActivityForResult(takePictureIntent, actionCode);

Now if we click picture then we have to handle intent data inside the onActivityResult()

private void handleSmallCameraPhoto(Intent intent) {
  Bundle extras = intent.getExtras();
  mImageBitmap = (Bitmap) extras.get("data");
  mImageView.setImageBitmap(mImageBitmap);
  mVideoUri = null;
  mImageView.setVisibility(View.VISIBLE);
  mVideoView.setVisibility(View.INVISIBLE);
 }

In activity result i have three method  one for handle small picture intent, second to handle big picture then one for handle Video .If you are taking video or big picture then study these method


 private void handleBigCameraPhoto() {

  if (mCurrentPhotoPath != null) {
   setPic();
   galleryAddPic();
   mCurrentPhotoPath = null;
  }
 }



      private void handleCameraVideo(Intent intent) {
  mVideoUri = intent.getData();
  mVideoView.setVideoURI(mVideoUri);
  mImageBitmap = null;
  mVideoView.setVisibility(View.VISIBLE);
  mImageView.setVisibility(View.INVISIBLE);
 }

                                                        Screen shot of this project



    

Source Code

Android News and source code