【发布时间】:2013-03-07 17:55:32
【问题描述】:
【问题讨论】:
标签: android frames image-editing
【问题讨论】:
标签: android frames image-editing
有很多方法。一种非常简单的方法是,您可以在 View 的 onDraw 方法中在图像上绘制自定义框架,然后在 Bitmap 中绘制视图。还有另一种方法,将帧像素数据写入图像像素数据,然后将新图像与帧组合,您可以使用openCV或其他第三方库来解码图像。
【讨论】:
编辑:图库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 以获得图像上所需的帧位置。
【讨论】:
<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>
【讨论】: