void CopyToOriginalImage() { if (SourceImage != null && DrawingImage != null) { // copy back to original image when format is incompatible with CoreGraphics using (var bdNew = DrawingImage.Lock()) using (var bdOrig = SourceImage.Lock()) { var size = DrawingImage.Size; for (int y = 0; y < size.Height; y++) { for (int x = 0; x < size.Width; x++) { bdOrig.SetPixel(x, y, bdNew.GetPixel(x, y)); } } } } }
void CopyToOriginalImage() { if (SourceImage != null && DrawingImage != null) { // copy back to original image when format is incompatible with CoreGraphics using (var bdNew = DrawingImage.Lock()) using (var bdOrig = SourceImage.Lock()) { var size = DrawingImage.Size; if (bdNew.BitsPerPixel == 32 && bdOrig.BitsPerPixel == 24) { unsafe { // assuming rgb is in same order as 32bpp bitmap, should be.. var src = (byte *)bdNew.Data; var dest = (byte *)bdOrig.Data; var length = size.Width * size.Height; for (int i = 0; i < length; i++) { *(dest++) = *(src++); *(dest++) = *(src++); *(dest++) = *(src++); src++; // ignore alpha } } } else { for (int y = 0; y < size.Height; y++) { for (int x = 0; x < size.Width; x++) { bdOrig.SetPixel(x, y, bdNew.GetPixel(x, y)); } } } } } }