Skip to content

Commit 6d4ffe5

Browse files
authored
Merge pull request #10 from BitooBit/develop
Develop
2 parents 81b3835 + 6a918eb commit 6d4ffe5

12 files changed

Lines changed: 69 additions & 33 deletions

File tree

-861 KB
Binary file not shown.
862 KB
Binary file not shown.

src/BitooBitImageEditor.Droid/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@
2424
// You can specify all the values or you can default the Build and Revision Numbers
2525
// by using the '*' as shown below:
2626
// [assembly: AssemblyVersion("1.0.*")]
27-
[assembly: AssemblyVersion("1.0.1.0")]
28-
[assembly: AssemblyFileVersion("1.0.1.0")]
27+
[assembly: AssemblyVersion("1.0.1.6")]
28+
[assembly: AssemblyFileVersion("1.0.1.6")]

src/BitooBitImageEditor.IOS/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
// You can specify all the values or you can default the Build and Revision Numbers
3232
// by using the '*' as shown below:
3333
// [assembly: AssemblyVersion("1.0.*")]
34-
[assembly: AssemblyVersion("1.0.1.0")]
35-
[assembly: AssemblyFileVersion("1.0.1.0")]
34+
[assembly: AssemblyVersion("1.0.1.6")]
35+
[assembly: AssemblyFileVersion("1.0.1.6")]

src/BitooBitImageEditor.UWP/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
// Можно задать все значения или принять номера сборки и редакции по умолчанию
2424
// используя "*", как показано ниже:
2525
// [assembly: AssemblyVersion("1.0.*")]
26-
[assembly: AssemblyVersion("1.0.1.0")]
27-
[assembly: AssemblyFileVersion("1.0.1.0")]
26+
[assembly: AssemblyVersion("1.0.1.6")]
27+
[assembly: AssemblyFileVersion("1.0.1.6")]
2828
[assembly: ComVisible(false)]

src/BitooBitImageEditor/BitooBitImageEditor.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<Copyright>BitooBit</Copyright>
1414
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1515
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
16-
<Version>1.0.1.0</Version>
17-
<AssemblyVersion>1.0.1.0</AssemblyVersion>
16+
<Version>1.0.1.6</Version>
17+
<AssemblyVersion>1.0.1.6</AssemblyVersion>
1818
</PropertyGroup>
1919

2020
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

src/BitooBitImageEditor/BitooBitImageEditor.xml

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/BitooBitImageEditor/Helper/SkiaHelper.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,34 @@ internal static class SkiaHelper
1616

1717

1818

19-
internal static (SKRect rect, float scaleX, float scaleY) CalculateRectangle(SKRect info, SKBitmap bitmap, Aspect aspect = Aspect.AspectFit)
19+
internal static (SKRect rect, float scaleX, float scaleY) CalculateRectangle(SKRect info, SKBitmap bitmap, BBAspect aspect = BBAspect.AspectFit)
2020
{
2121
return CalculateRectangle(info, bitmap.Width, bitmap.Height, aspect);
2222
}
2323

