How to take screen shot via programmatically particular view in Android
This post about how take screen shot particular via program.see the below example.
I have create three views
1.map
2.button
3.imageview
I tried to take screen shot of Map view.
xml code
Activity code
Before Taking Screen Shot
Download Source Code Here
This post about how take screen shot particular via program.see the below example.
I have create three views
1.map
2.button
3.imageview
I tried to take screen shot of Map view.
xml code
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.vj.screencapture.MainActivity"
tools:ignore="MergeRootFrame"
>
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<fragment
android:id="@+id/map"
android:layout_width="356dp"
android:layout_height="250dip"
class="com.google.android.gms.maps.SupportMapFragment"
/>
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/map_capture_btn"
/>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="200dp"
/>
</LinearLayout>
</FrameLayout>
Activity code
package
com.vj.screencapture;
import
com.google.android.gms.maps.GoogleMap;
import
com.google.android.gms.maps.SupportMapFragment;
import
android.support.v4.app.FragmentActivity;
import
android.graphics.Bitmap;
import
android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.ImageView;
import
android.widget.LinearLayout;
public class MainActivity extends FragmentActivity {
ImageView im;
LinearLayout linerlay;
GoogleMap gMap;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment mapFrag =
(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
gMap = mapFrag.getMap();
gMap.setMyLocationEnabled(true);
gMap.getUiSettings().setZoomControlsEnabled(true);
gMap.getUiSettings().setCompassEnabled(true);
linerlay = (LinearLayout)findViewById(R.id.linearLayout);
im = (ImageView)findViewById(R.id.imageView1);
Button btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
View v1 = im.getRootView().findViewById(R.id.map);
v1.setDrawingCacheEnabled(true);
Bitmap bm =
v1.getDrawingCache();
BitmapDrawable bitmapDrawable
= new BitmapDrawable(bm);
im.setImageBitmap(bm);
}
});
}
}
Before Taking Screen Shot
Before Take Screen Shot of Map View |
After Taking Screen Shot of Map view |
View v1 = im.getRootView().findViewById(R.id.map);
v1.setDrawingCacheEnabled(true);
Bitmap bm =
v1.getDrawingCache();
BitmapDrawable bitmapDrawable = new BitmapDrawable(bm);
im.setImageBitmap(bm);
Download Source Code Here
No comments:
Post a Comment