Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ImportedProjects
SVG
Commits
42db3781
Commit
42db3781
authored
Jan 16, 2019
by
mrbean-bremen
Committed by
mrbean-bremen
Jan 17, 2019
Browse files
Scale image before rendering it into a bitmap with defined size
- fixes #405
parent
2bcf5902
Changes
1
Hide whitespace changes
Inline
Side-by-side
Source/SvgDocument.cs
View file @
42db3781
...
...
@@ -537,29 +537,33 @@ namespace Svg
/// <summary>
/// Renders the <see cref="SvgDocument"/> in given size and returns the image as a <see cref="Bitmap"/>.
/// If one of rasterWidth and rasterHeight is zero, the image is scaled preserving aspect ratio,
/// otherwise the aspect ratio is ignored.
/// </summary>
/// <returns>A <see cref="Bitmap"/> containing the rendered document.</returns>
public
virtual
Bitmap
Draw
(
int
rasterWidth
,
int
rasterHeight
)
{
var
size
=
GetDimensions
();
RasterizeDimensions
(
ref
size
,
rasterWidth
,
rasterHeight
);
var
imageSize
=
GetDimensions
();
var
bitmapSize
=
imageSize
;
RasterizeDimensions
(
ref
bitmapSize
,
rasterWidth
,
rasterHeight
);
if
(
s
ize
.
Width
==
0
||
s
ize
.
Height
==
0
)
return
null
;
if
(
bitmapS
ize
.
Width
==
0
||
bitmapS
ize
.
Height
==
0
)
return
null
;
var
bitmap
=
new
Bitmap
((
int
)
Math
.
Round
(
size
.
Width
),
(
int
)
Math
.
Round
(
size
.
Height
));
try
{
Draw
(
bitmap
);
}
catch
{
bitmap
.
Dispose
();
throw
;
}
var
bitmap
=
new
Bitmap
((
int
)
Math
.
Round
(
bitmapSize
.
Width
),
(
int
)
Math
.
Round
(
bitmapSize
.
Height
));
try
{
var
renderer
=
SvgRenderer
.
FromImage
(
bitmap
);
renderer
.
ScaleTransform
(
bitmapSize
.
Width
/
imageSize
.
Width
,
bitmapSize
.
Height
/
imageSize
.
Height
);
Draw
(
renderer
);
}
catch
{
bitmap
.
Dispose
();
throw
;
}
//Trace.TraceInformation("End Render");
return
bitmap
;
return
bitmap
;
}
/// <summary>
...
...
Write
Preview
Supports
Markdown
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