24-
internal static (SKRect rect, float scaleX, float scaleY) CalculateRectangle(SKRect info, float width, float height, Aspect aspect = Aspect.AspectFit)
24+
internal static (SKRect rect, float scaleX, float scaleY) CalculateRectangle(SKRect info, float width, float height, BBAspect aspect = BBAspect.AspectFit)
2525
{
26+
BBAspect _aspect;
27+
if(aspect == BBAspect.Auto)
28+
{
29+
float aspectInfo = info.Width / info.Height;
30+
float aspectBitmap = width / height;
31+
if ((aspectInfo < 1 && aspectBitmap < 1) || (aspectInfo > 1 && aspectBitmap > 1))
32+
_aspect = BBAspect.AspectFill;
33+
else
34+
_aspect = BBAspect.AspectFit;
35+
}
36+
else
37+
_aspect = aspect;
38+
39+
40+
2641
float scaleX = info.Width / width;
2742
float scaleY = info.Height / height;
2843

29-
if (aspect != Aspect.Fill)
44+
if (_aspect != BBAspect.Fill)
3045
{
31-
scaleX = scaleY = aspect == Aspect.AspectFit ? Math.Min(scaleX, scaleY) : Math.Max(scaleX, scaleY);
46+
scaleX = scaleY = _aspect == BBAspect.AspectFit ? Math.Min(scaleX, scaleY) : Math.Max(scaleX, scaleY);
3247
float left = ((info.Width - scaleX * width) / 2) + info.Left;
3348
float top = ((info.Height - scaleX * height) / 2) + info.Top;
3449
float right = left + scaleX * width;

src/BitooBitImageEditor/ImageEditorConfig.cs

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,40 @@ public enum BackgroundType
1515
Color,
1616
StretchedImage
1717
}
18-
// Отсутствует комментарий XML для открытого видимого типа или члена
18+
19+
/// <summary>
20+
/// Determines how the image is displayed.
21+
/// </summary>
22+
public enum BBAspect
23+
{
24+
AspectFit = 0,
25+
AspectFill = 1,
26+
Fill = 2,
27+
Auto = 3
28+
}
29+
30+
1931

2032
/// <summary>сonfigurator image editor</summary>
2133
public sealed class ImageEditorConfig : BaseNotifier
2234
{
23-
private BackgroundType backgroundType = BackgroundType.Transparent;
24-
private Aspect aspect = Aspect.AspectFit;
35+
private float? сropAspectRatio;
36+
public const int maxPixels = 3000;
37+
2538

2639
public const string _loadingText = "Wait";
2740
public const string _successSaveText = "Success";
2841
public const string _errorSaveText = "Error";
2942

43+
3044
#pragma warning restore CS1591
3145

3246
/// <summary>constructor with default values</summary>
3347
public ImageEditorConfig() { }
3448

3549
/// <summary></summary>
3650
public ImageEditorConfig(bool canAddText = true, bool canFingerPaint = true, bool canTransformMainBitmap = true, float? cropAspectRatio = null,
37-
List<SKBitmapImageSource> stickers = null, int? outImageHeight = null, int? outImageWidht = null, Aspect aspect = Aspect.AspectFit,
51+
List<SKBitmapImageSource> stickers = null, int? outImageHeight = null, int? outImageWidht = null, BBAspect aspect = BBAspect.Auto,
3852
BackgroundType backgroundType = BackgroundType.Transparent, SKColor backgroundColor = default,
3953
bool canSaveImage = true, string loadingText = _loadingText, string successSaveText = _successSaveText, string errorSaveText = _errorSaveText)
4054
{
@@ -73,7 +87,11 @@ public ImageEditorConfig(bool canAddText = true, bool canFingerPaint = true, boo
7387
public string ErrorSaveText { get; set; } = _errorSaveText;
7488

7589
/// <summary>sets and returns the aspect ratio for cropping the image </summary>
76-
public float? CropAspectRatio { get; set; } = null;
90+
public float? CropAspectRatio
91+
{
92+
get => сropAspectRatio;
93+
set => сropAspectRatio = value <= 0 ? null : value;
94+
}
7795

7896
/// <summary>sets a set of stickers.
7997
/// <para>do not use a large number of stickers this will lead to a large consumption of RAM</para>
@@ -91,18 +109,10 @@ public ImageEditorConfig(bool canAddText = true, bool canFingerPaint = true, boo
91109
public SKColor BackgroundColor { get; set; } = default;
92110

93111
/// <summary>Defines the background type</summary>
94-
public BackgroundType BackgroundType
95-
{
96-
get => IsOutImageAutoSize ? BackgroundType.Transparent : backgroundType;
97-
set => backgroundType = value;
98-
}
112+
public BackgroundType BackgroundType { get; set; } = BackgroundType.StretchedImage;
99113

100114
/// <summary>Determines how the image is displayed</summary>
101-
public Aspect Aspect
102-
{
103-
get => IsOutImageAutoSize ? Aspect.AspectFit : aspect;
104-
set => aspect = value;
105-
}
115+
public BBAspect Aspect { get; set; } = BBAspect.Auto;
106116

107117
/// <summary>determines whether the user can change the aspect ratio when cropping an image </summary>
108118
public bool CanChangeCropAspectRatio => CropAspectRatio == null;
@@ -121,10 +131,16 @@ public void SetOutImageSize(int? height = null, int? widht = null)
121131
OutImageHeight = null;
122132
OutImageWidht = null;
123133
}
134+
else if (height > maxPixels || widht > maxPixels)
135+
{
136+
double outAspect = (double)widht / (double)height;
137+
OutImageHeight = widht > height ? (int)(maxPixels / outAspect) : maxPixels;
138+
OutImageWidht = widht > height ? maxPixels : (int)(maxPixels * outAspect);
139+
}
124140
else
125141
{
126-
OutImageHeight = height < 3000 ? height : 3000;
127-
OutImageWidht = widht < 3000 ? widht : 3000;
142+
OutImageHeight = height;
143+
OutImageWidht = widht;
128144
}
129145
}
130146

src/BitooBitImageEditor/ManipulationBitmap/TouchManipulationCanvasView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private void SetMainBitmap(SKBitmap bitmap)
164164

165165
private void SetMainBitmapMatrix()
166166
{
167-
var rect = SkiaHelper.CalculateRectangle(SkiaHelper.CalculateRectangle(rectInfo, outImageWidht, outImageHeight).rect, mainBitmap.Bitmap.Width, mainBitmap.Bitmap.Height);
167+
var rect = SkiaHelper.CalculateRectangle(SkiaHelper.CalculateRectangle(rectInfo, outImageWidht, outImageHeight).rect, mainBitmap.Bitmap.Width, mainBitmap.Bitmap.Height, config.Aspect);
168168
mainBitmap.Matrix = new SKMatrix(rect.scaleX, 0, rectInfo.MidX - rect.rect.Width / 2, 0, rect.scaleY, rectInfo.MidY - rect.rect.Height / 2, 0, 0, 1);
169169
}
170170

0 commit comments

Comments
 (0)