When using capture image layout . unfortunately , app has stopped , i when have 1 or 2 ,3 Image View in layout , the app works is ok but when add more image view in layout , app stopped ! Tank's u , for help me :);
code :
btn_save.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AsyncTask<Void, Void, Void> task = new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute() {
String MESSG= "Save Image";
String title="Processing ...";
SpannableString ss1= new SpannableString(title);
ss1.setSpan(new RelativeSizeSpan(1f), 0, ss1.length(), 0);
ss1.setSpan(new ForegroundColorSpan(Color.parseColor("#ff0000")), 0, ss1.length(), 0);
SpannableString ss2= new SpannableString(MESSG);
ss2.setSpan(new RelativeSizeSpan(1f), 0, ss2.length(), 0);
ss2.setSpan(new ForegroundColorSpan(Color.parseColor("#ff0000")), 0, ss2.length(), 0);
pd = new ProgressDialog(First.this);
pd.setTitle(ss1);
pd.setMessage(ss2);
pd.setCancelable(false);
pd.setIndeterminate(true);
pd.show();
}
@Override
protected Void doInBackground(Void... args) {
View content = findViewById(R.id.lay_canvens);
content.setDrawingCacheEnabled(true);
Bitmap bitmap = content.getDrawingCache();
bitmap = Bitmap.createBitmap(Bitmap.createBitmap(
content.getWidth() * 2, content.getHeight() * 2,
Bitmap.Config.ARGB_8888));
Canvas bitmapCanvas = new Canvas();
bitmapCanvas.setBitmap(bitmap);
bitmapCanvas.scale(2.0f, 2.0f);
content.draw(bitmapCanvas);
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
File imagesFolder = new File(Environment.getExternalStorageDirectory(),
"Photos");
imagesFolder.mkdirs();
int n=0;
String fileName = "Photos-" + String.valueOf(n) + ".JPEG";
File output = new File(imagesFolder, fileName);
while (output.exists()) {
n++;
fileName = "Photos-" + String.valueOf(n) + ".JPEG";
output = new File(imagesFolder, fileName);
}
Uri uriSavedImage = Uri.fromFile(output);
OutputStream imageFileOS;
try {
imageFileOS = getContentResolver().openOutputStream(uriSavedImage);
imageFileOS.write(out.toByteArray());
imageFileOS.flush();
imageFileOS.close();
} catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(), e+"", Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(getApplicationContext(), e+"", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
if (pd!=null) {
pd.dismiss();
}
}
};
task.execute((Void[])null);
}
});
Aucun commentaire:
Enregistrer un commentaire