visitingCardDialog.setContentView(R.layout.visitingcardtemplate1);
Button button = (Button) visitingCardDialog.findViewById(R.id.button2);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
RelativeLayout shareLayout = (RelativeLayout) visitingCardDialog.findViewById(R.id.vistingcard);
shareLayout.setDrawingCacheEnabled(true);
shareLayout.buildDrawingCache();
Bitmap bm = shareLayout.getDrawingCache();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, bytes);
loadImage(bm)
visitingCardDialog.dismiss();
}
});
visitingCardDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
visitingCardDialog.show();
这是我的加载函数它在photoeditorview上加载位图photoeditorview是photoeditorview类的对象
private void loadImage(Bitmap image) {
phoroEditorView.getSource().setImageBitmap(image);
}
这对我很管用!
RelativeLayout shareLayout = (RelativeLayout) visitingCardDialog.findViewById(R.id.vistingcard);
shareLayout.setDrawingCacheEnabled(true);
shareLayout.buildDrawingCache();
Bitmap bm = shareLayout.getDrawingCache();
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, bytes);
try {
bm = BitmapFactory.decodeStream(getAssets().open("1024x768.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, out);
Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
//Snapshot.CroppedBitmap= Bitmap.createBitmap(shareLayout.getDrawingCache(true));
loadImage(decoded);
visitingCardDialog.dismiss();