android-canvas

android: convert canvas to bitmap then save to SD card

早过忘川 提交于 2019-12-04 05:28:58
问题 i'm developing an android app where I can draw on a canvas. I want to convert my canvas to bitmap and then save it in jpeg format on my sd card.. how can i properly do this? 回答1: Something like that should work : http://developer.android.com/reference/android/view/View.html#getDrawingCache(boolean) public void toJPEGFile(){ File folder = new File(Environment.getExternalStorageDirectory()+"/folder/"); if(!folder.exists()) folder.mkdirs(); try { this.setDrawingCacheEnabled(true);

Android How to create onClick events in Canvas onDraw method

拜拜、爱过 提交于 2019-12-04 05:16:21
问题 i've searched around and still can't find a good answer. I have made my own class that extends an imageView and in the onDraw() method i am using canvas to draw circles onto my image. What i want to do now though is draw a button onto the image in different places and have an onClick event for it, so when the user presses the button it will open up a new activity.. Here is what I have so far..It draws the buttons in the right locations except my onClick method isn't firing @Override protected

Show marker inside a resource drawable which obtained from url

瘦欲@ 提交于 2019-12-04 04:26:05
Here is the map page I have, which shows all the users of my App. Also the images(markers) are obtained from the URL given from my server. These markers has to put inside a Drawable(a circle like image as shown). I created a circle like Bitmap from the url using Canvas. public Drawable showMe(String url) { Bitmap bitmap=null; try { URL newurl = new URL(url); bitmap = BitmapFactory.decodeStream(newurl.openConnection().getInputStream()); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e

Camera onPreviewFrame not called on some devices

荒凉一梦 提交于 2019-12-04 03:20:52
I am expecting the LogCat to be logging #onPreviewFrame() multiple times, but it only works on selected devices like: Samsung Galaxy S6 (7.0) Samsung Galaxy S6 (6.0.1) LG Leon (5.0.1) But does not on the following devices: LG G4 (6.0) Huawei 6X (7.0) Nexus 6P (7.0) Below is the code snippet: public CameraSurfaceView(Context context, AttributeSet set) { super(context, set); Log.d(TAG, "CameraSurfaceView(context, set)"); // Get the Surface Holder this.holder = this.getHolder(); this.holder.addCallback(this); this.holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); } @Override public void

Android canvas save always java.io.IOException: open failed: ENOENT (No such file or directory)

倾然丶 夕夏残阳落幕 提交于 2019-12-04 03:00:47
I have a canvas application. I'm trying to create a signature app with Canvas + onTouchListener . This is my save method, where I try to save the signature to an image: private void save() { hideMenuBar(); View content = this; content.setDrawingCacheEnabled(true); content.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); Bitmap bitmap = content.getDrawingCache(); String path = Environment.getExternalStorageDirectory().getAbsolutePath(); String imgPath = path+"/imotax/capture/spop/ttd/image" + "temp" + ".jpg"; File file = new File(imgPath); FileOutputStream ostream; try { file

Find exact coordinates of a single Character inside a TextView

为君一笑 提交于 2019-12-04 02:51:51
Currently I'm using paintObject.measureText(textCopy.substring(0,i)) while iterating through a copy of the TextView's text. For example, measureText("abc".substring(0,1)) will give me the relative x coordinates of 'b'. The y coordinate I get from layout.getLineTop() . This is working but not accurate for x coordinates for non-monospaced fonts. I can calibrate a little, but on each device it works differently. The best solution I can think of is to overwrite the class that is responsible for drawing the TextView on the screen and, hopefully, get the coordinates of each character drawn to screen

Getting Bitmap from Custom SurfaceView

可紊 提交于 2019-12-04 02:45:51
I have this code in a class that extends surface view and implements runnable I am able to use the class basically allows you to draw to the canvas using different colors and such. I'm trying to get a method that will allow me to save the image after it is drawn and this is the method. No matter what i do i just get a black image with nothing on it. Any ideas? I have cache drawing enabled Objective get a bitmap image from a custom SurfaceView I have exhausted options of looking at some other post on here and didn't find anything to work. Here is hoping that there is recently a new solution to

Triangle shaped ImageView with drag, scroll & zoom onTouch Android

牧云@^-^@ 提交于 2019-12-04 01:52:41
问题 I've added three different bitmap to one ImageView as shown in picture below. But the problem is that I cannot edit it after the Bitmap is set to ImageView . I want to drag, scroll & zoom the individual Bitmap in the ImageView . My code for getting the combined bitmap is: Bitmap setBitmapInTriangleShape(Bitmap bitmap1, Bitmap bitmap2, Bitmap bitmap3) { /* * int[] values= new int[2]; mImageView.getLocationOnScreen(values); */ double screenHeightAspect = 2.5; Bitmap drawnBitmap = null; bitmap1

Simple thread issue with Android animation

本秂侑毒 提交于 2019-12-04 01:35:01
问题 I'm trying to implement a thread with some simple Android animation. I'm just getting an error with sleep() - It says I need a method for it. I know there is probably an obvious solution. My app just places a ball that moves in a circle at a random location. What I want is to continue placing shapes at random locations. Anyway, can someone please tell what I'm doing wrong with my thread? Thanks. public class DrawingTheBall extends View { Bitmap bball; Random randX, randY; double theta;

How to fill rectangle with opacity in android

好久不见. 提交于 2019-12-04 00:27:39
I can fill rectangle with canvas draw rect: Rect rt = new Rect(0, 0, getWidth(), getHeight()); myPaint.setColor(myColor); myPaint.setStyle(Style.FILL); canvas.drawRect(rt, myPaint); But I need the method to fill rectangle with the opacity (in percent, with 0% is TRANSPARENT). How can I do that? Mohammed Azharuddin Shaikh You can use the Alpha property of Paint class . myPaint.setAlpha(10); will help you. 来源: https://stackoverflow.com/questions/10348084/how-to-fill-rectangle-with-opacity-in-android