2016-08-14 5 views
5

मैं फ्रेम कार्यक्षमता प्राप्त करने के लिए कोशिश कर रहा हूँ, ऐसा है कि अगर मैं एक छवि कैप्चरिंग के बाद प्रदान/गैलरी से पुन: प्राप्त करने, मैं इस कार्य कर दिया है, अब मैं कहाँ अटक कर रहा हूँ How can i merge two images with respect to frame image accordingly!!छवि में चित्र फ़्रेम कैसे जोड़ें?

अब समाधान दो छवियों के संयोजन के लिए स्पष्ट रूप से दिया जाता है Here और Here

लेकिन वे एक और ऐसे के साथ एक छवि को एडजस्ट करने के व्यवहार की व्याख्या नहीं कर रहे हैं कि मेरे मामले में, यहाँ कुछ उदाहरण हैं:

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' वर्ग के आकार प्रबंधन के संबंध में कोई अच्छी सामग्री है जो महान होगी –

संबंधित मुद्दे