cómo combinar dos imágenes en Android programando en java y guardando en una tarjeta SD externa o en otro lugar.Combine Images en android
Respuesta
probar este código.
private static final String TAG = "JoinImage";
private Bitmap mBackImage, mTopImage, mBackground;
private BitmapDrawable mBitmapDrawable;
private static String mTempDir;
private String mSavedImageName = null;
private FileOutputStream mFileOutputStream = null;
private Canvas mCanvas;
en onCreate()
//Create folder in SDCard to store newly generated image
mTempDir = Environment.getExternalStorageDirectory() + "/TestTemp/";
File mTempFile = new File(mTempDir);
if(!mTempFile.exists()) {
mTempFile.mkdirs();
}
//File name
mSavedImageName = "Test.png";
//Width = 604, Height = 1024 Change as per your requirement
mBackground = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
//Put back and top images in your res folder
mBackImage = BitmapFactory.decodeResource(getResources(), R.drawable.launcher);
mTopImage = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
mCanvas = new Canvas(mBackground);
mCanvas.drawBitmap(mBackImage, 0f, 0f, null);
mCanvas.drawBitmap(mTopImage, 12f, 12f, null);
try {
mBitmapDrawable = new BitmapDrawable(mBackground);
Bitmap mNewSaving = mBitmapDrawable.getBitmap();
String FtoSave = mTempDir + mSavedImageName;
File mFile = new File(FtoSave);
mFileOutputStream = new FileOutputStream(mFile);
mNewSaving.compress(CompressFormat.PNG, 95, mFileOutputStream);
mFileOutputStream.flush();
mFileOutputStream.close();
} catch(FileNotFoundException e) {
Log.e(TAG, "FileNotFoundExceptionError " + e.toString());
} catch(IOException e) {
Log.e(TAG, "IOExceptionError " + e.toString());
}
Log.i(TAG, "Image Created");
en Manifest
anadir este utiliza en permisos <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Try continuación Código
private Bitmap joinImages(File first, File second)
{
Bitmap bmp1, bmp2;
bmp1 = BitmapFactory.decodeFile(first.getPath());
bmp2 = BitmapFactory.decodeFile(second.getPath());
if (bmp1 == null || bmp2 == null)
return bmp1;
int height = bmp1.getHeight();
if (height < bmp2.getHeight())
height = bmp2.getHeight();
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth() + bmp2.getWidth(), height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, 0, 0, null);
canvas.drawBitmap(bmp2, bmp1.getWidth(), 0, null);
return bmOverlay;
}
hola tengo un error en este código, muestra que el mapa de bits es inmutable ??? Que es esto. Gracias – Herry
dónde en qué línea dice y está utilizando este código exactamente? – ingsaurabh
en la línea del lienzo, muestra el error de cualquier forma, gracias obtuve la respuesta de este enlace [http://ketankantilal.blogspot.com/2011/03/how-to-combine-images-and-store-to.html gracias por la ayuda. – Herry
- 1. Android Drawable Images from URL
- 2. Royalty Free Background Images For Android Application
- 3. Css/images/javascript en codeigniter
- 4. Lazy Load images on Listview in android (Beginner Level)?
- 5. ¿Hay QPath :: Combine en QT4?
- 6. Google images api
- 7. GridView auto fit images
- 8. JLabel images array
- 9. WPF TabItem Header Images
- 10. Google similar images algorithm
- 11. jQuery randomly fadeIn images
- 12. PyParsing: ¿Qué hace Combine()?
- 13. MSBuild combine files
- 14. Combine NotifyIcon y ToolTip
- 15. html table cells combine
- 16. Jquery Cycle + Firefox Squishing Images
- 17. ASP.NET TextRenderer.DrawText Awful Text Images
- 18. simpleCart js thumbnail images undefined
- 19. Excel - Combine varias columnas en una columna
- 20. Batch Combine CSV Remove Header
- 21. ¿Cuál es la diferencia entre src = "/ images/logo.gif" y src = "images/logo.gif"?
- 22. Crystal Reports Images y ASP.Net MVC
- 23. Listar todo Google Map Marker Images
- 24. LabVIEW, C++ DLL, e IMAQ Images
- 25. PyQt4: combine textChanged y editingFinished para QLineEdit
- 26. Combine DVCS con Visual Source Safe
- 27. Python 2.7 Combine abc.abstractmethod y classmethod
- 28. jQuery combine funciones .ready y .resize
- 29. Combine layout_weight y maxWidth para vistas
- 30. LINQ: combine join y group por
lo qué se refiere exactamente mediante la fusión de dos imágenes? –
tengo dos imágenes diferentes que quiero hacer un programa en Android que combine estas imágenes como una sola imagen por programación. – Herry
Una vez más, ¿a qué te refieres con combinar? Si tiene dos imágenes, desea producir una sola imagen que sea concatenación de las dos o si desea sumar los valores de píxel de alguna manera. Si la primera imagen es más grande que la segunda? Explique con más detalles –