Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
E
esc_pos_print_plus
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dio Maulana
esc_pos_print_plus
Commits
ee7610bc
Commit
ee7610bc
authored
Sep 02, 2019
by
Andrey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added new printImage method using ESC * command
parent
7b9f912d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
2 deletions
+61
-2
printer.dart
lib/src/printer.dart
+61
-2
No files found.
lib/src/printer.dart
View file @
ee7610bc
...
@@ -315,10 +315,10 @@ class Printer {
...
@@ -315,10 +315,10 @@ class Printer {
return
res
;
return
res
;
}
}
/// Print image
/// Print image
using GS v 0 (obsolete command)
///
///
/// [image] is an instanse of class from [Image library](https://pub.dev/packages/image)
/// [image] is an instanse of class from [Image library](https://pub.dev/packages/image)
void
printImage
(
Image
image
)
{
void
printImage
Raster
(
Image
image
)
{
const
bool
highDensityHorizontal
=
true
;
const
bool
highDensityHorizontal
=
true
;
const
bool
highDensityVertical
=
true
;
const
bool
highDensityVertical
=
true
;
...
@@ -355,4 +355,63 @@ class Printer {
...
@@ -355,4 +355,63 @@ class Printer {
sendRaw
(
List
.
from
(
header
)..
addAll
(
res
));
sendRaw
(
List
.
from
(
header
)..
addAll
(
res
));
}
}
/// Print image using ESC *
///
/// [image] is an instanse of class from [Image library](https://pub.dev/packages/image)
void
printImage
(
Image
image
)
{
const
bool
highDensityHorizontal
=
true
;
const
bool
highDensityVertical
=
true
;
invert
(
image
);
final
Image
imageRotated
=
copyRotate
(
image
,
270
);
// TODO(Andrey): Mirror image (FLIP_LEFT_RIGHT)
const
int
lineHeight
=
highDensityVertical
?
3
:
1
;
final
List
<
List
<
int
>>
blobs
=
_toColumnFormat
(
imageRotated
,
lineHeight
*
8
);
print
(
blobs
.
length
);
print
(
blobs
[
0
].
length
);
final
int
widthPx
=
imageRotated
.
width
;
const
int
densityByte
=
(
highDensityHorizontal
?
1
:
0
)
+
(
highDensityVertical
?
32
:
0
);
// header = ESC + b"*" + six.int2byte(density_byte) + _int_low_high(width_pixels, 2)
final
List
<
int
>
header
=
List
.
from
(
cBitImg
.
codeUnits
);
header
.
add
(
densityByte
);
header
.
addAll
(
_intLowHigh
(
widthPx
,
2
));
// Adjust line spacing (for 16-unit line feeds): ESC 3 0x10 (HEX: 0x1b 0x33 0x10)
sendRaw
([
27
,
51
,
16
]);
for
(
int
i
=
0
;
i
<
blobs
.
length
;
++
i
)
{
sendRaw
(
List
.
from
(
header
)..
addAll
(
blobs
[
i
])..
addAll
(
'
\n
'
.
codeUnits
));
}
// Reset line spacing: ESC 2 (HEX: 0x1b 0x32)
sendRaw
([
27
,
50
]);
}
/// Extract slices of an image as equal-sized blobs of column-format data.
///
/// [image] Image to extract from
/// [lineHeight] Printed line height in dots
List
<
List
<
int
>>
_toColumnFormat
(
Image
image
,
int
lineHeight
)
{
final
int
widthPx
=
image
.
width
;
final
int
heightPx
=
image
.
height
;
int
left
=
0
;
List
<
List
<
int
>>
blobs
=
[];
int
i
=
0
;
// TODO(Andrey): We lose a part of image here -> use while(left < widthPx)
while
((
left
-
widthPx
).
abs
()
>=
lineHeight
)
{
final
Image
slice
=
copyCrop
(
image
,
left
,
0
,
lineHeight
,
heightPx
);
// File('slice_$i.png')..writeAsBytesSync(encodePng(slice));
final
Uint8List
bytes
=
slice
.
getBytes
(
format:
Format
.
luminance
);
blobs
.
add
(
_convert1bit
(
bytes
));
i
++;
left
+=
lineHeight
;
}
return
blobs
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment