完善代码

This commit is contained in:
新无止竞 2025-01-02 15:43:46 +08:00
parent c42600f1b1
commit 4399f8c50e
10 changed files with 91 additions and 54 deletions

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using CPF.Drawing;
using SkiaSharp;
namespace CPF.Linux.OpenGL
{

View File

@ -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()

View File

@ -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);

View File

@ -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);

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ApplicationIcon />
<StartupObject />
</PropertyGroup>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
namespace CPF.Charts
{

View File

@ -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

View File

@ -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);

View File

@ -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 = "取消",
//}
}
}));