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
6f53360e
Commit
6f53360e
authored
Dec 18, 2013
by
Jay
Browse files
Add data-uri scheme (embedded images) to image support
parent
fdaeac02
Changes
1
Hide whitespace changes
Inline
Side-by-side
Source/Basic Shapes/SvgImage.cs
View file @
6f53360e
...
...
@@ -125,14 +125,29 @@ namespace Svg
{
try
{
// handle data/uri embedded images (http://en.wikipedia.org/wiki/Data_URI_scheme)
if
(
uri
.
Scheme
==
"data"
)
{
string
uriString
=
uri
.
OriginalString
;
int
dataIdx
=
uriString
.
IndexOf
(
","
)
+
1
;
if
(
dataIdx
<=
0
||
dataIdx
+
1
>
uriString
.
Length
)
throw
new
Exception
(
"Invalid data URI"
);
// we're assuming base64, as ascii encoding would be *highly* unsusual for images
// also assuming it's png or jpeg mimetype
byte
[]
imageBytes
=
Convert
.
FromBase64String
(
uriString
.
Substring
(
dataIdx
));
Image
image
=
Image
.
FromStream
(
new
MemoryStream
(
imageBytes
));
return
image
;
}
// should work with http: and file: protocol urls
var
httpRequest
=
WebRequest
.
Create
(
uri
);
using
(
WebResponse
webResponse
=
httpRequest
.
GetResponse
())
{
MemoryStream
ms
=
BufferToMemoryStream
(
webResponse
.
GetResponseStream
());
Image
b
=
Bitmap
.
FromStream
(
ms
);
return
b
;
Image
image
=
Bitmap
.
FromStream
(
ms
);
return
image
;
}
}
catch
(
Exception
ex
)
...
...
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