nativescript-community / nativescript-community/ui-canvas
Getting image from canvas.
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 38
- Forks
- 9
- PR merge metrics
- No merged PRs in 30d
Description
Make sure to check the demo app(s) for sample usage
I checked all examples specially Complex.vue and canvastests.ts but can't make it work.
If the demo apps cannot help and there is no issue for your problem, tell us about it
Please, ensure your title is less than 63 characters long and starts with a capital
letter.
Calling canvas.getImage() returns "undefined" on draw method
Which platform(s) does your issue occur on?
-Android
- emulator
Please, provide the following version numbers that your issue occurs with:
- NS version: 8.5.3
- Cross-platform modules: (check the 'version' attribute in the
node_modules/tns-core-modules/package.jsonfile in your project) - android 8.5.0
- "dependencies": {
"@nativescript-community/ui-canvas": "^4.6.12",
"@nativescript/camera": "^5.1.0",
"@nativescript/core": "~8.5.0",
"@nativescript/theme": "~3.0.2",
"nativescript-camera": "^4.5.0",
"nativescript-material-loading-indicator": "^1.0.0",
"nativescript-photo-editor": "file:../nativescript-photo-editor",
"nativescript-vue": "~2.9.3"
},
"devDependencies": {
"@nativescript/android": "8.5.0",
"@nativescript/ios": "8.5.2",
"@nativescript/preview-cli": "1.0.2",
"@nativescript/webpack": "~5.0.14",
"nativescript-vue-template-compiler": "~2.9.3"
}
Please, tell us how to recreate the issue in as much detail as possible.
I'm trying to use a canvas to base on someone clicking a pen they will be able to draw on top of an image.
When calling canvas.getImage() I'm getting as a response "undefined" when using it on draw() Method.
I've been trying to look at examples with getting the canvas and saving the image but I was unable to achieve this.
I was able to get the value from canvas.getImage() If I duplicate the code creating a new canvas object and copying exactly what the event.canvas does(see example below)
I made this small example when drawing a simple text in case it was my other code but this happens here as well. The canvas.getImage() returns "undefined"
Is there any code involved?
<CanvasView ref="canvas" width="50%" height="50%" @draw="onDraw" @touch="onTouch" />
onDraw(event) {
try {
const canvas = event.canvas;
const textPaint = new Paint();
textPaint.color = new Color('red');
textPaint.setStrokeWidth(3);
textPaint.setAntiAlias(true);
canvas.drawBitmap(this.image, null, createRect(0, 0, canvas.getWidth(), canvas.getHeight()), null);
canvas.drawText('Filled Text', 20, 20, textPaint);
canvas.getImage();
//Returns undefined
let newCanvas = new Canvas(canvas.getWidth(), canvas.getHeight());
newCanvas.drawBitmap(this.image, null, createRect(0, 0, canvas.getWidth(), canvas.getHeight()), null);
newCanvas.drawText('Filled Text', 60, 0, textPaint);
newCanvas.getImage();
// Returns bitmap image - Works but not ideal!
} catch (error) {
console.log(error);
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the CanvasView draw event in the reported onDraw method and compare its event.canvas behavior with the separately created Canvas. Review Complex.vue and canvastests.ts for the intended getImage usage, then reproduce the Android case with the listed NativeScript and @nativescript-community/ui-canvas versions. Done means the reported draw-time call has a defined image result consistent with the documented behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, typescript
- Domain
- computer-graphics, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100