BitmapSource TransformBitmap(RenderTargetBitmap source) { //.Mutate(x => x.get) //.Clone(x => x.Rotate(RotateMode.Rotate90)); //sourceImage.Clone(x => x.Rotate(RotateMode.Rotate90)); var buffer = new UInt32[source.PixelWidth * source.PixelHeight]; source.CopyPixels(buffer, source.PixelWidth * 4, 0); var target = new UInt32[source.PixelWidth]; for (var i = 0; i < source.PixelWidth; ++i) { var x = new Vector3(); for (var j = 0; j < source.PixelHeight; ++j) { uint packed = buffer[j * source.PixelWidth + i]; var pp = new Rgba32(packed); if (pp.A != 255) { continue; } Rgb p = pp; //if (packed != 0u) System.Diagnostics.Debugger.Break(); x = Vector3.Max(x, p.ToVector3()); } target[i] = new Rgba32(x).PackedValue; } //return RenderTargetBitmap.Create(source.PixelWidth, source.PixelHeight, 96, 96, source.Format, source.Palette, buffer, source.PixelWidth * 4); return(RenderTargetBitmap.Create(source.PixelWidth, 1, 96, 96, source.Format, source.Palette, target, source.PixelWidth * 4)); }
/// <summary> /// renders the text based on the properties set /// </summary> public IImageAdapter Render() { IImageAdapter retVal = null; mFormattedText = new FormattedText(Text, CultureInfo.CurrentUICulture, FlowDirection.LeftToRight, getTypeface(), FontSize, new System.Windows.Media.SolidColorBrush(_foreGround)); int textWidth = (int)mFormattedText.Width; int textHeight = (int)mFormattedText.Height; using (ImageUtility imageUtil = new ImageUtility(textWidth, textHeight)) { imageUtil.GetSetPixelUnsafeBegin(); int stride = textWidth * 4; byte[] milBuffer = new byte[stride * textHeight]; RenderTargetBitmap renderTargeBitmap = (RenderTargetBitmap)RenderTargetBitmap.Create(textWidth, textHeight, 96, 96, PixelFormats.Bgra32, null, milBuffer, stride); { Visual visual = new TypoDrawingVisual(mFormattedText, _backGround); renderTargeBitmap.Render(visual); renderTargeBitmap.CopyPixels(milBuffer, stride, 0); int index = 0; byte[] vscanBuffer = imageUtil.GetStreamBufferBGRA(); for (int y = 0; y < textHeight; y++) { for (int x = 0; x < textWidth; x++) { index = 4 * (y * textWidth + x); vscanBuffer[index] = milBuffer[index]; vscanBuffer[index + 1] = milBuffer[index + 1]; vscanBuffer[index + 2] = milBuffer[index + 2]; vscanBuffer[index + 3] = milBuffer[index + 3]; } } } imageUtil.GetSetPixelUnsafeCommit(); retVal = new ImageAdapter(imageUtil.Bitmap32Bits); } return(retVal); }