Click here to Skip to main content
15,918,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a picturebox in my form and draw shapes in picturebox by MouseDown and MouseUp events.
finally I must save image of picturebox with drawn shapes in TIFF File. I use this codes:
VB
<pre>     Dim bitmap = New Bitmap(PictureBox1.Width, PictureBox1.Height)
        PictureBox1.DrawToBitmap(bitmap, PictureBox1.ClientRectangle)
        Dim PATH = Application.StartupPath & "\TIFF\" & My.Settings.PATH & ".TIFF"
        bitmap.Save(PATH, System.Drawing.Imaging.ImageFormat.Tiff)

But the clarity and quality of the TIF image is much lower than the original image. I will link a part of the original image and the TIIF for Comparison.

What I have tried:

 I will link a part of the original image and the TIIF for Comparison<a href=""></a><a href="https://s2.uupload.ir/files/a2_gv3i.jpg">https://s2.uupload.ir/files/a2_gv3i.jpg</a>[<a href="https://s2.uupload.ir/files/a2_gv3i.jpg" target="_blank" title="New Window">^</a>]
<a href=""></a><a href="https://s2.uupload.ir/files/a11_ikaz.jpg">https://s2.uupload.ir/files/a11_ikaz.jpg</a>[<a href="https://s2.uupload.ir/files/a11_ikaz.jpg" target="_blank" title="New Window">^</a>]
Posted
Updated 11-Dec-22 1:46am
v2

1 solution

Simple: don't draw on the PictureBox, draw on the Image it contains and Invalidate the PictureBox to display the changes.

You can then save the Image directly to a disk file without any loss of quality (because you are using TIFF files, and that is a lossless image format - JPG isn't, so each time you save the image, you lose detail).
 
Share this answer
 
Comments
moshaveran 12-Dec-22 2:00am    
It was a great offer. But there is a problem:
If we zoom-in or zoom-out the image before drawing the shapes, the shapes will not be drawn in their exact place!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900