The task is following:
To draw parts of some bitmap only behind a path (user draws path using his finger). It must look like the user draws this bitmap by his finger. It is similar to task: erasing some picture by finger, but the approach should be different.
I know it is possible with OpenGL, but at first i am looking for more light option with standard android canvas and view drawing.
I have seen the example FingerPaint in APIDemos (please, do not refer me to it).
I am interested in somebody's real experience of implementing this task, or any other info, links or code, which can help.
Thanks.
You say to not refer you to FingerPaint, but have you considered that this sample may indeed hold the answer?
You could adapt it to two views on top of each other... your hidden image underneath and the fingerpaint view acting as a mask on top. You "paint" with the colour 0x00000000, i.e. total transparency, thereby revealing the image in the view underneath.
Related
I'm new to android development so I have this novice question here:
I have a Canvas View, customized, in an activity. I want to programmatically display images (PNG drawables).
Clearly I have 2 ways of doing this, the first, more conventional way is:
Option I:
Find the "Activity Layout" (the layout for the entire activity)
Set params for the PNG ImageView.
ActivityLayout.addView(pngImageView)
Edit: So this way, the PNG will be shown, but not really "a part of" the Canvas, as it is not really drawn "in" the Canvas, but on top of it but to users, it's impossible to tell.
Option II:
Use a Drawable object, set its resource to my desired PNG drawable, then call
Drawable.draw(myCanvas)
Edit: In this way, the drawable will be "a part of" the Canvas and actually drawn "in" it. But then again, the users wouldn't be able to tell it from the first option.
Would I be better off with Option II? Particularly, I want to manipulate the png drawable, flip it, rotate it etc. probably using Matrix.
Thanks in advance!
Edit: I want as little hassle as possible, and I want to be able to export the entire canvas to bmp file in the future including everything on the canvas and the png drawable.
The differences is that the canvas drawing is done by hardware acceleration (GPU), and the Dynamic drawing is done by software (CPU). If you disable hardware acceleration, they become the exact same.I am not sure which one is the more accurate, they seem like just different implementations.
Hello friends!
I need to create a photo editor, which allow to put the emoticons, text and drawing with a brush on the picture.
Open the illustration
An editor must be able to change the position of smiles & text, their size and rotation with two fingers (multi-touch).
Mechanics is clear to me. I found ready realization of multi-controller:
https://github.com/lukehutch/android-multitouch-controller
But I don't understand how better visualize all the layers in terms of performance:
Layer 3 - text
Layer 2 - emoticons
Layer 1 - drawing
Layer 0 - photo
I am afraid to use the canvas, without your opinion. I heard that the canvas buggy when displaying a large number of images.
I found examples visualize the layers of images using layer-list with the 's inside. I think this method will be more performance numbers for my task.
But I have not found documentation of how to update the position (top / left) when you move an item.
My question is: What is the best use for the visualization of all layers and the possibility to save the final image (merge all layers)?
Please help, what to choose and what is the right path!
Thank you in advance! :)
Canvas is not buggy. It's the only way for you to render things onto a Bitmap. By the looks of your requirement, I think you need to draw your Layers onto different bitmaps. Layer 0 will be your default bitmap. Every other layer will be individual bitmaps on their own. The reason they have to be on a bitmap of their own is so that you can move them as you wish.
You final merge will be to draw all these bitmaps, on the default bitmap via Canvas.drawBitmap() call.
I'm developing an android app in which I want to integrate a feature using which user can take screenshot, doodle something on it and then send it via mail.
How to implement this? I just need a pen for doodling and an eraser to erase last doodle.
Take a look at this library :
ActiveDoodle
You can display two ImageViews on top of each other: the bottom one containing the photo, the top one containing an initially transparent Bitmap. In the top ImageView's onTouchEvent() method you can transform touch events into strokes of pen applied to the bitmap using a Canvas. You might want to read up on MotionEvents and Canvases.
After the user is done with doodling, you can load the screenshot to a Bitmap, rescale the doodle bitmap to match the screenshot's size, and draw in on top, again using a Canvas. Reading about Porter/Duff algebra will probably prove useful with applying an XferMode to a Paint.
on a canvas is it possible to draw text but make half of it not show up (as if it is being drawn partially off of the canvas, but actually not being off the canvas). i have an indicator on a "graph" with some text and it follows the point but I do not want the text to be drawn out of the graph portion (i am drawing other stuff outside that area).
I also have a background on the layout behind the canvas so I cannot just paint with a bitmap because that would cause some aspect ratio/sizing issues (wouldn't look good).
I have tried looking for answers all over Google, Stack overflow, and by experimentation with no avail. On Google I found many interesting things about drawing text on an android canvas but nothing that I was looking fore, I am pretty stumped, and I am starting to think that what I want is not even possible, and i may need to draw the text custom with points or figure out an alternative that looks just as good.
It's absolutely possible. Probably the fastest is to use clipRect to limit drawing to your graph portion. See this answer: Using clipRect - explanation
The reference on the various forms of clipRect is here: http://developer.android.com/reference/android/graphics/Canvas.html#clipRect(android.graphics.Rect, android.graphics.Region.Op)
If I recall, the whole operation will look something like:
yourCanves.save()
yourCanvas.clipRect(...)
yourCanvas.drawText(...)
yourCanvas.restore()
The restore() call serves to undo the clipRect so you can draw outside it for later drawing.
The simplest solution that popped in my mind, would be to cut using substring the text that you want to dispaly.
Example:
if(MyString >5){
canvas.drawText("VeryLongTe...");
}
easy now.
What I want eventually:
I want to have 2 bitmaps overlayed on a view. Same bitmaps with the one above have higher brightness than the below one.
Now when the user strokes(with touch event (like paint brush)) on the upper bitmap, I want those parts of the upper bitmap to go invisible.
For those who are familiar with adobe photoshop perhaps this will make more sense:
I want to draw a mask on an image being display so that only the unmasked parts remain visible. But the mask can be drawn from a brush with variable hardness/size.
How do I achieve this functionality? Direct me in in the line where I should research or give sample code.
Also, is it possible to draw strokes on an imageview with a brush which has variable hardness? I know that I can drawPath and drawArc on a canvas, but I do not know how to achieve the different brush strokes/styles.
Please pardon me if I haven't phrased my question right, or wasn't able to find similar duplicates.
You can use FrameLayout to overlay one image over other in Android and for Custom Masking search FingerPaint on google.
I think the best way is to do your own off-screen compositing, then render the composited image using an ImageView or perhaps a subclass with custom interaction. See this sample code for an example of how to do such compositing using the Porter-Duff transfer modes.