public static BitmapRam ToBitmapRam(this BitmapSource src) { var result = new BitmapRam(src.PixelWidth, src.PixelHeight); result.CopyPixelsFrom(src); return(result); }
public BitmapRam ToBitmapRam() { var result = new BitmapRam(Width, Height); result.CopyPixelsFrom(this); return(result); }
public void Blur(GaussianBlur blur, BlurEdgeMode edgeMode) { var temp = new BitmapRam(Width, Height); using (UseWrite()) using (temp.UseWrite()) { PreMultiply(); blur.Horizontal(this, temp, edgeMode); blur.Vertical(temp, this, edgeMode); UnPreMultiply(); } }
/// <summary>Loads a .tga image directly into a <see cref="BitmapRam"/> instance.</summary> public static BitmapRam Load(Stream file) { var header = file.Read(18); if (header[0] != 0) { throw new NotSupportedException("Only images with no offset are supported"); } if (header[1] != 0) { throw new NotSupportedException("Only RGB images are supported"); } if (header[2] != 2) { throw new NotSupportedException("Only RGB images are supported"); } if (header[8] != 0 || header[9] != 0 || header[10] != 0 || header[11] != 0) { throw new NotSupportedException("Only images with origin at 0,0 are supported"); } var width = (header[13] << 8) + header[12]; var height = (header[15] << 8) + header[14]; if (width > 2048 || height > 2048) // an arbitrary limit; more for sanity check than anything else { throw new NotSupportedException("Only images up to 2048x2048 are supported"); } if (width == 0 || height == 0) { throw new NotSupportedException("Images with a zero width or height are not supported"); } if (header[16] != 32) { throw new NotSupportedException("Only 32 bits per pixel images are supported"); } bool rightWayUp = (header[17] & 32) != 0; var raw = file.Read(width * height * 4); var result = new BitmapRam(width, height); result.CopyPixelsFrom(raw, width, height, width * 4, !rightWayUp); return(result); }
/// <summary>Loads a .tga image directly into a <see cref="BitmapRam"/> instance.</summary> public static BitmapRam Load(Stream file) { var header = file.Read(18); if (header[0] != 0) throw new NotSupportedException("Only images with no offset are supported"); if (header[1] != 0) throw new NotSupportedException("Only RGB images are supported"); if (header[2] != 2) throw new NotSupportedException("Only RGB images are supported"); if (header[8] != 0 || header[9] != 0 || header[10] != 0 || header[11] != 0) throw new NotSupportedException("Only images with origin at 0,0 are supported"); var width = (header[13] << 8) + header[12]; var height = (header[15] << 8) + header[14]; if (width > 2048 || height > 2048) // an arbitrary limit; more for sanity check than anything else throw new NotSupportedException("Only images up to 2048x2048 are supported"); if (width == 0 || height == 0) throw new NotSupportedException("Images with a zero width or height are not supported"); if (header[16] != 32) throw new NotSupportedException("Only 32 bits per pixel images are supported"); bool rightWayUp = (header[17] & 32) != 0; var raw = file.Read(width * height * 4); var result = new BitmapRam(width, height); result.CopyPixelsFrom(raw, width, height, width * 4, !rightWayUp); return result; }
public BitmapRam ToBitmapRam() { var result = new BitmapRam(Width, Height); result.CopyPixelsFrom(this); return result; }
public static BitmapRam ToBitmapRam(this BitmapSource src) { var result = new BitmapRam(src.PixelWidth, src.PixelHeight); result.CopyPixelsFrom(src); return result; }
public static unsafe BitmapBase SizePos(BitmapBase source, double scaleWidth, double scaleHeight, int inX, int inY, int outX, int outY, int maxWidth = 0, int maxHeight = 0, Filter filter = null) { if (source.Width <= 0 || source.Height <= 0) { return(source.ToBitmapSame()); } PixelRect pureImg = source.PreciseSize(0); if (pureImg.Width <= 0 || pureImg.Height <= 0) { return(source.ToBitmapSame()); } int outWidth = (int)Math.Round(pureImg.Width * scaleWidth); int outHeight = (int)Math.Round(pureImg.Height * scaleHeight); if (scaleWidth == 1 && scaleHeight == 1) { //no resize needed if (inX != outX || inY != outY) { BitmapBase result; if (maxWidth == 0 && maxHeight == 0) { result = new BitmapRam(outX - inX + source.Width, outY - inY + source.Height); } else { result = new BitmapRam(Math.Min(outX - inX + source.Width, maxWidth), Math.Min(outY - inY + source.Height, maxHeight)); } result.DrawImage(source, outX - inX, outY - inY); return(result); } else { return(source.ToBitmapSame()); } } if (filter == null) { if (scaleWidth < 1) { filter = new LanczosFilter(); } else { filter = new MitchellFilter(); } } int transparentOffset; if (pureImg.Left != 0 || pureImg.Top != 0) { transparentOffset = pureImg.Left * 4 + pureImg.Top * source.Stride; // Resample looks better if transprent pixels is cropped. Especially if the image is square // Data+DataOffset, pureImg.Width, pureImg.Height instead of Data, Width, Height works like left-top cropping } else { transparentOffset = 0; } BitmapBase afterHorzResample, afterVertResample; // Horizontal resampling if (scaleWidth == 1) { afterHorzResample = source; } else { afterHorzResample = new BitmapRam(outWidth, pureImg.Height); ContributorEntry[] contrib = filter.PrecomputeResample(scaleWidth, pureImg.Width, outWidth); Resample1D(afterHorzResample, source, transparentOffset, contrib, outWidth, pureImg.Height, true); transparentOffset = 0; } // Vertical resampling if (scaleHeight == 1) { afterVertResample = afterHorzResample; } else { afterVertResample = new BitmapRam(outWidth, outHeight); ContributorEntry[] contrib = filter.PrecomputeResample(scaleHeight, pureImg.Height, outHeight); Resample1D(afterVertResample, afterHorzResample, transparentOffset, contrib, outHeight, outWidth, false); } BitmapBase final; //At this point image will be resized and moved to another BitmapBase anyway int drawX = outX - (int)Math.Round((inX - pureImg.Left) * scaleWidth); int drawY = outY - (int)Math.Round((inY - pureImg.Top) * scaleHeight); if (maxWidth == 0 && maxHeight == 0) { final = new BitmapRam(Math.Max(drawX + outWidth, maxWidth), Math.Max(drawY + outHeight, maxHeight)); } else { final = new BitmapRam(Math.Max(drawX + outWidth, maxWidth), Math.Max(drawY + outHeight, maxHeight)); } final.DrawImage(afterVertResample, drawX, drawY); return(final); }