मैं उदाहरण बना दिया। कृपया इस भंडार का संदर्भ लें। 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);
परिणाम नीचे है:
आप घुमा सकते हैं अनुवाद और पैमाने बिटमैप छवि के बिटमैप और फ्रेम के बिटमैप फिट करने के लिए। यहां बिटमैप घूर्णन, अनुवाद और स्केलिंग का उदाहरण है http://android--code.blogspot.jp/2015/11/android-how-to-rotate-bitmap-on-canvas.html – nshmura
@nshmura यह इतना आसान नहीं है, क्या होगा यदि कोई भी यह सुनिश्चित कर सके कि छवि को घुमाने और बदलने के द्वारा समायोजित किया जाएगा? –
मुझे लगता है कि हम घुमाने, अनुवाद और पैमाने के साथ कर सकते हैं। क्या आप अपनी फ्रेम छवि पोस्ट कर सकते हैं? – nshmura