我想创建一个应用程序,我需要在其中添加框架到图像。我不知道重新分级这个。我有一个链接,框架被添加到图像中。任何人都可以帮助我。
这是链接
@提前致谢!!
编辑:画廊OnItemClickListener
gallery.setOnItemClickListener(new OnItemClickListener() {
Bitmap frame = null, out = null;
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Bitmap urImage = BitmapFactory.decodeResource(getResources(),
R.drawable.urBackgroundImageID);//edit
frame = BitmapFactory.decodeResource(getResources(),
frames[arg2]);
out = combineImages(frame, urImage);
imageView.setImageBitmap(out); //add "out" for ur ImageView
}
});
frames[]
是可绘制的数组,即不同的帧
以下方法将动态组合两个图像
public Bitmap combineImages(Bitmap frame, Bitmap image) {
Bitmap cs = null;
Bitmap rs = null;
rs = Bitmap.createScaledBitmap(frame, image.getWidth(),
image.getHeight(), true);
cs = Bitmap.createBitmap(rs.getWidth(), rs.getHeight(),
Bitmap.Config.RGB_565);
Canvas comboImage = new Canvas(cs);
comboImage.drawBitmap(image, 0, 0, null);
comboImage.drawBitmap(rs, 0, 0, null);
if (rs != null) {
rs.recycle();
rs = null;
}
Runtime.getRuntime().gc();
return cs;
}
您可以尝试不同的整数值
comboImage.drawBitmap(image, 0, 0, null);
comboImage.drawBitmap(rs, 0, 0, null);
我放在那里0
以获得图像上所需的帧位置。
有很多方法。一种非常简单的方法是,您可以在 View 的 onDraw 方法中在图像上绘制自定义框架,然后在 Bitmap 中绘制视图。还有另一种方法,将帧像素数据写入图像像素数据,然后将新图像与帧组合,您可以使用 openCV 或其他第三方库来解码图像。
<FrameLayout
android:id="@+id/frame"
android:layout_width="120dp"
android:layout_height="120dp"
android:foreground="@drawable/your frame...">
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="10dp"
android:layout_gravity="center"
android:src="@drawable/ic_launcher" />
</FrameLayout>