android-canvas

Custom Font not working on Android

纵然是瞬间 提交于 2019-12-01 12:47:38
I am doing the below. All I get is the basic font, not my custom symbol font. Any ideas? Paint pnt = new Paint(); // SymbolNo is 38. Returns string "&" which is correct in normal font. String symbolText = Character.toString((char)SymbolNo); // Should adopt a symbol font and draw symbol to screen instead. But I just see "&" Typeface tf = Typeface.createFromAsset(m_context.getAssets(), "fonts/myFont.TTF" ); pnt.setTypeface(tf); m_canvas.drawText(symbolText,x, y, pnt); my font is in assets/fonts/myFont.TTF Not every font works with Android. It just silently fails. One course of action is to find

canvas is offset by setting identity matrix in onDraw of custom view

故事扮演 提交于 2019-12-01 12:32:42
I set a matrix to my canvas in the onDraw method of a custom view via canvas.setMatrix(matrix); then I just draw a grid using predefined paints: canvas.drawRect(0,0,viewWidth,viewHeight, background); for(int i=0; i <= nRows; i++){ canvas.drawLine(0,i*cellHeight, nCols*cellWidth,i*cellHeight,lines); canvas.drawLine(i*cellWidth, 0, i*cellWidth, nRows*cellHeight, lines); if(i != nRows) canvas.drawText(""+i, i*cellWidth, (i+1)*cellHeight, text); } and for some reason the whole canvas is offset by about 1.5 times the height of a cell. Any idea why this is happening or how to fix it? The matrix was

onOffsetsChanged: move Bitmap

时光毁灭记忆、已成空白 提交于 2019-12-01 11:25:23
i want my Bitmap that has the height of the screen and has a bigger width than the screen to be moved a little bit to the right or left if the user changes the desktop so he can see the entire image. Here is my code that just works partially: int x = -1*(int)((xOffset*bmp.getWidth())); canvas.drawBitmap(bmp, x, 0, null); thank you! George Freeman You get exact pixel values via the variables xPixels and yPixels in onOffsetsChanged(). See my answer here: android live wallpaper rescaling For example, in onOffsetsChanged(), you can set a private class variable mPixels = xPixels; Then, in your draw

Android View inflateException

杀马特。学长 韩版系。学妹 提交于 2019-12-01 11:17:57
I'm trying to create a custom view - finger paint, and I'm having trouble with this error and I don't know how to fix it. Can anybody tell me what is wrong? LogCat: 08-04 08:34:01.171: E/AndroidRuntime(15664): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.boenka.mk/com.boenka.mk.Draw}: android.view.InflateException: Binary XML file line #9: Error inflating class com.boenka.mk.DrawPanel 08-04 08:34:01.171: E/AndroidRuntime(15664): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 08-04 08:34:01.171: E/AndroidRuntime(15664): at android.app

Animate rotation of an image in Android

与世无争的帅哥 提交于 2019-12-01 10:40:57
I have a gear image which I want to continuously rotate about a fixed point. Earlier I was accomplishing this by including the image in my Android class as an ImageView and applying a RotateAnimation to it. @InjectView(R.id.gear00) ImageView gear00; RotateAnimation ra07 = new RotateAnimation(0, 359, 129, 186); ra07.setDuration(10000); ra07.setRepeatCount(RotateAnimation.INFINITE); ra07.setInterpolator(new LinearInterpolator()); gear00.setAnimation(ra07); Basically, I was injecting the ImageView into the class and applying a rotation animation. However, I dont have the luxury of using an

ColorPicker in android not working

走远了吗. 提交于 2019-12-01 09:26:25
I have made a simple drawing android program for learning ,I have put a colorDialog which is displayed properly bu after selecting any color ,The pen color is not changing ,It still remains "black" the default color.I have tried as below,Please help me for it,My code is as below: Main.java package com.example.singletouch; import java.util.AbstractMap; import java.util.Map; import java.util.concurrent.ConcurrentLinkedQueue; import com.example.singletouch.SingleTouchView.DrawingPens; import android.os.Bundle; import android.app.ActionBar.LayoutParams; import android.app.Activity; import android

How to overlay bitmap over another bitmap at particular XY position

我的未来我决定 提交于 2019-12-01 09:21:26
问题 I am working on a project where I have used canvas and user can touch move one bitmap overlay to another bitmap. When user presses save button then both bitmaps should merge and become a single bitmap. I have done all things and now merging two bitmap at XY position remains. During my research I found following code. private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) { Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); Canvas canvas = new Canvas

onOffsetsChanged: move Bitmap

拈花ヽ惹草 提交于 2019-12-01 07:57:04
问题 i want my Bitmap that has the height of the screen and has a bigger width than the screen to be moved a little bit to the right or left if the user changes the desktop so he can see the entire image. Here is my code that just works partially: int x = -1*(int)((xOffset*bmp.getWidth())); canvas.drawBitmap(bmp, x, 0, null); thank you! 回答1: You get exact pixel values via the variables xPixels and yPixels in onOffsetsChanged(). See my answer here: android live wallpaper rescaling For example, in

Android View inflateException

旧时模样 提交于 2019-12-01 07:40:11
问题 I'm trying to create a custom view - finger paint, and I'm having trouble with this error and I don't know how to fix it. Can anybody tell me what is wrong? LogCat: 08-04 08:34:01.171: E/AndroidRuntime(15664): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.boenka.mk/com.boenka.mk.Draw}: android.view.InflateException: Binary XML file line #9: Error inflating class com.boenka.mk.DrawPanel 08-04 08:34:01.171: E/AndroidRuntime(15664): at android.app.ActivityThread

How to draw a bitmap on a canvas, respecting alpha values of the bitmap?

点点圈 提交于 2019-12-01 06:40:36
background i have a master bitmap that i need to draw on it other bitmaps. the master bitmap has some semi-transparent pixels (pixels with variant values for the alpha channel) , so that the other bitmaps that are drawn on it should be merged with it instead of overriding the colors completely. the question how can i set the canvas to draw the bitmaps on the master bitmap with respect to the semi-transparent pixels ? note: the alpha is not for the whole bitmap/s . it's per pixel. Canvas.setXfermode(Xfermode xfermode) . There are a number of Xfermode s you can choose. Desmond Yao public void