Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed nuget/BitooBitImageEditor.1.0.1.5-beta.nupkg
Binary file not shown.
Binary file added nuget/BitooBitImageEditor.1.0.1.6.nupkg
Binary file not shown.
4 changes: 2 additions & 2 deletions src/BitooBitImageEditor.Droid/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.0.1.6")]
[assembly: AssemblyFileVersion("1.0.1.6")]
4 changes: 2 additions & 2 deletions src/BitooBitImageEditor.IOS/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.0.1.6")]
[assembly: AssemblyFileVersion("1.0.1.6")]
4 changes: 2 additions & 2 deletions src/BitooBitImageEditor.UWP/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
// Можно задать все значения или принять номера сборки и редакции по умолчанию
// используя "*", как показано ниже:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.0.1.6")]
[assembly: AssemblyFileVersion("1.0.1.6")]
[assembly: ComVisible(false)]
4 changes: 2 additions & 2 deletions src/BitooBitImageEditor/BitooBitImageEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<Copyright>BitooBit</Copyright>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>1.0.1.0</Version>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<Version>1.0.1.6</Version>
<AssemblyVersion>1.0.1.6</AssemblyVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
7 changes: 6 additions & 1 deletion src/BitooBitImageEditor/BitooBitImageEditor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions src/BitooBitImageEditor/Helper/SkiaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,34 @@ internal static class SkiaHelper



internal static (SKRect rect, float scaleX, float scaleY) CalculateRectangle(SKRect info, SKBitmap bitmap, Aspect aspect = Aspect.AspectFit)
internal static (SKRect rect, float scaleX, float scaleY) CalculateRectangle(SKRect info, SKBitmap bitmap, BBAspect aspect = BBAspect.AspectFit)
{
return CalculateRectangle(info, bitmap.Width, bitmap.Height, aspect);
}

internal static (SKRect rect, float scaleX, float scaleY) CalculateRectangle(SKRect info, float width, float height, Aspect aspect = Aspect.AspectFit)
internal static (SKRect rect, float scaleX, float scaleY) CalculateRectangle(SKRect info, float width, float height, BBAspect aspect = BBAspect.AspectFit)
{
BBAspect _aspect;
if(aspect == BBAspect.Auto)
{
float aspectInfo = info.Width / info.Height;
float aspectBitmap = width / height;
if ((aspectInfo < 1 && aspectBitmap < 1) || (aspectInfo > 1 && aspectBitmap > 1))
_aspect = BBAspect.AspectFill;
else
_aspect = BBAspect.AspectFit;
}
else
_aspect = aspect;



float scaleX = info.Width / width;
float scaleY = info.Height / height;

if (aspect != Aspect.Fill)
if (_aspect != BBAspect.Fill)
{
scaleX = scaleY = aspect == Aspect.AspectFit ? Math.Min(scaleX, scaleY) : Math.Max(scaleX, scaleY);
scaleX = scaleY = _aspect == BBAspect.AspectFit ? Math.Min(scaleX, scaleY) : Math.Max(scaleX, scaleY);
float left = ((info.Width - scaleX * width) / 2) + info.Left;
float top = ((info.Height - scaleX * height) / 2) + info.Top;
float right = left + scaleX * width;
Expand Down
50 changes: 33 additions & 17 deletions src/BitooBitImageEditor/ImageEditorConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,40 @@ public enum BackgroundType
Color,
StretchedImage
}
// Отсутствует комментарий XML для открытого видимого типа или члена

/// <summary>
/// Determines how the image is displayed.
/// </summary>
public enum BBAspect
{
AspectFit = 0,
AspectFill = 1,
Fill = 2,
Auto = 3
}



/// <summary>сonfigurator image editor</summary>
public sealed class ImageEditorConfig : BaseNotifier
{
private BackgroundType backgroundType = BackgroundType.Transparent;
private Aspect aspect = Aspect.AspectFit;
private float? сropAspectRatio;
public const int maxPixels = 3000;


public const string _loadingText = "Wait";
public const string _successSaveText = "Success";
public const string _errorSaveText = "Error";


#pragma warning restore CS1591

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

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

/// <summary>sets and returns the aspect ratio for cropping the image </summary>
public float? CropAspectRatio { get; set; } = null;
public float? CropAspectRatio
{
get => сropAspectRatio;
set => сropAspectRatio = value <= 0 ? null : value;
}

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

/// <summary>Defines the background type</summary>
public BackgroundType BackgroundType
{
get => IsOutImageAutoSize ? BackgroundType.Transparent : backgroundType;
set => backgroundType = value;
}
public BackgroundType BackgroundType { get; set; } = BackgroundType.StretchedImage;

/// <summary>Determines how the image is displayed</summary>
public Aspect Aspect
{
get => IsOutImageAutoSize ? Aspect.AspectFit : aspect;
set => aspect = value;
}
public BBAspect Aspect { get; set; } = BBAspect.Auto;

/// <summary>determines whether the user can change the aspect ratio when cropping an image </summary>
public bool CanChangeCropAspectRatio => CropAspectRatio == null;
Expand All @@ -121,10 +131,16 @@ public void SetOutImageSize(int? height = null, int? widht = null)
OutImageHeight = null;
OutImageWidht = null;
}
else if (height > maxPixels || widht > maxPixels)
{
double outAspect = (double)widht / (double)height;
OutImageHeight = widht > height ? (int)(maxPixels / outAspect) : maxPixels;
OutImageWidht = widht > height ? maxPixels : (int)(maxPixels * outAspect);
}
else
{
OutImageHeight = height < 3000 ? height : 3000;
OutImageWidht = widht < 3000 ? widht : 3000;
OutImageHeight = height;
OutImageWidht = widht;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void SetMainBitmap(SKBitmap bitmap)

private void SetMainBitmapMatrix()
{
var rect = SkiaHelper.CalculateRectangle(SkiaHelper.CalculateRectangle(rectInfo, outImageWidht, outImageHeight).rect, mainBitmap.Bitmap.Width, mainBitmap.Bitmap.Height);
var rect = SkiaHelper.CalculateRectangle(SkiaHelper.CalculateRectangle(rectInfo, outImageWidht, outImageHeight).rect, mainBitmap.Bitmap.Width, mainBitmap.Bitmap.Height, config.Aspect);
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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/SampleImageEditor/SampleImageEditor.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<key>CFBundleIdentifier</key>
<string>ru.bitoobit.imageeditor</string>
<key>CFBundleVersion</key>
<string>21.0</string>
<string>22.0</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion src/SampleImageEditor/SampleImageEditor/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public MainPage()
public int? OutImageWidht { get; set; } = null;
public bool UseSampleImage { get; set; } = true;

public List<Aspect> Aspects { get; } = new List<Aspect> { Aspect.AspectFill, Aspect.AspectFit, Aspect.Fill };
public List<BBAspect> Aspects { get; } = new List<BBAspect> { BBAspect.Auto, BBAspect.AspectFill, BBAspect.AspectFit, BBAspect.Fill };
public List<BackgroundType> BackgroundTypes { get; } = new List<BackgroundType> { BackgroundType.Transparent, BackgroundType.StretchedImage, BackgroundType.Color };
public List<SKColor> Colors { get; } = new List<SKColor> { SKColors.Red, SKColors.Green, SKColors.Blue };

Expand Down