I want to create an image (e.g coupons) in my applications by giving the specifications in the edit text.Let suppose i have 3 edit texts for name,color,content respectively.when i fill these details and click on submit button, A image should generate containing all the specifications that i have giving in the edit text so that user can change it any time and generate the desired image.
how can i achieve this?
You can create a Bitmap of whatever size you want for your coupons:
Bitmap coupon = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Then you create a Canvas for drawing into the Bitmap:
Canvas canvas = new Canvas(coupon);
Draw your coupon using canvas with the same calls as you would when drawing to the screen. Finally, you can display the Bitmap on the screen either in a custom view's onDraw method or by creating an ImageView and calling it's setImageBitmap method with your coupon bitmap.
Related
I am currently using a View to trace the users fingers and draw lines depending on the color picked. I have set the background image using setBackGround() but I would now like to get the background + what the user user drawn into a variable. There exists getBackGround and getForeGround, not not both. How do I achieve this? I do not want to store the image locally on the persons phone.
The code used to achieve the tracing was used from this example and the setBackground was achieved by,
dv = new DrawingView(this);
dv.setBackground(imageview.getDrawable());
Where the imageview was defined and has data in it before.
You have to pass view(name of the view), Where a view is like a relativeLayout
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap returnedBitmap = view.getDrawingCache();
imageView.setImageBitmap(returnedBitmap);
Is there a way to add text to a bitmap with rotation and text customization, and them save the bitmap with text to the device storage. Also can this be applied to adding images to an image?
Just create a Canvas backed up by a Bitmap with new Canvas(myMutableBitmap) and do your text drawing in it. Then save the bitmap back with myMutableBitmap.compress().
I need to save a number of formatted circles to a Bitmap whenever a button is pushed, and then draw those circles to the canvas. I was looking around, but had a great deal of trouble finding resources on how to save a shape I had created that was not an already created resource file. Any advice on how to go about this would be appreciated.
Say you are in your custom view, but it should work also with a OnTouchListener in any view.
Create a mutable bitmap with Bitmap.createBitmap() with the same width and height of your view
use your logic for getting information of the circles, for example you can use onTouchEvent() to get the coordinates of you finger(s)
with this information you can use Bitmap.setPixel() to save it to the bitmap
optional, onDraw() you can draw your bitmap with Canvas.drawBitmap()
In case you need to draw shapes to the bitmap you can create a new Canvas(bitmap) and draw on this canvas: the pixels will be set on the bitmap.
I'm newbie with canvas.
I'm trying to draw child bitmap on parent bitmap using canvas.drawbitmap(childbitmap,matrix,point) method. I'm getting number of bitmaps using loop and trying to overlay image on all that bitmaps But somehow the output which I got haven't original child image. It looks like white image. so I'm able to seen child image on parent one but don't know why it looks like this?
Let me put my code over here with output image.
Canvas mCanvas = new Canvas(bitmap);
Paint p = new Paint();
Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(),
R.drawable.ic_launcher);
mCanvas.drawBitmap(icon,0,0,p);
This above code will run with loop and it will give multiple "bitmap" object on which I have to draw canvas. So now I'm taking launcher icon as child bitmap.while checking final output it shows like below image :
Check the white image instead of launcher icon.So what's wrong with my code?
Waiting for your best suggestion ASAP.
You are drawing your bitmap on top with the current canvas. So you have to call mCanvas.drawBitmap a second time to draw the foreground bitmap.
Is there a way to do it? I d like to save the canvas screen as a Bitmap object, and then draw it again, to the screen.
You can construct a Canvas passing in a Bitmap onto which the canvas will draw. See http://developer.android.com/reference/android/graphics/Canvas.html#Canvas(android.graphics.Bitmap)
You need to construct a Bitmap appropriately sized to the view into which you want to draw.
Just guessing here, but if you are doing this because you want to draw off screen then draw the bitmap on all at once you might also look at SurfaceHolder/SurfaceView.