拍照时放置相框 Android 工作室
Place frame when taking photo Android Studio
我想开发一个应用程序,可以拍照并允许您 select 一个相框。
我已经开发了接口,比如拍照和存储。
但是我给拍的照片加了个框我不行
有什么推荐吗?
您以什么格式存储拍摄的照片和相框图像?如果你打算把你的照片插入一个简单的框架,我建议先把你拍的照片画在 Canvas 上,然后在上面画你的框架。请记住大小 - 您不希望您的图片太小或太大。
我在这里提供了一个示例片段:
public Bitmap Output(Bitmap takenPhoto, Bitmap frameImage)
{
int width, height, x, y;
height = ### // your desired height of the whole output image
width = ### // your desired width of the whole output image
x = ### // specify indentation for the picture
y = ###
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(result);
Paint paint = new Paint();
c.drawBitmap(takenPhoto, x, y, paint); // draw your photo over canvas, keep indentation in mind (x and y)
c.drawBitmap(frameImage, 0, 0, paint); // now draw your frame on top of the image
return result;
}
请记住,我尚未测试代码,您可能(实际上,您必须)应用更正。
感谢您的帮助,我把我的解决方案:
ImageView 结果;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bitmap miBitmap = Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(miBitmap);
Paint paint = new Paint();
c.drawBitmap(drawableToBitmap(R.mipmap.ic_launcher), 500, 500, paint); // draw your photo over canvas, keep indentation in mind (x and y)
c.drawBitmap(drawableToBitmap(R.drawable.silver_frame), 0, 0, paint); // now draw your frame on top of the image
Resultado.setImageBitmap(miBitmap);
}
public Bitmap drawableToBitmap(int imagen){
return BitmapFactory.decodeResource(getApplicationContext().getResources(), imagen);
}
我想开发一个应用程序,可以拍照并允许您 select 一个相框。
我已经开发了接口,比如拍照和存储。
但是我给拍的照片加了个框我不行
有什么推荐吗?
您以什么格式存储拍摄的照片和相框图像?如果你打算把你的照片插入一个简单的框架,我建议先把你拍的照片画在 Canvas 上,然后在上面画你的框架。请记住大小 - 您不希望您的图片太小或太大。
我在这里提供了一个示例片段:
public Bitmap Output(Bitmap takenPhoto, Bitmap frameImage)
{
int width, height, x, y;
height = ### // your desired height of the whole output image
width = ### // your desired width of the whole output image
x = ### // specify indentation for the picture
y = ###
Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(result);
Paint paint = new Paint();
c.drawBitmap(takenPhoto, x, y, paint); // draw your photo over canvas, keep indentation in mind (x and y)
c.drawBitmap(frameImage, 0, 0, paint); // now draw your frame on top of the image
return result;
}
请记住,我尚未测试代码,您可能(实际上,您必须)应用更正。
感谢您的帮助,我把我的解决方案:
ImageView 结果;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bitmap miBitmap = Bitmap.createBitmap(1000, 1000, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(miBitmap);
Paint paint = new Paint();
c.drawBitmap(drawableToBitmap(R.mipmap.ic_launcher), 500, 500, paint); // draw your photo over canvas, keep indentation in mind (x and y)
c.drawBitmap(drawableToBitmap(R.drawable.silver_frame), 0, 0, paint); // now draw your frame on top of the image
Resultado.setImageBitmap(miBitmap);
}
public Bitmap drawableToBitmap(int imagen){
return BitmapFactory.decodeResource(getApplicationContext().getResources(), imagen);
}