[英]Augmented reality in Android for Positioning Map Overlays on Camera View
[英]taking screenshot camera view+layout view android augmented reality
我尝试从帧缓冲区中获取屏幕捕获,它非常适合我的布局视图,我在这里使用了以下代码:
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;
// create bitmap screen capture
Bitmap bitmap;
View v1 = mCurrentUrlMask.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
OutputStream fout = null;
imageFile = new File(mPath);
try {
fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
fout.flush();
fout.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但是我想用相机视图捕获布局视图,因为我也在布局视图或透明网页的背景中使用cameraview。 一种解决方法是分别拍摄相机图像和布局视图,并将它们彼此放置并保存新的位图。
有人可以建议我对此采取任何适当的解决方案吗? 提前致谢
为了将两个图像放在一起,您可能希望遵循此代码以其100%的效果将两个图像叠加在一起
Bitmap border = BitmapFactory.decodeResource(getResources(), R.drawable.vignette2);
int width = bmp.getWidth();
int height = bmp.getHeight();
change = Bitmap.createScaledBitmap(change, width, height, false); // change is Bitmap
Canvas canvas = new Canvas(change);
Bitmap scaledBorder = Bitmap.createScaledBitmap(border,width,height, false);
canvas.drawBitmap(scaledBorder, 0, 0,null);
//canvas.drawBitmap(k, 0, 0, null);
view.setImageBitmap(change); // view is the imageView
现在是保存视图的一部分,简单的方法是
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
save = view.getDrawingCache(); // save is a Bitmap
接着 :
final FileOutputStream out = new FileOutputStream(file);
save.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
Toast.makeText(getApplication(), "Image Saved",
Toast.LENGTH_SHORT).show();
这将为您保存imageview的视图,或者如果它的Layout只是设置您的布局并给它命名,然后用view
替换它,请在您检查保存是否成功设置后不要忘记
view.setDrawingCacheEnabled(false);
我无法将代码发布为注释,因此您可以在onActivtity上传递该特定方法,或者在您发送意图或自定义摄像头后传递它,然后可以在单击“摄像头”按钮时进行控制只需添加一种方法即可捕获视图。 这是我保存视图的方法。
void Save() {
if (null != view.getDrawable()) {
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
save = view.getDrawingCache();
final File myDir = new File(folder);
myDir.mkdirs();
final Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
final String fname = "StyleMe-" + n + ".png";
final File file = new File(myDir, fname);
if (file.exists())
file.delete();
try {
final FileOutputStream out = new FileOutputStream(file);
save.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"
+ Environment.getExternalStorageDirectory())));
Toast.makeText(getApplication(), "Image Saved",
Toast.LENGTH_SHORT).show();
} catch (final Exception e) {
Toast.makeText(getApplication(),
"Something Went Wrong check if you have Enough Memory",
Toast.LENGTH_LONG).show();
}
} else {
final Toast tst = Toast.makeText(getApplication(),
"Please Select An Image First", Toast.LENGTH_LONG);
tst.setGravity(Gravity.CENTER, 0, 0);
tst.show();
}
view.setDrawingCacheEnabled(false);
}
为了让您连续保存视图,只需添加loop即可。 当您单击相机按钮时,循环开始! 在这里,在我的保存方法中,不必担心重叠名称:)。 它将随机生成每个图像的名称!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.