I have an SVG file format in which there is 5-6 icon and I need to pick icon according to the requirement not the whole Image.
In Simply you can parse the .SVG onto your ImageView Or Canvas but this time I need to choose particular icon from the among.
Is this possible to do with the coding or i need to draw all icon separately ?
Somebody suggest me the way, how to make it happen ?
I did not try it but you may :
Create a Bitmap with the size of your icon
Create a new Canvas associated to this Bitmap
Draw your svg into the Canvas with an offset
-- If your icon coordinates are (X1, Y1)
-- Then when you draw an element substract SVG (X1, Y1)
Draw the Bitmap on screen.
It is a little bit homemade solution... maybe there is some libraries doing those king of things for you.
You could set a clip and translation on the canvas before drawing to hide all but the icon you want, but I think the best course of action is to use separate image files.
You don't say which SVG library you are using. If you are using AndroidSVG, you could add <view> elements to your SVG (one for each icon) and select the appropriate icon to draw using renderViewToPicture() etc.
Related
Hi,
I'm trying to understand how to make custom view (with green background) on Android like represented on attached image. Please suggest, should I use Path for this or something else?
A good starting point would be http://tips.androidhive.info/2013/09/android-layout-rounded-corner-border/ . Then you can play with the attribute values to get the desired background. Hope this helps.
You have two good options for accomplishing this.
Bitmap
Create the desired image in Photoshop, Gimp or something similar. Export it as a png file then import it as a bitmap resource into your Android application.
This is by far the simpler and faster of the two methods, but here are two significant problems. First, you should supply bitmaps for each screen density bucket. Second, each bitmap resource you add increases the install size of your app. This can get out of hand quickly.
Path
As you mentioned in your question, you can draw the desired shape directly onto a canvas using a Path. More specifically, you'll use the cubicTo() method to create bezier curves.
I recommend using your image editor's "path" tool to learn how the control points affect the curve. Once you've drawn the shape in the image editor, write down the coordinates for every point on your path as well as the corresponding control points. Then do a little math to convert the points to ratios of the image's overall width and height.
You can implement the shape in your app as a View or as a Drawable. In either case, you'll be drawing to a Canvas. The important step will be to set up the path by multiplying the ratios with the size of your drawing area. After you draw the fancy edge, be sure to draw the straight edges via lineTo() and to close the shape with close().
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.
Is there a way to use vector graphics to be google maps marker? I know that google maps takes a bitmap for a marker, but I have a vector graphics (coming from server) and I am not sure how to display that as marker?
Thank you
Technically, if you are able to render your vector image as a Drawable, you can use it as a map marker. Vector drawables on Android are complicated but maybe you already solved that problem.
You need to programmatically create a writable Bitmap with the desired size (specify your constant size in dips to adjust it to the screen density), create a Canvas based on that Bitmap, set the bounds on your Drawable then draw it on the Canvas. Your Bitmap will then contain the rendering of your Drawable and you can create a Marker from it.
but I have a vector graphics file and I am not sure how to achieve that?
Open it in your vector drawing app and export as bitmap (PNG) to use on Android. This is the less painful way than anything else.
I want to crop an image in alphabet(A-Z,0-9) in Andorid any idea ?
Here is an example of what I am looking for Cut out image in shape of text
but he uses java's awt api(I am looking for Android) also it is too slow.
After some googling and reading android docs found that we can specified drawing area for canvas using canvas.clipPath(path) then I can draw a rectangular image on canvas and image will only be visible that is drawn in clipped area,hopefully :)
So now I can crop image in small rectangle and draw rectangle on Text path is it possible to get Outline of an Alphabet for given font ?
On Android you should be able to do that very easily by using a BitmapShader.
Instantiate your BitmapShader.
Instantiate a Paint, and call setShader(bitmapShader).
Draw text with Canvas.drawText("Cat", x,y, paint).
I have a bitmap image that is of irregular shape that I fill with a certain color to simulate a "meter" of sorts. My current method uses a ColorMatrixColorFilter to replace color on the original bimtap, up to a percentage by bitmap height. What I'd really like to do is replace the color by volume.
You could draw a filled bitmap overtop of the unfilled one, but use a clipping path based on the meter's level. If that can be done with a rectangular clip, it will be quite straightforward with Canvas.clipRect(float,float,float,float). Otherwise, you may have to specify a more general path and use Canvas.clipPath(Path). However, the clipPath is not anti-aliased, so it can look a bit lousy.
Another option is to draw the overlay directly with a custom Path, possibly using SVG path primitives for convenience. See this project: http://code.google.com/p/svg-android/ and specifically this method: http://svg-android.googlecode.com/svn/trunk/svgandroid/docs/com/larvalabs/svgandroid/SVGParser.html#parsePath(java.lang.String).