android-canvas

Android - Drawing to a PDF canvas from WebView

核能气质少年 提交于 2019-12-21 07:29:36
问题 I've been having troubles getting PDF printing work on Android. What I'm trying to do is render some HTML in WebView, then draw the WebView contents on a PDF canvas and finally write the PDF to a file. The problem I'm having is that when I draw to the PDF canvas the content gets clipped even though there is plenty of canvas left. I've tried resizing the canvas using the .clipRect(Rect rect, Op op) and that kind of worked but not as well as I would've liked. I also have no idea how I can

How to save objects previously drawn to the Canvas on a redraw?

久未见 提交于 2019-12-21 06:06:27
问题 Every time a SurfaceView is redrawn, things that were previously drawn are erased. How do I save their state so that my loop will add new objects to the screen without erasing the old ones? 回答1: Draw with a Bitmap : Bitmap mDrawBitmap; Canvas mBitmapCanvas; Paint mDrawPaint = new Paint(); @Override public void onDraw(Canvas canvas) { if (mDrawBitmap == null) { mDrawBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); mBitmapCanvas = new Canvas(mDrawBitmap); } //

[android]Circle with SweepGradient to animate

喜你入骨 提交于 2019-12-21 05:16:35
问题 Hi, I m trying to draw a circle as shown in the picture.where my values ranges from 0-100. 0-40 green 41-60 yellow 61-80 orange and 81-100 red. the view should animate from 0 to defined value slowly,this one to achieve. I have tried the following code ,and trying to achieve, code as follows: public class GradiantActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

onScale and Canvas - how to adjust origin point after zooming image?

淺唱寂寞╮ 提交于 2019-12-21 05:12:05
问题 I have a very simple test app with a custom component MyView.java - which displays a scrollable and scalable image (representing a board in a Scrabble-like word game): 1) In my scale listener I adjust the scale factor: public boolean onScale(ScaleGestureDetector detector) { mScale *= detector.getScaleFactor(); // XXX how to adjust mOffsetX and mOffsetY ? XXX constrainZoom(); constrainOffsets(); invalidate(); return true; } 2) And then in the drawing method of my custom component I apply the

How to save view from canvas to PNG file?

独自空忆成欢 提交于 2019-12-21 04:35:18
问题 I created canvas that can be used to draw some shapes on it. How can I save its content to PNG file on user's SD card? 回答1: check out this link this link In this link you can find the method void saveImage() { try { String filename = Environment.getExternalStorageDirectory().toString(); File f = new File(filename ,"myImage.png"); f.createNewFile(); System.out.println("file created " + f.toString()); FileOutputStream out = new FileOutputStream(f); Bitmap bitmap = showImage(urlStr); bitmap

Redraw multiple Paths at same positions from previous layout orientation

好久不见. 提交于 2019-12-21 04:21:55
问题 Based on my previous question of "How to create a BottomBar as StickyBottomCaptureLayout in camera2 Android api?", I created a layout with a StickyBar (SB) which is always locked above/near the system bar. I set the default positions and coordinates of the SB and the other layout in onLayout() (exactly as my answer). The upper layout is a simple custom DrawView which has an ArrayList of Path s drew by the user. When the device rotates, it recalls onDraw() and calls several times canvas

Canvas.drawText() doesn't render large emojis on Android

不羁的心 提交于 2019-12-21 04:12:55
问题 Canvas.drawText() doesn't render emojis above a certain font size on Android. Correct render at somewhere below 256 px: Incorrect render at above 256 px: (There is a similar question about Google Chrome, and just like Android, Chrome also uses the Skia graphics library, so this seems like a bug in Skia .) Apparently emojis fail to render above 256 px font size on my devices. But I'm not sure if this is the limit everywhere. Is there a way to learn the font size at which emojis disappear? Or

Android: invalidate(dirty)

不问归期 提交于 2019-12-20 20:32:03
问题 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

Freehand Image Crop draw inside bitmap region

北战南征 提交于 2019-12-20 14:39:07
问题 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

android fast pixel access and manipulation

你说的曾经没有我的故事 提交于 2019-12-20 12:43:12
问题 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