このコードを使用して 2 つの画像を 1 つに結合することができましたが、SD カードに保存する方法がわかりません。アプリ名にちなんで名付けられたSDカードのフォルダーに保存したい。
おまけ: イメージ名が日時または一意のものの後にあると、イメージ名のコピーがないようにできます。
public class CombineImages extends View{
private Bitmap buffer;
private Canvas canvas;
private Matrix matrix = new Matrix();
public CombineImages(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CombineImages(Context context) {
super(context);
}
public void combine(ImageView imageView){
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
combine(bitmap);
}
public void combine(Bitmap bitmap) {
updateBuffer(bitmap);
draw(canvas);
postInvalidate();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(buffer, matrix , null);
}
private void updateBuffer(Bitmap bitmap) {
if(buffer == null){
createBuffer(bitmap);
}
else{
if(bitmap.getWidth() > buffer.getWidth() || bitmap.getHeight() > buffer.getHeight()){
Bitmap oldBuffer = buffer;
createBuffer(bitmap);
drawBitmnapToBuffer(oldBuffer);
oldBuffer.recycle();
}
drawBitmnapToBuffer(bitmap);
}
getLayoutParams().height = buffer.getHeight();
getLayoutParams().width = buffer.getWidth();
}
private void drawBitmnapToBuffer(Bitmap bitmap) {
canvas.save();
// add your translation logic here using canvas.translate(dx, dy);
canvas.drawBitmap(bitmap, matrix, null);
canvas.restore();
}
private void createBuffer(Bitmap bitmap) {
buffer = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);
canvas = new Canvas(buffer);
}
}