I want to create a ImageButton and set an image as background mantaining original size. So I use this few lines of code find on StackOverflow too:
ImageButton retry = new ImageButton(this);
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.button2);
retry.setImageBitmap(image);
retry.setMinimumWidth(image.getWidth());
retry.setMinimumHeight(image.getHeight());
But unfortunately I obtain following result:

Obviously I don’t want the “background button”, but only the image. How can I do?
It depends on your image but. You can achieve this by writing style to your button.
Firstl you should define your shape for your button in drawables folder(if it doesnt exist dont hesitate to create and define button_shape.xml).
After you define your style in style file.
and set style property of Button.