public static MemBitmap CopyImgBuffer(this MemBitmap src, int srcX, int srcY, int srcW, int srcH) { //simple copy Rectangle orgSourceRect = new Rectangle(0, 0, src.Width, src.Height); Rectangle requestRect = new Rectangle(srcX, srcY, srcW, srcH); Rectangle toCopyRect = Rectangle.Intersect(new Rectangle(0, 0, src.Width, src.Height), new Rectangle(srcX, srcY, srcW, srcH)); if (toCopyRect.Width == 0 || toCopyRect.Height == 0) { return(null); } //----- MemBitmap copyBmp = new MemBitmap(toCopyRect.Width, toCopyRect.Height); unsafe { using (CpuBlit.Imaging.TempMemPtr srcBufferPtr = MemBitmap.GetBufferPtr(src)) using (CpuBlit.Imaging.TempMemPtr dstBufferPtr = MemBitmap.GetBufferPtr(copyBmp)) { int *srcPtr = (int *)srcBufferPtr.Ptr; int *dstPtr = (int *)dstBufferPtr.Ptr; int lineEnd = srcY + srcH; int orgSrcW = src.Width; for (int line = toCopyRect.Top; line < toCopyRect.Bottom; ++line) { NativeMemMx.memcpy((byte *)dstPtr, (byte *)(srcPtr + ((line * orgSrcW) + toCopyRect.Left)), toCopyRect.Width * 4); dstPtr += toCopyRect.Width; } } } return(copyBmp); }
public static int[] CopyImgBuffer(MemBitmap memBmp, int width, int height) { //calculate stride for the width int destStride = MemBitmap.CalculateStride(width, CpuBlit.Imaging.PixelFormat.ARGB32); int newBmpW = destStride / 4; int[] buff2 = new int[newBmpW * height]; unsafe { using (CpuBlit.Imaging.TempMemPtr srcBufferPtr = MemBitmap.GetBufferPtr(memBmp)) { byte* srcBuffer = (byte*)srcBufferPtr.Ptr; int srcIndex = 0; int srcStride = memBmp.Stride; fixed (int* destHead = &buff2[0]) { byte* destHead2 = (byte*)destHead; for (int line = 0; line < height; ++line) { //System.Runtime.InteropServices.Marshal.Copy(srcBuffer, srcIndex, (IntPtr)destHead2, destStride); NativeMemMx.memcpy((byte*)destHead2, srcBuffer + srcIndex, destStride); srcIndex += srcStride; destHead2 += destStride; } } } } return buff2; }
public override void SaveImage(MemBitmap bitmap, Stream output, OutputImageFormat outputFormat, object saveParameters) { //save img to using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bitmap.Width, bitmap.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); unsafe { byte *ptr = (byte *)MemBitmap.GetBufferPtr(bitmap).Ptr; MemMx.memcpy((byte *)bmpdata.Scan0, ptr, bmpdata.Stride * bmp.Height); } bmp.UnlockBits(bmpdata); //save to stream System.Drawing.Imaging.ImageFormat format = null; switch (outputFormat) { case OutputImageFormat.Default: throw new NotSupportedException(); case OutputImageFormat.Jpeg: format = System.Drawing.Imaging.ImageFormat.Jpeg; break; case OutputImageFormat.Png: format = System.Drawing.Imaging.ImageFormat.Png; break; } bmp.Save(output, format); } }
public unsafe static TempMemPtr FromBmp(MemBitmap bmp, out byte *headPtr) { TempMemPtr ptr = MemBitmap.GetBufferPtr(bmp); headPtr = (byte *)ptr.Ptr; return(ptr); }
public override void DrawImage(Image img) { MemBitmap memBmp = img as MemBitmap; if (memBmp == null) { //? TODO return; } if (_renderQuality == RenderQuality.Fast) { //todo, review here again TempMemPtr tmp = MemBitmap.GetBufferPtr(memBmp); BitmapBuffer srcBmp = new BitmapBuffer(img.Width, img.Height, tmp.Ptr, tmp.LengthInBytes); //_bxt.BlitRender(srcBmp, false, 1, null); //_bxt.Blit(0, 0, srcBmp.PixelWidth, srcBmp.PixelHeight, srcBmp, 0, 0, srcBmp.PixelWidth, srcBmp.PixelHeight, // ColorInt.FromArgb(255, 255, 255, 255), // BitmapBufferExtensions.BlendMode.Alpha); _bxt.FastAlphaBlit(0, 0, srcBmp, 0, 0, srcBmp.PixelWidth, srcBmp.PixelHeight); return; } //------------------------------- bool useSubPix = UseSubPixelLcdEffect; //save, restore later... //before render an image we turn off vxs subpixel rendering this.UseSubPixelLcdEffect = false; _aggsx.Render(memBmp, null as AffinePlan[]); //restore... this.UseSubPixelLcdEffect = useSubPix; }
public unsafe static TempMemPtr FromBmp(MemBitmap memBmp, out int *headPtr) { TempMemPtr ptr = MemBitmap.GetBufferPtr(memBmp); headPtr = (int *)ptr.Ptr; return(ptr); }
public static void dbugSaveToPngFile(this MemBitmap bmp, string filename) { SaveImgBufferToPngFile(MemBitmap.GetBufferPtr(bmp), bmp.Stride, bmp.Width, bmp.Height, filename); }
PaintFx.Surface CreateSurfaceFromMemBitmap(MemBitmap memBmp) { var tmpBuffer = MemBitmap.GetBufferPtr(memBmp); PaintFx.MemHolder holder = new PaintFx.MemHolder(tmpBuffer.Ptr, tmpBuffer.LengthInBytes); PaintFx.Surface surface = new PaintFx.Surface(memBmp.Stride, memBmp.Width, memBmp.Height, holder); return(surface); }
public static void CopyFromGdiPlusBitmapSameSize( Bitmap windowsBitmap, MemBitmap actualImage) { int h = windowsBitmap.Height; int w = windowsBitmap.Width; //byte[] targetBuffer = ActualImage.GetBuffer(actualImage); BitmapData bitmapData1 = windowsBitmap.LockBits( new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, windowsBitmap.PixelFormat); IntPtr scan0 = bitmapData1.Scan0; int stride = bitmapData1.Stride; //TODO: review here //use buffer copy unsafe { //target TempMemPtr targetMemPtr = MemBitmap.GetBufferPtr(actualImage); byte * target = (byte *)targetMemPtr.Ptr; int startRowAt = ((h - 1) * stride); byte * src = (byte *)scan0; for (int y = h; y > 0; --y) { // byte* target = targetH + ((y - 1) * stride); //System.Runtime.InteropServices.Marshal.Copy( // (IntPtr)src,//src // targetBuffer, startRowAt, stride); MemMx.memcpy(target + startRowAt, src, stride); startRowAt -= stride; src += stride; } targetMemPtr.Dispose(); ////////////////////////////////////////////////////////////////// //fixed (byte* targetH = &targetBuffer[0]) //{ // byte* src = (byte*)scan0; // for (int y = h; y > 0; --y) // { // byte* target = targetH + ((y - 1) * stride); // for (int n = stride - 1; n >= 0; --n) // { // *target = *src; // target++; // src++; // } // } //} } windowsBitmap.UnlockBits(bitmapData1); }
public void SetImageAttributes(LoadedImageAttributes parameters) { _imgWidth = parameters.Width; _imgHeight = parameters.Height; _component = parameters.Components; _bitStream = new BitStream(); _memBmp = new MemBitmap(_imgWidth, _imgHeight); _tempMemPtr = MemBitmap.GetBufferPtr(_memBmp); }
public void SetBitmap(MemBitmap bmp) { _width = bmp.Width; _height = bmp.Height; _widthLim = _width - 1; unsafe { _curAddr = _bufferPtr = (int *)MemBitmap.GetBufferPtr(bmp).Ptr; } }
public override MemBitmap ScaleImage(MemBitmap bitmap, float x_scale, float y_scale) { //scale using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(bitmap.Width, bitmap.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)) { var bmpdata = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); unsafe { byte *ptr = (byte *)MemBitmap.GetBufferPtr(bitmap).Ptr; PixelFarm.Drawing.Internal.MemMx.memcpy((byte *)bmpdata.Scan0, ptr, bmpdata.Stride * bmp.Height); } bmp.UnlockBits(bmpdata); // int new_w = (int)Math.Round(bitmap.Width * x_scale); int new_h = (int)Math.Round(bitmap.Height * y_scale); if (new_w < 64 && new_h < 64) { using (System.Drawing.Bitmap scaledBmp = (System.Drawing.Bitmap)bmp.GetThumbnailImage(new_w, new_h, null, IntPtr.Zero)) { #if DEBUG //scaledBmp.Save("thumb01.png"); #endif //copy var bmpdata2 = scaledBmp.LockBits(new System.Drawing.Rectangle(0, 0, new_w, new_h), System.Drawing.Imaging.ImageLockMode.ReadOnly,//***read System.Drawing.Imaging.PixelFormat.Format32bppArgb); MemBitmap newMemBitmap = MemBitmap.CreateFromCopy(new_w, new_h, new_w * new_h * 4, bmpdata2.Scan0); scaledBmp.UnlockBits(bmpdata2); #if DEBUG //newMemBitmap.SaveImage("thumb01_1.png"); #endif return(newMemBitmap); } } else { using (System.Drawing.Bitmap scaledBmp = new System.Drawing.Bitmap(bmp, new_w, new_h)) { //copy var bmpdata2 = scaledBmp.LockBits(new System.Drawing.Rectangle(0, 0, new_w, new_h), System.Drawing.Imaging.ImageLockMode.ReadOnly, //***read System.Drawing.Imaging.PixelFormat.Format32bppArgb); MemBitmap newMemBitmap = MemBitmap.CreateFromCopy(new_w, new_h, new_w * new_h * 4, bmpdata2.Scan0); scaledBmp.UnlockBits(bmpdata2); return(newMemBitmap); } } } }
public static RadialGradientBrush Resolve(Drawing.RadialGradientBrush radGradientBrush) { RadialGradientBrush glGradient = radGradientBrush.InnerBrush as RadialGradientBrush; if (glGradient == null) { //temp fix //check if some color stop has alpha //create a new one Build(radGradientBrush, out float[] v2f); glGradient = new RadialGradientBrush(v2f); ColorStop[] colorStops = radGradientBrush.ColorStops; for (int i = 0; i < colorStops.Length; ++i) { ColorStop stop = radGradientBrush.ColorStops[i]; if (stop.Color.A < 255 * 0.8) //temp fix 0.8 { glGradient._hasSignificateAlphaCompo = true; break; } } //create a single horizontal line linear gradient bmp //for texture look up //create MemBitmap for this lookup table GradientSpanGenExtensions.GenerateSampleGradientLine(radGradientBrush, out Color[] sampleColors); MemBitmap lookupBmp = new MemBitmap(sampleColors.Length, 1);//1 pixel height unsafe { int *ptr = (int *)MemBitmap.GetBufferPtr(lookupBmp).Ptr; for (int i = 0; i < sampleColors.Length; ++i) { Color c = sampleColors[i]; * ptr = (int)c.ToABGR(); ptr++; } } glGradient._lookupBmp = new GLBitmap(lookupBmp, true); glGradient._cx = radGradientBrush.StartPoint.X; glGradient._cy = radGradientBrush.StartPoint.Y; glGradient._r = (float)radGradientBrush.Length; if (radGradientBrush.CoordTransformer != null) { glGradient._invertedAff = (PixelFarm.CpuBlit.VertexProcessing.Affine)radGradientBrush.CoordTransformer.CreateInvert(); } radGradientBrush.InnerBrush = glGradient; } return(glGradient); }
public static void dbugSaveToJpgFile(this MemBitmap bmp, string filename) { TempMemPtr tmpMem = MemBitmap.GetBufferPtr(bmp); SaveImgBufferToJpgFileUnsafe(tmpMem, bmp.Stride, bmp.Width, bmp.Height, filename); tmpMem.Dispose(); }
public override void SetClipboardImage(Image img) { if (img is MemBitmap memBmp) { System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(memBmp.Width, memBmp.Height); using (TempMemPtr tmp = MemBitmap.GetBufferPtr(memBmp)) { BitmapHelper.CopyToGdiPlusBitmapSameSize(tmp.Ptr, bmp); } } }
public void SetSourceBitmap(MemBitmap bmpSrc) { ((IPixelEvaluator)this).SetSourceDimension(bmpSrc.Width, bmpSrc.Height); var memPtr = MemBitmap.GetBufferPtr(bmpSrc); unsafe { _currentAddr = _destBuffer = (int *)memPtr.Ptr; } OnSetSoureBitmap(); }
void BlendScanline(MemBitmap dstBmp, byte[] expandGreyBuffer, PixelFarm.Drawing.Color color, int x, int y, int width) { byte[] rgb = new byte[3] { color.R, color.G, color.B }; //------------------------- //destination CpuBlit.Imaging.TempMemPtr memPtr = MemBitmap.GetBufferPtr(dstBmp); //start pixel int destImgIndex = (x * 4) + (dstBmp.Stride * y); //start img src int srcImgIndex = x + (width * y); int colorIndex = 0; int round = 0; byte color_a = color.alpha; unsafe { byte *destImgBuffer = (byte *)memPtr.Ptr; while (width > 3) { int a0 = expandGreyBuffer[srcImgIndex] * color_a; int a1 = expandGreyBuffer[srcImgIndex + 1] * color_a; int a2 = expandGreyBuffer[srcImgIndex + 2] * color_a; byte ec0 = destImgBuffer[destImgIndex]; //existing color byte ec1 = destImgBuffer[destImgIndex + 1]; //existing color byte ec2 = destImgBuffer[destImgIndex + 2]; //existing color //------------------------------------------------------ //please note that we swap a2 and a0 on the fly**** //------------------------------------------------------ byte n0 = (byte)((((rgb[colorIndex] - ec0) * a2) + (ec0 << 16)) >> 16); byte n1 = (byte)((((rgb[colorIndex + 1] - ec1) * a1) + (ec1 << 16)) >> 16); byte n2 = (byte)((((rgb[colorIndex + 2] - ec2) * a0) + (ec2 << 16)) >> 16); destImgBuffer[destImgIndex] = n0; destImgBuffer[destImgIndex + 1] = n1; destImgBuffer[destImgIndex + 2] = n2; destImgIndex += 4; round = 0; colorIndex = 0; srcImgIndex += 3; width -= 3; } memPtr.Dispose(); } }
static byte[] CreateGreyScaleBuffer(MemBitmap bmp) { //assume img is 32 rgba img int imgW = bmp.Width; int height = bmp.Height; //56 level grey scale buffer CpuBlit.Imaging.TempMemPtr srcMemPtr = MemBitmap.GetBufferPtr(bmp); int greyScaleBufferLen = imgW * height; byte[] greyScaleBuffer = new byte[greyScaleBufferLen]; int destIndex = 0; int srcImgIndex = 0; int srcImgStride = bmp.Stride; unsafe { byte *srcImgBuffer = (byte *)srcMemPtr.Ptr; for (int y = 0; y < height; ++y) { srcImgIndex = srcImgStride * y; destIndex = imgW * y; for (int x = 0; x < imgW; ++x) { byte r = srcImgBuffer[srcImgIndex]; byte g = srcImgBuffer[srcImgIndex + 1]; byte b = srcImgBuffer[srcImgIndex + 2]; byte a = srcImgBuffer[srcImgIndex + 3]; if (r != 0 || g != 0 || b != 0) { } if (a != 255) { } //skip alpha //byte greyScaleValue = // (byte)((0.333f * (float)r) + (0.5f * (float)g) + (0.1666f * (float)b)); greyScaleBuffer[destIndex] = (byte)(((a + 1) / 256f) * 64f); destIndex++; srcImgIndex += 4; } } } srcMemPtr.Dispose(); return(greyScaleBuffer); }
protected void Attach(MemBitmap bmp, PixelBlender32 pixelBlender = null) { if (pixelBlender == null) { //use default pixel blender ? if (_defaultPixelBlender == null) { _defaultPixelBlender = new PixelBlenderBGRA(); } pixelBlender = _defaultPixelBlender; } Attach(bmp.Width, bmp.Height, bmp.BitDepth, MemBitmap.GetBufferPtr(bmp), pixelBlender); }
/// <summary> /// copy from actual image direct to hBmpScan0 /// </summary> /// <param name="memBmp"></param> /// <param name="hBmpScan0"></param> public static void CopyToWindowsBitmapSameSize( MemBitmap memBmp, IntPtr hBmpScan0) { //1st, fast CpuBlit.Imaging.TempMemPtr tmp = MemBitmap.GetBufferPtr(memBmp); //System.Runtime.InteropServices.Marshal.Copy(rawBuffer, 0, // hBmpScan0, rawBuffer.Length); unsafe { NativeMemMx.memcpy((byte *)hBmpScan0, (byte *)tmp.Ptr, tmp.LengthInBytes); } }
public static int[] CopyImgBuffer(this MemBitmap memBmp, int width, int height, bool flipY = false) { //calculate stride for the width int destStride = MemBitmap.CalculateStride(width, PixelFormat.ARGB32); int newBmpW = destStride / 4; int[] buff2 = new int[newBmpW * height]; unsafe { using (TempMemPtr srcBufferPtr = MemBitmap.GetBufferPtr(memBmp)) { byte *srcBuffer = (byte *)srcBufferPtr.Ptr; int srcIndex = 0; int srcStride = memBmp.Stride; if (flipY) { fixed(int *destHead = &buff2[0]) { byte *destHead2 = (byte *)destHead; srcBuffer += (height - 1) * srcStride; for (int line = 0; line < height; ++line) { //System.Runtime.InteropServices.Marshal.Copy(srcBuffer, srcIndex, (IntPtr)destHead2, destStride); MemMx.memcpy((byte *)destHead2, srcBuffer + srcIndex, destStride); srcIndex -= srcStride; destHead2 += destStride; } } } else { fixed(int *destHead = &buff2[0]) { byte *destHead2 = (byte *)destHead; for (int line = 0; line < height; ++line) { //System.Runtime.InteropServices.Marshal.Copy(srcBuffer, srcIndex, (IntPtr)destHead2, destStride); MemMx.memcpy((byte *)destHead2, srcBuffer + srcIndex, destStride); srcIndex += srcStride; destHead2 += destStride; } } } } } return(buff2); }
/// <summary> /// copy from actual image direct to hBmpScan0 /// </summary> /// <param name="actualImage"></param> /// <param name="hBmpScan0"></param> public static void CopyToWindowsBitmapSameSize( MemBitmap actualImage, IntPtr hBmpScan0) { //1st, fast //byte[] rawBuffer = ActualImage.GetBuffer(actualImage); unsafe { TempMemPtr memPtr = MemBitmap.GetBufferPtr(actualImage); MemMx.memcpy((byte *)hBmpScan0, (byte *)memPtr.Ptr, actualImage.Stride * actualImage.Height); memPtr.Dispose(); } //System.Runtime.InteropServices.Marshal.Copy(rawBuffer, 0, // hBmpScan0, rawBuffer.Length); }
public static int[] CopyImgBuffer(MemBitmap memBmp) { int[] buff2 = new int[memBmp.Width * memBmp.Height]; unsafe { using (CpuBlit.Imaging.TempMemPtr pixBuffer = MemBitmap.GetBufferPtr(memBmp)) { //fixed (byte* header = &pixelBuffer[0]) byte *header = (byte *)pixBuffer.Ptr; { System.Runtime.InteropServices.Marshal.Copy((IntPtr)header, buff2, 0, buff2.Length);//length in bytes } } } return(buff2); }
public override MemBitmap LoadImage(Stream input) { using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(input)) { var bmpData2 = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); MemBitmap memBitmap = new MemBitmap(bmp.Width, bmp.Height); unsafe { byte *dst = (byte *)MemBitmap.GetBufferPtr(memBitmap).Ptr; MemMx.memcpy(dst, (byte *)bmpData2.Scan0, bmpData2.Stride * bmpData2.Height); } return(memBitmap); } }
void DrawBitmap(MemBitmap memBmp, double left, double top, int srcX, int srcY, int srcW, int srcH) { //check image caching system if (_renderQuality == RenderQuality.Fast) { TempMemPtr tmp = MemBitmap.GetBufferPtr(memBmp); unsafe { BitmapBuffer srcBmp = new BitmapBuffer(memBmp.Width, memBmp.Height, tmp.Ptr, tmp.LengthInBytes); try { var src = new BitmapBufferEx.RectD(srcX, srcY, srcW, srcH); var dest = new BitmapBufferEx.RectD(left, top, srcW, srcH); BitmapBuffer bmpBuffer = new BitmapBuffer(memBmp.Width, memBmp.Height, tmp.Ptr, tmp.LengthInBytes); _bxt.CopyBlit(dest, bmpBuffer, src); } catch (Exception ex) { } } return; } //save, restore later... bool useSubPix = UseSubPixelLcdEffect; //before render an image we turn off vxs subpixel rendering this.UseSubPixelLcdEffect = false; if (_orientation == RenderSurfaceOrientation.LeftTop) { //place left upper corner at specific x y _aggsx.Render(memBmp, left, this.Height - (top + memBmp.Height), srcX, srcY, srcW, srcH); } else { //left-bottom as original //place left-lower of the img at specific (x,y) _aggsx.Render(memBmp, left, top, srcX, srcY, srcW, srcH); } //restore... this.UseSubPixelLcdEffect = useSubPix; }
/// <summary> /// copy from mem image direct to hBmpScan0 /// </summary> /// <param name="srcMemBmp"></param> /// <param name="dstHBmpScan0"></param> public static void CopyToWindowsBitmapSameSize( MemBitmap srcMemBmp, IntPtr dstHBmpScan0) { //1st, fast //byte[] rawBuffer = ActualImage.GetBuffer(actualImage); TempMemPtr memPtr = MemBitmap.GetBufferPtr(srcMemBmp); unsafe { PixelFarm.Drawing.Internal.MemMx.memcpy((byte *)dstHBmpScan0, (byte *)memPtr.Ptr, srcMemBmp.Stride * srcMemBmp.Height); } //System.Runtime.InteropServices.Marshal.Copy(rawBuffer, 0, // hBmpScan0, rawBuffer.Length); memPtr.Dispose(); }
public static void Save(MemBitmap bmp, Stream strm) { //------------- unsafe { PixelFarm.CpuBlit.Imaging.TempMemPtr tmp = MemBitmap.GetBufferPtr(bmp); int *intBuffer = (int *)tmp.Ptr; int imgW = bmp.Width; int imgH = bmp.Height; Hjg.Pngcs.ImageInfo imgInfo = new Hjg.Pngcs.ImageInfo(imgW, imgH, 8, true); //8 bits per channel with alpha Hjg.Pngcs.PngWriter writer = new Hjg.Pngcs.PngWriter(strm, imgInfo); Hjg.Pngcs.ImageLine iline = new Hjg.Pngcs.ImageLine(imgInfo, Hjg.Pngcs.ImageLine.ESampleType.BYTE); int startReadAt = 0; int imgStride = imgW * 4; int srcIndex = 0; int srcIndexRowHead = (tmp.LengthInBytes / 4) - imgW; for (int row = 0; row < imgH; row++) { byte[] scanlineBuffer = iline.ScanlineB; srcIndex = srcIndexRowHead; for (int b = 0; b < imgStride;) { int srcInt = intBuffer[srcIndex]; srcIndex++; scanlineBuffer[b] = (byte)((srcInt >> 16) & 0xff); scanlineBuffer[b + 1] = (byte)((srcInt >> 8) & 0xff); scanlineBuffer[b + 2] = (byte)((srcInt) & 0xff); scanlineBuffer[b + 3] = (byte)((srcInt >> 24) & 0xff); b += 4; } srcIndexRowHead -= imgW; startReadAt += imgStride; writer.WriteRow(iline, row); } writer.End(); } }
void CopyBitmapToScreen() { if (_memBmp == null) { return; } //------- //copy from mem bitmap to native bitmap var bmp_data = _myBitmap.LockBits(new System.Drawing.Rectangle(0, 0, _myBitmap.Width, _myBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (var tmpMemPtr = MemBitmap.GetBufferPtr(_memBmp)) { unsafe { PixelFarm.Drawing.Internal.MemMx.memcpy((byte *)bmp_data.Scan0, (byte *)tmpMemPtr.Ptr, tmpMemPtr.LengthInBytes); } } _myBitmap.UnlockBits(bmp_data); _g.DrawImage(_myBitmap, 0, 0); }
public static int[] CopyImgBuffer(MemBitmap src, int srcX, int srcY, int srcW, int srcH) { //calculate stride for the width int destStride = MemBitmap.CalculateStride(srcW, CpuBlit.Imaging.PixelFormat.ARGB32); int newBmpW = destStride / 4; int[] buff2 = new int[newBmpW * srcH]; unsafe { using (CpuBlit.Imaging.TempMemPtr srcBufferPtr = MemBitmap.GetBufferPtr(src)) { byte* srcBuffer = (byte*)srcBufferPtr.Ptr; int srcIndex = 0; int srcStride = src.Stride; fixed (int* destHead = &buff2[0]) { byte* destHead2 = (byte*)destHead; //move to specific src line srcIndex += srcStride * srcY; int lineEnd = srcY + srcH; for (int line = srcY; line < lineEnd; ++line) { //System.Runtime.InteropServices.Marshal.Copy(srcBuffer, srcIndex, (IntPtr)destHead2, destStride); NativeMemMx.memcpy((byte*)destHead2, srcBuffer + srcIndex, destStride); srcIndex += srcStride; destHead2 += destStride; } } } } return buff2; }
static System.Drawing.Bitmap CreatePlatformBitmap(MemBitmap memBmp) { System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( memBmp.Width, memBmp.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); var srcPtr = MemBitmap.GetBufferPtr(memBmp); var bmpdata = bmp.LockBits( new System.Drawing.Rectangle(0, 0, memBmp.Width, memBmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb); unsafe { MemMx.memcpy( (byte *)bmpdata.Scan0, (byte *)srcPtr.Ptr, srcPtr.LengthInBytes); } bmp.UnlockBits(bmpdata); return(bmp); }