|
|
|
@ -11,6 +11,7 @@ namespace ImageSharp |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
|
using Formats; |
|
|
|
|
|
|
|
@ -245,7 +246,7 @@ namespace ImageSharp |
|
|
|
/// <summary>
|
|
|
|
/// Returns a Base64 encoded string from the given image.
|
|
|
|
/// </summary>
|
|
|
|
/// <example>data:image/gif;base64,R0lGODlhAQABAIABAEdJRgAAACwAAAAAAQABAAACAkQBAA==</example>
|
|
|
|
/// <example><see href="data:image/gif;base64,R0lGODlhAQABAIABAEdJRgAAACwAAAAAAQABAAACAkQBAA=="/></example>
|
|
|
|
/// <returns>The <see cref="string"/></returns>
|
|
|
|
public string ToBase64String() |
|
|
|
{ |
|
|
|
@ -257,6 +258,57 @@ namespace ImageSharp |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a copy of the image in the given pixel format.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TColor2">The pixel format.</typeparam>
|
|
|
|
/// <typeparam name="TPacked2">The packed format. <example>uint, long, float.</example></typeparam>
|
|
|
|
/// <returns>The <see cref="Image{TColor2, TPacked2}"/></returns>
|
|
|
|
public Image<TColor2, TPacked2> To<TColor2, TPacked2>() |
|
|
|
where TColor2 : struct, IPackedPixel<TPacked2> |
|
|
|
where TPacked2 : struct |
|
|
|
{ |
|
|
|
Image<TColor2, TPacked2> target = new Image<TColor2, TPacked2>(this.Width, this.Height) |
|
|
|
{ |
|
|
|
Quality = this.Quality, |
|
|
|
FrameDelay = this.FrameDelay, |
|
|
|
HorizontalResolution = this.HorizontalResolution, |
|
|
|
VerticalResolution = this.VerticalResolution, |
|
|
|
CurrentImageFormat = this.CurrentImageFormat, |
|
|
|
RepeatCount = this.RepeatCount |
|
|
|
}; |
|
|
|
|
|
|
|
using (PixelAccessor<TColor, TPacked> pixels = this.Lock()) |
|
|
|
using (PixelAccessor<TColor2, TPacked2> targetPixels = target.Lock()) |
|
|
|
{ |
|
|
|
Parallel.For( |
|
|
|
0, |
|
|
|
target.Height, |
|
|
|
Bootstrapper.Instance.ParallelOptions, |
|
|
|
y => |
|
|
|
{ |
|
|
|
for (int x = 0; x < target.Width; x++) |
|
|
|
{ |
|
|
|
TColor2 color = default(TColor2); |
|
|
|
color.PackFromVector4(pixels[x, y].ToVector4()); |
|
|
|
targetPixels[x, y] = color; |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
if (this.ExifProfile != null) |
|
|
|
{ |
|
|
|
target.ExifProfile = new ExifProfile(this.ExifProfile); |
|
|
|
} |
|
|
|
|
|
|
|
foreach (ImageFrame<TColor, TPacked> frame in this.Frames) |
|
|
|
{ |
|
|
|
target.Frames.Add(frame.To<TColor2, TPacked2>()); |
|
|
|
} |
|
|
|
|
|
|
|
return target; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Copies the properties from the other <see cref="Image{TColor, TPacked}"/>.
|
|
|
|
/// </summary>
|
|
|
|
@ -278,6 +330,10 @@ namespace ImageSharp |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a new <see cref="ImageFrame{TColor,TPacked}"/> from this instance
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The <see cref="ImageFrame{TColor,TPacked}"/></returns>
|
|
|
|
internal virtual ImageFrame<TColor, TPacked> ToFrame() |
|
|
|
{ |
|
|
|
return new ImageFrame<TColor, TPacked>(this); |
|
|
|
|