And so, the disposition is as follows: There is an Image (control) with a size of 100 by 100. The image is set to 100 by 100 as the image source.

In runtime, I translate Image into BitMap and save it to a file with the following code:

int width = (int)image.ActualWidth; int height = (int)image.ActualHeight; RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Default); rtb.Render(image); BmpBitmapEncoder encoder = new BmpBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(rtb)); MemoryStream ms = new MemoryStream(); encoder.Save(ms); ms.Position = 0; Bitmap CurentPrintLabelImg = new Bitmap(ms); CurentPrintLabelImg.Save("Test.bmp"); 

As a result, I expect that at the output I will receive an image of 100 by 100 absolutely identical to sorsy. But I get an image with grayscale on the borders of black areas. (looks like a blur)

Also noticed that image.ActualWidth and image.ActualHeight are less than 100 (~ 99 and 98)

How to achieve the coincidence of the original and the output image and why the control is scaled in runtime?

  • Uh, what are you doing? Why do you save the view, not the model? Save your Image.Source . - VladD
  • @VladD: I understandably slightly simplified the problem. I can replace the image with an outline in which such images will be pieces 5 + text + something handwritten by a juzverem and I will need to save all this into a picture without resizing, translating into gray gradations and quality loss ... - Alexey
  • Anyway, this is somehow wrong. You are trying to save the View, and you should in theory have all these objects in the model, and save in it. To (a) not hang UI at the time of preservation, (b) not depend on the characteristics of the rendering, (c) well, in general, so it seems more correct. - VladD
  • OK. Let's say. I have pictures in the model, the text and path that yuzver painted something there. Now the whole thing I need to build the way it looked on the screen in the canvas and save it in the picture ... To draw all this turn the Graphics? - Alexey
  • Well or through WritableBitmap , Drawing , RenderTargetBitmap and so on. Type this: stackoverflow.com/a/14387686/276994 . Here you certainly control all sizes, and you can separate this part from the presentation - VladD

0