android-canvas

How to create a square bitmap from a rectangular bitmap in Android

有些话、适合烂在心里 提交于 2019-12-03 07:51:36
Basically, I have a rectangular bitmap and want to create a new Bitmap with squared dimensions which will contain the rectangular bitmap inside of it. So, for example, if the source bitmap has width:100 and height:400, I want a new bitmap with width:400 and height:400. Then, draw the source bitmap centered inside of this new bitmap (see attached image for a better understanding). My code below creates the square bitmap fine, but the source bitmap is not being drawn into it. As a result, I'm left with a bitmap that is completely black. Here is the code: Bitmap sourceBitmap = BitmapFactory

Infinite scroll of finite items

浪子不回头ぞ 提交于 2019-12-03 07:11:46
问题 I have a GridView that has items inside 5x50. I need to scroll them in all directions and instead of stopping when reached the end just start from the top/left. for example left-to-right scroll before scroll 1 2 3 4 5 6 7 8 9 10 after scroll to the right 5 1 2 3 4 10 6 7 8 9 and for top-to-bottom (or bottom-to-top) before scroll to the bottom 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 after scroll 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 I try to make it smooth scroll as GridView native scroll. 回答1: Here

Android: invalidate(dirty)

╄→尐↘猪︶ㄣ 提交于 2019-12-03 06:36:30
It seems like Android really doesn't like invalidate (Rect dirty) , which is used to invalidate only part of a canvas. When I invalidate part of a canvas (shown in green below) and a ToggleButton outside of the canvas needs to be redrawn at the same time, the entire region shown in red is erased! It seems as though Android is just invalidating everything within the smallest rectangle encompassing the union of the two regions that need to be redrawn, even if one of the regions is outside of the View whose canvas I'm invalidating. Is this standard behaviour, and if so, why would anyone use

How to rotate TextView without clipping its bounds?

﹥>﹥吖頭↗ 提交于 2019-12-03 06:21:21
I'm trying to rotate my subclass of TextView using canvas.rotate() : canvas.save(); final int w = getWidth(); final int h = getHeight(); float px = w/2f; float py = h/2f; canvas.rotate(mAngle, px, py); super.draw(canvas); canvas.restore(); TextView is rotated, however bounds of my view are clipped: I understand that this is because of my view's size - it is not changed during rotation while it should. But if I'll change width\height in onMeasure problem will remain - I'm using LayoutParams.WRAP_CONTENT , so TextView just change it's size according to values provided in setMeasuredDimensions .

GL error from OpenGLRenderer: 0x502

限于喜欢 提交于 2019-12-03 06:18:16
问题 Our code is performing very simple operations on a Canvas (entirely in UI thread): drawText, translate, save, restore. Occasionally, we get this (on Nexus 4 running 4.3): W/Adreno200-ES20(22118): <gl_draw_error_checks:550>: GL_INVALID_OPERATION D/OpenGLRenderer(22118): GL error from OpenGLRenderer: 0x502 E/OpenGLRenderer(22118): GL_INVALID_OPERATION and the corresponding text is not drawn to the canvas. One problem is that it happens randomly. The code will work without error for maybe 10-20

Capture Image while Device is Locked with Password

 ̄綄美尐妖づ 提交于 2019-12-03 06:06:54
问题 I want to implement a functionality to capture image through front camera when someone tries to unlock my device and enter incorrect password 3 times. I checked that it is possible in Android and some applications are also available in Market. I have done some work to achieve this but I am getting a black Image. Here's the code : Register with Device admin to get the broadcast for incorrect password attempt : public class DeviceAdminSample extends DeviceAdminReceiver { static Context ctx;

Slow App with Background image

拜拜、爱过 提交于 2019-12-03 05:34:09
问题 I am making a small game for android. It is working smoothly when its working on a white background but when i want to put a background image, its becoming slower and slower. First i tried to add it as a layout background image but it was very slow, the animations were happening frame by frame. And then i decided to draw the background image as a Bitmap on canvas, the result was a little faster than the previous one but still its nothing comparing to the white background. I tried to scale the

Custom Button Background with diagonal Cutting View

a 夏天 提交于 2019-12-03 05:11:27
问题 I want to set background as shown in image i have tried many tutorial for example https://medium.com/@adinugroho/create-diagonal-cut-view-in-android-5a376eca6a1c https://github.com/florent37/DiagonalLayout but not getting proper result,can anyone help me to get perfect result. Thanks in Advance. 回答1: UPDATED ANSWER Please do note that you may need to tweak the width and height of the Button to make it work for you. You can do this with vector and layer-list drawables. diagonal_shape <vector

android fast pixel access and manipulation

馋奶兔 提交于 2019-12-03 03:45:16
I'm trying to port an emulator that i have written in java to android. Things have been going nicely, I was able to port most of my codes with minor changes however due to how emulation works, I need to render image at pixel level. As for desktop java I use int[] pixelsA = ((DataBufferInt) src.getRaster().getDataBuffer()).getData(); which allow me to get the reference to the pixel buffer and update it on the fly(minimize object creations) Currently this is what my emulator for android does for every frame @Override public void onDraw(Canvas canvas) { buffer = Bitmap.createBitmap(pixelsA, 256,

Freehand Image Crop draw inside bitmap region

醉酒当歌 提交于 2019-12-03 03:03:12
Trying to achieve freehand cropping of an image, so I'm able to draw on the image. But it goes outside bitmap region. I just wanna restrict that user can only draw inside bitmap region, check below screen shot. I am trying to implement functionality like Photoshop lasso tool . Its drawing outside view region, which generates incorrect output. Output Code@ onDraw public void onDraw(Canvas canvas) { final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); canvas.drawBitmap(bitmap, rect, rect, null); // RectF r = new RectF(); // Matrix matrix = new Matrix(); // matrix.mapRect(r);