android-canvas

Understanding Canvas and Surface concepts

人走茶凉 提交于 2019-12-17 06:20:46
问题 I'm struggling to understand the process of drawing to SurfaceView and therefore the whole Surface / Canvas / Bitmap system, which is used in Android. I've read all articles and API documentation pages, which I was able to find on android-developers site, a few tutorials of android graphics, LunarLander source code and this question. Please tell me, which of these statements are true, which are not, and why. Canvas has its own Bitmap attached to it. Surface has its own Canvas attached to it.

How to Measure TextView Height Based on Device Width and Font Size?

拈花ヽ惹草 提交于 2019-12-17 06:09:12
问题 I am looking for method in Android that will take a input (text, text_font_size, device_width) and based on these calculations it will return how much height will required to display particular text ? I am setting a text view/ webview height runtime based on his content,I am aware about warp content but I can't use in my case because of some web view minimum height issue. So I am trying to calculate height and based on that I am setting view height. I have tried with following ways Paint

MediaRecorder and VideoSource.SURFACE, stop failed: -1007 (a serious Android bug)

限于喜欢 提交于 2019-12-17 04:10:50
问题 I'm trying to record MediaRecorder without using Camera instance but using Surface video source (yes it's possible, but it turned out that it's not that perfect) - mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE); I just write what the issue: Next code works only on some devices and works temporary on some devices after a recent device rebooting or doesn't work at all If it doesn't work ok MediaRecorder.stop() method fails with the next error E/MediaRecorder: stop failed: -1007

Android canvas: draw transparent circle on image

*爱你&永不变心* 提交于 2019-12-17 03:50:29
问题 I am creating a pixel-hunting game. So my activity shows an ImageView. And I want to create a hint "show me where is the object". For this I need to blur whole image except a circle around a point where the object is located. Instead of blur I can show a just semitransparent black background. There is there is no problem to draw a semitransparent rectangle on the Canvas. But I don't know how to crop a transparent circle from it. The result should look like like this: Please help me to achieve

Android canvas draw rectangle

六月ゝ 毕业季﹏ 提交于 2019-12-17 03:24:14
问题 how to draw empty rectangle with etc. borderWidth=3 and borderColor=black and part within rectangle don't have content or color. Which function in Canvas to use void drawRect(float left, float top, float right, float bottom, Paint paint) void drawRect(RectF rect, Paint paint) void drawRect(Rect r, Paint paint) Thanks. I try this example Paint myPaint = new Paint(); myPaint.setColor(Color.rgb(0, 0, 0)); myPaint.setStrokeWidth(10); c.drawRect(100, 100, 200, 200, myPaint); It draws rectangle and

Draw an bitmap on a canvas with a custom shape

自闭症网瘾萝莉.ら 提交于 2019-12-14 03:57:08
问题 I want to draw an image with the following shape on a canvas: The black must be replaced by my image. I currently draw the image as a whole. I just don't know how I can get that sort of shape in it? canvas.drawBitmap(header,0,0,mPaint); Can someone help me? 回答1: Thanks to pskink I've got it: int width = this.getMeasuredWidth(); int height = this.getMeasuredHeight(); BitmapShader shader; shader = new BitmapShader(header, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); mPaint.setShader(shader);

Load bitmap into canvas and draw over it

天涯浪子 提交于 2019-12-14 00:41:47
问题 I like to make an app, something like a little paint, I have to get a bitmap, draw it on a canvas and next, draw over it (with figer)... So, I actually have this code: import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import android.content.Context; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.os.Environment; import android.util

Comparing pixel colors in a selected region

偶尔善良 提交于 2019-12-13 20:26:10
问题 canvas.drawCircle((float)(myMidPoint.x - myEyesDistance/2.0), myMidPoint.y, (float)30.0, myPaint); canvas.drawCircle((float)(myMidPoint.x + myEyesDistance/2.0), myMidPoint.y, (float)30.0, myPaint); The image shows the eyes detected using canvas. How to get the pixel colors in the circled region so that I can compare it with any preset values and tell whether eye is open or not? See the image in link. 来源: https://stackoverflow.com/questions/17779843/comparing-pixel-colors-in-a-selected-region

Android never call method onCreateThumbnail

点点圈 提交于 2019-12-13 20:22:13
问题 Based on Android documentation, method onCreateThumbnail is called before pausing the activity, and should draw into outBitmap the imagery for the desired thumbnail in the dimensions of that bitmap. It can use the given canvas , which is configured to draw into the bitmap, for rendering if desired. The default implementation returns fails and does not draw a thumbnail; this will result in the platform creating its own thumbnail if needed. When the method returns true , system will not use a

Android View.invalidate(Rect) different behavior between two devices

纵饮孤独 提交于 2019-12-13 16:28:15
问题 I have a custom view (a Waveform) that needs to be synchronized with a media player progress. The problem is that I'm having a different behavior when using invalidate(Rect) Here is the code that makes the update in my custom view: public void setProgress(int currentDuration) { // ... Some code to calculate the dirty width invalidate(mDirtyWidth,0,mDirtyWidth+ mDirtyWidthRegion, viewHeight); } This is working perfectly on a Samsung Galaxy 4 (Android 4.4.2). Screenshot with "Show GPU view