2016-08-14 14 views
5

私は、フレームの機能を達成しようと、私はギャラリーから取り出し/取り込み後の画像を提供する場合、私はこの部分を行っているような、今私は立ち往生午前どこAMは今、2枚の画像を合成するための解決策が明確に与えられているHow can i merge two images with respect to frame image accordingly!!画像に画像フレームを追加するには?

ですHereHere

しかし、彼らは私の場合には、ここではいくつかの例があることを別のようにして一つの画像を調整する動作を説明されていません。

image with frame1

image with frame2

I am already using Libraries like picasso and EasyImage so if they can help?

編集:

テストフレームの例test frame

+0

あなたは、画像のビットマップと、フレームのビットマップに合わせてビットマップを、回転変換し、スケールすることができます。ここでは、ビットマップの回転、変換、スケーリングの例です。http://android-code.blogspot.jp/2015/11/android-how-to-rotate-bitmap-on-canvas.html – nshmura

+0

@nshmuraそれは簡単ではありませんが、どのようにすれば、どのように回転だけを使って画像を調整し、変換することができるのでしょうか? –

+0

私は、回転、翻訳、および拡大縮小を行うことができると思います。フレーム画像を投稿できますか? – nshmura

答えて

2

私は例を作りました。このリポジトリを参照してください。 https://github.com/nshmura/TestFrame/

Frameクラスは、ピクチャのビットマップとフレームのビットマップをマージします。

public class Frame { 

    //filename of frame 
    private String mFrameName; 

    //Rect of picture area in frame 
    private final Rect mPictureRect; 

    //degree of rotation to fit picture and frame. 
    private final float mRorate; 

    public Frame(String frameName,int left, int top, int right, int bottom, float rorate) { 
     mFrameName = frameName; 
     mPictureRect = new Rect(left, top, right, bottom); 
     mRorate = rorate; 
    } 

    public Bitmap mergeWith(Context context, Bitmap pictureBitmap) { 
     Bitmap frameBitmap = AssetsUtil.getBitmapFromAsset(context, mFrameName); 

     Bitmap.Config conf = Bitmap.Config.ARGB_8888; 
     Bitmap bitmap = Bitmap.createBitmap(frameBitmap.getWidth(), frameBitmap.getHeight(), conf); 
     Canvas canvas = new Canvas(bitmap); 

     Matrix matrix = getMatrix(pictureBitmap); 
     canvas.drawBitmap(pictureBitmap, matrix, null); 

     canvas.drawBitmap(frameBitmap, 0, 0, null); 

     return bitmap; 

    } 

    Matrix getMatrix(Bitmap pictureBitmap) { 
     float widthRatio = mPictureRect.width()/(float) pictureBitmap.getWidth(); 
     float heightRatio = mPictureRect.height()/(float) pictureBitmap.getHeight(); 

     float ratio; 

     if (widthRatio > heightRatio) { 
      ratio = widthRatio; 

     } else { 
      ratio = heightRatio; 
     } 

     float width = pictureBitmap.getWidth() * ratio; 
     float height = pictureBitmap.getHeight() * ratio; 
     float left = mPictureRect.left - (width - mPictureRect.width())/2f; 
     float top = mPictureRect.top - (height - mPictureRect.height())/2f; 

     Matrix matrix = new Matrix(); 
     matrix.postRotate(mRorate); 
     matrix.postScale(ratio, ratio); 
     matrix.postTranslate(left, top); 

     return matrix; 
    } 
} 

このような用途:

//This is sample picture. 
//Please take picture form gallery or camera. 
Bitmap pictureBitmap = AssetsUtil.getBitmapFromAsset(this, "picture.jpg"); 

//This is sample frame. 
// the number of left, top, right, bottom is the area to show picture. 
// last argument is degree of rotation to fit picture and frame. 
Frame frameA = new Frame("frame_a.png", 113, 93, 430, 409, 4); 
Bitmap mergedBitmap = frameA. mergeWith(this, pictureBitmap); 

//showing result bitmap 
ImageView imageView = (ImageView) findViewById(R.id.image); 
imageView.setImageBitmap(mergedBitmap); 

結果は以下の通りです:

enter image description here

+0

左、右、上、下、整数が動作しますが、私はそれを私の写真では動作させようとしていますが、そうすることができません。フレーム画像以外は何も表示されません –

+0

。 – nshmura

+0

「Rect」クラスのサイズ処理に関する素晴らしい資料があれば、「Rect」クラスではそれほど快適ではありません –

関連する問題