Hi,
we are working on android AR project. the application works as follows
camera starts and when the camera detects the marker, a 3D object is
overlayed on the screen, so my preview will have the camera + virtual
3D object.
so i want to capture that preview.i am not able to get that preview.i
am working on android sdk 2.2 .
when i m running my app on galaxy tab 10.1, that device have the
screen capture button so its pretty easy in tab case. but for phones
running on sdk 2.2 . please give me hint on this.
my code is ************************************
package com.example;
import java.io.FileOutputStream;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.media.MediaScannerConnection;
import
android.media.MediaScannerConnection.MediaScannerConnectionClient;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
public class SaveImageActivity extends Activity {
SomeView sv = null;
MediaScannerConnection _mediaScanConnectionClient = null;
MediaScannerConnectionClient cl;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sv = new SomeView(this);
setContentView(sv);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_BACK:
Log.i("key event done", "****");
if (sv != null) {
saveView(sv);
return true;
}
default:
}
return super.onKeyDown(keyCode, event);
}
private void saveView(View view) {
Bitmap b = Bitmap.createBitmap(view.getWidth(),
view.getHeight(),
Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
view.draw(c);
FileOutputStream fos = null;
try {
fos = new
FileOutputStream("/sdcard/DCIM/Test/some_view_image_"
+ System.currentTimeMillis() + ".png");
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+
Environment.getExternalStorageDirectory())));
if (fos != null) {
b.compress(Bitmap.CompressFormat.PNG, 100, fos);
_mediaScanConnectionClient = new
MediaScannerConnection(
getApplicationContext(), cl);
_mediaScanConnectionClient.connect();
Log.i("****", "bitmap created");
fos.close();
}
//setWallpaper(b);
} catch (Exception e) {
Log.e("testSaveView", "Exception: " + e.toString());
}
}
class SomeView extends View {
public SomeView(Context context) {
super(context);
}
public void onDraw(Canvas canvas) {
canvas.drawARGB(0x80, 0xff, 0, 0);
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setTextSize(48);
canvas.drawText("...Some view...", 10,
canvas.getHeight() / 2,
paint);
}
}
}
--
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