개정판 661b7416
issue #999: Add FromString to all of controls
Change-Id: I64093e34a5f9e8d367cbed769ff4db8d7472cb7a
MarkupToPDF/Controls/Etc/ImgControl.cs | ||
---|---|---|
15 | 15 |
using MarkupToPDF.Common; |
16 | 16 |
using MarkupToPDF.Serialize.Core; |
17 | 17 |
using MarkupToPDF.Serialize.S_Control; |
18 |
using System.Windows.Media.Imaging; |
|
19 |
using Svg2Xaml; |
|
18 | 20 |
|
19 | 21 |
namespace MarkupToPDF.Controls.Etc |
20 | 22 |
{ |
... | ... | |
284 | 286 |
Base_Image.Height = 0; |
285 | 287 |
SetImage(); |
286 | 288 |
} |
289 |
|
|
287 | 290 |
public void SetImage() |
288 | 291 |
{ |
289 | 292 |
this.ApplyTemplate(); |
... | ... | |
368 | 371 |
return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize())); |
369 | 372 |
} |
370 | 373 |
} |
374 |
|
|
375 |
/// <summary> |
|
376 |
/// create a imgcontrol from given string |
|
377 |
/// </summary> |
|
378 |
/// <param name="str"></param> |
|
379 |
/// <returns></returns> |
|
380 |
public static ImgControl FromString(string str, SolidColorBrush brush, string sProjectNo) |
|
381 |
{ |
|
382 |
ImgControl instance = null; |
|
383 |
using (S_ImgControl s = JsonSerializerHelper.JsonDeserialize<S_ImgControl>(str)) |
|
384 |
{ |
|
385 |
Image img = new Image(); |
|
386 |
if (s.ImagePath.Contains(".svg")) |
|
387 |
{ |
|
388 |
byte[] imageData = null; |
|
389 |
DrawingImage image = null; |
|
390 |
using (System.Net.WebClient web = new System.Net.WebClient()) |
|
391 |
{ |
|
392 |
imageData = web.DownloadData(new Uri(s.ImagePath)); |
|
393 |
System.IO.Stream stream = new System.IO.MemoryStream(imageData); |
|
394 |
image = SvgReader.Load(stream); |
|
395 |
} |
|
396 |
img.Source = image; |
|
397 |
} |
|
398 |
else |
|
399 |
{ |
|
400 |
img.Source = new BitmapImage(new Uri(s.ImagePath)); |
|
401 |
} |
|
402 |
|
|
403 |
instance = new ImgControl |
|
404 |
{ |
|
405 |
Angle = s.Angle, |
|
406 |
StartPoint = s.StartPoint, |
|
407 |
TopRightPoint = s.TR, |
|
408 |
EndPoint = s.EndPoint, |
|
409 |
LeftBottomPoint = s.LB, |
|
410 |
PointSet = s.PointSet, |
|
411 |
Opacity = s.Opac, |
|
412 |
FilePath = s.ImagePath, |
|
413 |
UserID = s.UserID, |
|
414 |
ImageData = img.Source, |
|
415 |
Memo = s.Memo |
|
416 |
}; |
|
417 |
|
|
418 |
instance.ImageData = img.Source; |
|
419 |
} |
|
420 |
|
|
421 |
return instance; |
|
422 |
} |
|
371 | 423 |
} |
372 | 424 |
} |
내보내기 Unified diff