|
@@ -404,45 +404,67 @@ namespace Common.system
|
404
|
404
|
{
|
405
|
405
|
try
|
406
|
406
|
{
|
407
|
|
- //System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
|
408
|
407
|
//在位图中呈现UI元素
|
409
|
408
|
RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, PrimaryScreen.DpiX, PrimaryScreen.DpiY, PixelFormats.Pbgra32);
|
410
|
409
|
bmp.Render(ui);
|
411
|
410
|
BitmapEncoder encoder = new PngBitmapEncoder();
|
412
|
411
|
encoder.Frames.Add(BitmapFrame.Create(bmp));
|
413
|
|
- //encoder.Save(fs);
|
414
|
|
- //fs.Close();
|
415
|
|
- Bitmap Img = new Bitmap(ImgWidth, ImgHeight);
|
416
|
|
- try
|
|
412
|
+ if (ImgWidth > 0)
|
417
|
413
|
{
|
418
|
|
- MemoryStream memoryStream = new MemoryStream();
|
419
|
|
- encoder.Save(memoryStream);
|
420
|
|
- //System.Drawing.Image img = System.Drawing.Image.FromStream(memoryStream);
|
421
|
|
- Bitmap bit = new Bitmap(memoryStream);
|
|
414
|
+ Bitmap Img = new Bitmap(ImgWidth, ImgHeight);
|
422
|
415
|
try
|
423
|
416
|
{
|
424
|
|
- Graphics g = Graphics.FromImage(Img);
|
425
|
|
- //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
426
|
|
- g.DrawImage(bit, new Rectangle(0, 0, ImgWidth, ImgHeight), new Rectangle(0, 0, (int)bit.Width, (int)bit.Height), GraphicsUnit.Pixel);
|
427
|
|
- g.Dispose();
|
|
417
|
+ MemoryStream memoryStream = new MemoryStream();
|
|
418
|
+ encoder.Save(memoryStream);
|
|
419
|
+ //System.Drawing.Image img = System.Drawing.Image.FromStream(memoryStream);
|
|
420
|
+ Bitmap bit = new Bitmap(memoryStream);
|
|
421
|
+ try
|
|
422
|
+ {
|
|
423
|
+ Graphics g = Graphics.FromImage(Img);
|
|
424
|
+ //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
425
|
+ g.DrawImage(bit, new Rectangle(0, 0, ImgWidth, ImgHeight), new Rectangle(0, 0, (int)bit.Width, (int)bit.Height), GraphicsUnit.Pixel);
|
|
426
|
+ g.Dispose();
|
|
427
|
+ }
|
|
428
|
+ catch
|
|
429
|
+ {
|
|
430
|
+ Img = bit;
|
|
431
|
+ }
|
|
432
|
+ new Thread(new ThreadStart(new Action(() =>
|
|
433
|
+ {
|
|
434
|
+ Img.Save(filePathName);
|
|
435
|
+ //Bitmap bitmap = CutImageWhitePart(Img);
|
|
436
|
+ //FileToolsCommon.DeleteFile(filePathName);
|
|
437
|
+ //bitmap.Save(filePathName);
|
|
438
|
+ //bitmap.Dispose();
|
|
439
|
+ Img.Dispose();
|
|
440
|
+ bit.Dispose();
|
|
441
|
+ }))).Start();
|
428
|
442
|
}
|
429
|
|
- catch
|
|
443
|
+ catch (Exception ex)
|
430
|
444
|
{
|
431
|
|
- Img = bit;
|
|
445
|
+
|
432
|
446
|
}
|
433
|
|
- new Thread(new ThreadStart(new Action(() =>
|
434
|
|
- {
|
435
|
|
- //Img.Save(filePathName);
|
436
|
|
- Bitmap bitmap = CutImageWhitePart(Img);
|
437
|
|
- FileToolsCommon.DeleteFile(filePathName);
|
438
|
|
- bitmap.Save(filePathName);
|
439
|
|
- bitmap.Dispose();
|
440
|
|
- Img.Dispose();
|
441
|
|
- bit.Dispose();
|
442
|
|
- }))).Start();
|
443
|
447
|
}
|
444
|
|
- catch (Exception ex)
|
|
448
|
+ else
|
445
|
449
|
{
|
|
450
|
+ System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
|
|
451
|
+ encoder.Save(fs);
|
|
452
|
+ fs.Close();
|
|
453
|
+
|
|
454
|
+ //MemoryStream memoryStream = new MemoryStream();
|
|
455
|
+ //encoder.Save(memoryStream);
|
|
456
|
+ //Bitmap bit = new Bitmap(memoryStream);
|
|
457
|
+ //bit.Save(filePathName);
|
|
458
|
+ //bit.Dispose();
|
|
459
|
+
|
|
460
|
+ //using (FileStream tFileStream = new FileStream(filePathName,FileMode.Create, FileAccess.Write))
|
|
461
|
+ //{
|
|
462
|
+ // PngBitmapEncoder tPngBitmapEncoder = new PngBitmapEncoder();
|
|
463
|
+ // tPngBitmapEncoder.Interlace = PngInterlaceOption.On;
|
|
464
|
+ // tPngBitmapEncoder.Frames.Add(BitmapFrame.Create(bmp));
|
|
465
|
+ // tPngBitmapEncoder.Save(tFileStream);
|
|
466
|
+ // tFileStream.Close();
|
|
467
|
+ //}
|
446
|
468
|
|
447
|
469
|
}
|
448
|
470
|
}
|