From 4399f8c50e9262d702303f2ad55c633e5c554e35 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=96=B0=E6=97=A0=E6=AD=A2=E7=AB=9E?= <734913414@qq.com>
Date: Thu, 2 Jan 2025 15:43:46 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CPF.Linux/OpenGL/GlxContext.cs | 4 --
CPF.Skia/SkiaBitmap.cs | 30 ++++++++++---
CPF.Skia/SkiaDrawingFactory.cs | 4 +-
CPF.Skia/ThreeDEffect.cs | 11 ++---
CPF.Toolkit.Demo/CPF.Toolkit.Demo.csproj | 2 +-
CPF.Toolkit/CPF.Toolkit.csproj | 2 +-
CPF/Charts/Chart.cs | 1 -
ConsoleApp1.sln | 16 +++++++
ConsoleApp1/3DEffect.cs | 21 +++++----
ConsoleApp1/View/Window1.cs | 54 ++++++++++++------------
10 files changed, 91 insertions(+), 54 deletions(-)
diff --git a/CPF.Linux/OpenGL/GlxContext.cs b/CPF.Linux/OpenGL/GlxContext.cs
index ad340d4..1743b4e 100644
--- a/CPF.Linux/OpenGL/GlxContext.cs
+++ b/CPF.Linux/OpenGL/GlxContext.cs
@@ -1,8 +1,4 @@
using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-using CPF.Drawing;
-using SkiaSharp;
namespace CPF.Linux.OpenGL
{
diff --git a/CPF.Skia/SkiaBitmap.cs b/CPF.Skia/SkiaBitmap.cs
index 09dec96..0ae30d2 100644
--- a/CPF.Skia/SkiaBitmap.cs
+++ b/CPF.Skia/SkiaBitmap.cs
@@ -116,10 +116,21 @@ namespace CPF.Skia
default:
break;
}
+
+
var m = new MemoryStream();
var stream = new SKManagedWStream(m);
- SKPixmap.Encode(stream, bitmap, f, 100);
- stream.Dispose();
+ // Create an SKImage from the SKBitmap
+ using (var image = SKImage.FromBitmap(bitmap))
+ {
+ // Encode the image into the desired format with the specified quality
+ var data = image.Encode(f, 100);
+
+ // Write the encoded data to the provided stream
+ data.SaveTo(m);
+ }
+ //SKPixmap.Encode(stream, bitmap, f, 100);
+ //stream.Dispose();
m.Position = 0;
return m;
}
@@ -144,11 +155,20 @@ namespace CPF.Skia
default:
break;
}
- //var m = new MemoryStream();
+ ////var m = new MemoryStream();
var stream = new SKManagedWStream(m);
- SKPixmap.Encode(stream, bitmap, f, 100);
+ // Create an SKImage from the SKBitmap
+ using (var image = SKImage.FromBitmap(bitmap))
+ {
+ // Encode the image into the desired format with the specified quality
+ var data = image.Encode(f, 100);
+
+ // Write the encoded data to the provided stream
+ data.SaveTo(m);
+ }
+ //SKPixmap.Encode(stream, bitmap, f, 100);
stream.Dispose();
- //return m;
+ ////return m;
}
public object Clone()
diff --git a/CPF.Skia/SkiaDrawingFactory.cs b/CPF.Skia/SkiaDrawingFactory.cs
index 3fcfa58..eb2fd38 100644
--- a/CPF.Skia/SkiaDrawingFactory.cs
+++ b/CPF.Skia/SkiaDrawingFactory.cs
@@ -138,7 +138,9 @@ namespace CPF.Skia
}
else
{
- fontWrap = new FontWrapper { SKTypeface = SKFontManager.Default.MatchTypeface(font, style) };
+ fontWrap = new FontWrapper { SKTypeface = SKFontManager.Default.MatchFamily(font.FamilyName, style) ?? font };
+ var fff = SKTypeface.Default;
+ SKFontManager.Default.MatchFamily(font.FamilyName, style);
}
#endif
_fontFamilies.TryAdd(new FontKey(weight, slant, fontFamily), fontWrap);
diff --git a/CPF.Skia/ThreeDEffect.cs b/CPF.Skia/ThreeDEffect.cs
index 1b997d7..8e58f21 100644
--- a/CPF.Skia/ThreeDEffect.cs
+++ b/CPF.Skia/ThreeDEffect.cs
@@ -64,7 +64,7 @@ namespace CPF.Skia
float yCenter = bitmap.Height / 2;
// Translate center to origin
- SKMatrix matrix = SKMatrix.MakeTranslation(-xCenter, -yCenter);
+ SKMatrix matrix = SKMatrix.CreateTranslation(-xCenter, -yCenter);
// Use 3D matrix for 3D rotations and perspective
SKMatrix44 matrix44 = SKMatrix44.CreateIdentity();
@@ -77,11 +77,12 @@ namespace CPF.Skia
matrix44.PostConcat(perspectiveMatrix);
// Concatenate with 2D matrix
- SKMatrix.PostConcat(ref matrix, matrix44.Matrix);
-
+ //SKMatrix.PostConcat(ref matrix, matrix44.Matrix);
+ matrix.PostConcat(matrix44.Matrix);
// Translate back to center
- SKMatrix.PostConcat(ref matrix,
- SKMatrix.MakeTranslation(xCenter, yCenter));
+ //SKMatrix.PostConcat(ref matrix,
+ // SKMatrix.CreateTranslation(xCenter, yCenter));
+ matrix.PostConcat(SKMatrix.CreateTranslation(xCenter, yCenter));
//var tr= dc.Transform;
//tr.ScalePrepend(0.9f, 0.9f);
diff --git a/CPF.Toolkit.Demo/CPF.Toolkit.Demo.csproj b/CPF.Toolkit.Demo/CPF.Toolkit.Demo.csproj
index 8602593..e172e80 100644
--- a/CPF.Toolkit.Demo/CPF.Toolkit.Demo.csproj
+++ b/CPF.Toolkit.Demo/CPF.Toolkit.Demo.csproj
@@ -2,7 +2,7 @@
WinExe
- netcoreapp3.0
+ net8.0;net9.0
diff --git a/CPF.Toolkit/CPF.Toolkit.csproj b/CPF.Toolkit/CPF.Toolkit.csproj
index a49aac9..2bcf31b 100644
--- a/CPF.Toolkit/CPF.Toolkit.csproj
+++ b/CPF.Toolkit/CPF.Toolkit.csproj
@@ -1,7 +1,7 @@
- netstandard2.0
+ net8.0;net9.0
diff --git a/CPF/Charts/Chart.cs b/CPF/Charts/Chart.cs
index a695c79..711ee35 100644
--- a/CPF/Charts/Chart.cs
+++ b/CPF/Charts/Chart.cs
@@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
-using System.Text;
namespace CPF.Charts
{
diff --git a/ConsoleApp1.sln b/ConsoleApp1.sln
index 0f0814f..51d1b21 100644
--- a/ConsoleApp1.sln
+++ b/ConsoleApp1.sln
@@ -21,6 +21,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CPF.Razor", "CPF.Razor\CPF.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CpfRazorSample", "CpfRazorSample\CpfRazorSample.csproj", "{25A4EE47-F5BD-4F1E-B143-3E3B50C5AC2A}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CPF.Toolkit", "CPF.Toolkit\CPF.Toolkit.csproj", "{3EE582BD-55C3-4192-8473-620C1ABB188F}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CPF.Toolkit.Demo", "CPF.Toolkit.Demo\CPF.Toolkit.Demo.csproj", "{DAFE1B84-A07A-46AB-927F-EFF867ED329F}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -82,6 +86,18 @@ Global
{25A4EE47-F5BD-4F1E-B143-3E3B50C5AC2A}.Release|Any CPU.Build.0 = Release|Any CPU
{25A4EE47-F5BD-4F1E-B143-3E3B50C5AC2A}.类库d|Any CPU.ActiveCfg = Debug|Any CPU
{25A4EE47-F5BD-4F1E-B143-3E3B50C5AC2A}.类库d|Any CPU.Build.0 = Debug|Any CPU
+ {3EE582BD-55C3-4192-8473-620C1ABB188F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3EE582BD-55C3-4192-8473-620C1ABB188F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3EE582BD-55C3-4192-8473-620C1ABB188F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3EE582BD-55C3-4192-8473-620C1ABB188F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3EE582BD-55C3-4192-8473-620C1ABB188F}.类库d|Any CPU.ActiveCfg = Debug|Any CPU
+ {3EE582BD-55C3-4192-8473-620C1ABB188F}.类库d|Any CPU.Build.0 = Debug|Any CPU
+ {DAFE1B84-A07A-46AB-927F-EFF867ED329F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {DAFE1B84-A07A-46AB-927F-EFF867ED329F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {DAFE1B84-A07A-46AB-927F-EFF867ED329F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {DAFE1B84-A07A-46AB-927F-EFF867ED329F}.Release|Any CPU.Build.0 = Release|Any CPU
+ {DAFE1B84-A07A-46AB-927F-EFF867ED329F}.类库d|Any CPU.ActiveCfg = Debug|Any CPU
+ {DAFE1B84-A07A-46AB-927F-EFF867ED329F}.类库d|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/ConsoleApp1/3DEffect.cs b/ConsoleApp1/3DEffect.cs
index 5ebd632..c9f15c3 100644
--- a/ConsoleApp1/3DEffect.cs
+++ b/ConsoleApp1/3DEffect.cs
@@ -59,9 +59,11 @@ namespace ConsoleApp1
float x = 0;
float y = 0;
- SKMatrix matrix = SKMatrix.MakeTranslation(-x, -y);
- SKMatrix.PostConcat(ref matrix, taperMatrix);
- SKMatrix.PostConcat(ref matrix, SKMatrix.MakeTranslation(x, y));
+ SKMatrix matrix = SKMatrix.CreateTranslation(-x, -y);
+ matrix.PostConcat(taperMatrix);
+ //SKMatrix.PostConcat(ref matrix, taperMatrix);
+ //SKMatrix.PostConcat(ref matrix, SKMatrix.CreateTranslation(x, y));
+ matrix.PostConcat(SKMatrix.CreateTranslation(x, y));
var canvas = (dc as CPF.Skia.SkiaDrawingContext).SKCanvas;
var mat = canvas.TotalMatrix;
@@ -81,7 +83,7 @@ namespace ConsoleApp1
{
public static SKMatrix Make(SKSize size, TaperSide taperSide, TaperCorner taperCorner, float taperFraction)
{
- SKMatrix matrix = SKMatrix.MakeIdentity();
+ SKMatrix matrix = SKMatrix.CreateIdentity();
switch (taperSide)
{
@@ -230,7 +232,7 @@ namespace ConsoleApp1
float yCenter = bitmap.Height / 2;
// Translate center to origin
- SKMatrix matrix = SKMatrix.MakeTranslation(-xCenter, -yCenter);
+ SKMatrix matrix = SKMatrix.CreateTranslation(-xCenter, -yCenter);
// Use 3D matrix for 3D rotations and perspective
SKMatrix44 matrix44 = SKMatrix44.CreateIdentity();
@@ -243,11 +245,12 @@ namespace ConsoleApp1
matrix44.PostConcat(perspectiveMatrix);
// Concatenate with 2D matrix
- SKMatrix.PostConcat(ref matrix, matrix44.Matrix);
-
+ //SKMatrix.PostConcat(ref matrix, matrix44.Matrix);
+ matrix.PostConcat(matrix44.Matrix);
// Translate back to center
- SKMatrix.PostConcat(ref matrix,
- SKMatrix.MakeTranslation(xCenter, yCenter));
+ //SKMatrix.PostConcat(ref matrix,
+ // SKMatrix.CreateTranslation(xCenter, yCenter));
+ matrix.PostConcat(SKMatrix.CreateTranslation(xCenter, yCenter));
//var tr= dc.Transform;
//tr.ScalePrepend(0.9f, 0.9f);
diff --git a/ConsoleApp1/View/Window1.cs b/ConsoleApp1/View/Window1.cs
index 7d6b0da..2221b18 100644
--- a/ConsoleApp1/View/Window1.cs
+++ b/ConsoleApp1/View/Window1.cs
@@ -2542,34 +2542,34 @@ LUNA".Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
Height = "100%",
Children =
{
- new EditComboBox
- {
+ // new EditComboBox
+ // {
- PresenterFor=this,
- Name=nameof(EditComboBox1),
- Height = 28,
- Width = 152,
- MarginRight = 1,
- Items =sp
- },
- new Button
- {
- Commands =
- {
- {
- nameof(Button.Click),
- nameof(Cancel),
- this,
- CommandParameter.EventSender,
- CommandParameter.EventArgs
- },
- },
- MarginBottom = 10,
- Height = 32,
- Width = 83,
- MarginLeft = 282,
- Content = "取消",
- }
+ // PresenterFor=this,
+ // Name=nameof(EditComboBox1),
+ // Height = 28,
+ // Width = 152,
+ // MarginRight = 1,
+ // Items =sp
+ // },
+ // new Button
+ //{
+ // Commands =
+ // {
+ // {
+ // nameof(Button.Click),
+ // nameof(Cancel),
+ // this,
+ // CommandParameter.EventSender,
+ // CommandParameter.EventArgs
+ // },
+ // },
+ // MarginBottom = 10,
+ // Height = 32,
+ // Width = 83,
+ // MarginLeft = 282,
+ // Content = "取消",
+ //}
}
}));