Comments (1)
First customize the drawing object and implement the drawing behavior inside it:
import 'dart:ui' as ui;
/// Custom drawn image
/// url: https://web-strapi.mrmilu.com/uploads/flutter_logo_470e9f7491.png
const String _imageUrl = 'https://web-strapi.mrmilu.com/uploads/flutter_logo_470e9f7491.png';
class ImageContent extends PaintContent {
ImageContent(this.image, {this.imageUrl = ''});
ImageContent.data({
required this.startPoint,
required this.size,
required this.image,
required this.imageUrl,
required Paint paint,
}) : super.paint(paint);
factory ImageContent.fromJson(Map<String, dynamic> data) {
return ImageContent.data(
startPoint: jsonToOffset(data['startPoint'] as Map<String, dynamic>),
size: jsonToOffset(data['size'] as Map<String, dynamic>),
imageUrl: data['imageUrl'] as String,
image: data['image'] as ui.Image,
paint: jsonToPaint(data['paint'] as Map<String, dynamic>),
);
}
Offset startPoint = Offset.zero;
Offset size = Offset.zero;
final String imageUrl;
final ui.Image image;
@override
void startDraw(Offset startPoint) => this.startPoint = startPoint;
@override
void drawing(Offset nowPoint) => size = nowPoint - startPoint;
@override
void draw(Canvas canvas, Size size, bool deeper) {
final Rect rect = Rect.fromPoints(startPoint, startPoint + this.size);
paintImage(canvas: canvas, rect: rect, image: image, fit: BoxFit.fill);
}
@override
ImageContent copy() => ImageContent(image);
@override
Map<String, dynamic> toContentJson() {
return <String, dynamic>{
'startPoint': startPoint.toJson(),
'size': size.toJson(),
'imageUrl': imageUrl,
'paint': paint.toJson(),
};
}
}
Convert image:
Future<ui.Image> _getImage(String path) async {
final Completer<ImageInfo> completer = Completer<ImageInfo>();
final NetworkImage img = NetworkImage(path);
img.resolve(ImageConfiguration.empty).addListener(
ImageStreamListener((ImageInfo info, _) {
completer.complete(info);
}),
);
final ImageInfo imageInfo = await completer.future;
return imageInfo.image;
}
Set it to controller:
_drawingController.setPaintContent(ImageContent(
await _getImage(_imageUrl),
imageUrl: _imageUrl,
));
Then draw on the drawing board:
Complete code:main.dart
from flutter_drawing_board.
Related Issues (20)
- Support insert text ? HOT 2
- 请教一下如何设置才能把画板弄成全屏而不是居中呢? HOT 3
- Load drawing content of Eraser type not work
- How can I move the background image with a left click? HOT 1
- support addListener HOT 1
- support pan & zoom control HOT 1
- support canRedo / canUndo / canClear HOT 4
- How to make the controller stop drawing? HOT 1
- Select & edit shape support HOT 2
- One-finger smudge and two-finger zoom work fine, but more than three fingers cause the smudge gesture to fail[Discussions] HOT 1
- [How to use] How to get view drawn call back like view drawing started completed etc HOT 2
- [Bug report] can't draw in some cases, because of the false finger count
- [Discussions] When I try to save the file and trigger `_getImageData()`, the `data` always turns out to be null HOT 2
- How to convert to String HOT 1
- [Bug report] HOT 2
- [Feature request] Fix the canvas HOT 3
- [Feature request] Should have a function to reset the canvas to its initial size and position. HOT 1
- Export to PDF or SVG
- 工具栏目怎样浮动到画板上 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_drawing_board.