Search This Blog

Monday, October 24, 2016

Camera - Chụp hình lưu thành file

public void SaveImageHadConvert()
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
if(saveFileSuccessTruoc)
{
if (m_camera != null)
m_camera.stopPreview();
}

Bitmap bit = overlay(bitmapSau);

File fileFolder;
File fileImage;
FileOutputStream os;

try
{
fileFolder = new File(Environment.getExternalStorageDirectory() + "/eBiz4DPPC");
if(!fileFolder.exists())
{
fileFolder.mkdirs();
}

m_strImageFileName = fileFolder.getPath() + "/" + m_strCustID + "_" + m_strType + "_" + (new SimpleDateFormat("yyyyMMddHHmmss")).format(new Date()) + ".jpg";
fileImage = new File(m_strImageFileName);

FileOutputStream fos = new FileOutputStream(fileImage);              
bit.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
bit.recycle();
bit = null;
}
catch (Exception e)
{
clsUtil.ShowMsgErr(frmDualCamera.this, e.getMessage());
}
}
});
}




private Bitmap overlay(Bitmap bmp1)
{
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, new Matrix(), null);

return bmOverlay;
}

No comments:

Post a Comment