Windows Forms drawing not saving
When im drawing on the picturebox (pageImage) and im saving, the data is not saved
39 Replies
how i create Graphics instance
look at PageImage_MouseUp event
im able to draw on the window, but when it comes to save, it does not work
isDrawing
ever get set to false?the image does not change, it keep original and the drawing does not affect
like on the picturebox i see that i drew but when it comes to save it to a file the changes dont applies
When you are drawing, I believe the drawing data gets saved to the
g
object. When you save, it looks like you're just saving the page but that doesn't contain the data which you drew
Maybe I'm wrong?i think so, but then how can i save the Graphics too?
Are you able to convert
g
to a bitmap or image object?uh i think
Stack Overflow
Convert graphics object to bitmap object
How can I convert graphics object to bitmap object using C#?
Graphics Class (System.Drawing)
Encapsulates a GDI+ drawing surface. This class cannot be inherited.
Check out the documentation, I'm sure one of the methods will help you out here
The second answer in the stackoverflow page sounds promising:
Bitmap bmp = new Bitmap(100,100,graphics);
@MonJamp it just save a blank page
Bitmap bitmap = new Bitmap(pageImage.Width, pageImage.Height, g);
without the drawing
man idk
thank you for trying to help
For sure
There are many different ways you could go about to implement this, I'm not too familiar with how to use the
Graphics
object but maybe the best approach would be to save the pixel data in an array as you're drawing - just an idea
Good luckYou're saving
pageImage
not its Graphics
created instance called g
Ye that's what we figured out before, the difficulty is saving the Graphics object to a bitmap
And combining both the pageImage and g
then how can i combine these 2 instance to save them in one file?
Try this
Create a new Bitmap that has your image
new Bitmap(pageImage.Image)
Create the Graphics from this bitmap Graphics.FromImage(bitmap)
Set pageImage.Image = bitmap
Draw as you normally would, but call pageImage.Invalidate()
at the end so it can display changes
Then on save you want to bitmap.Save(pageImage.ImageLocation, ...)
@Nasdack "A generic error occurred in GDI+" when the mouseUp event if fired :
when it tries to save the image
drawingBitmap = new Bitmap(pageImage.ImageLocation);
can that be .Image
insteadi dont think so cause im setting the with with ImageLocation
ive found this idk this ay workshttps://www.youtube.com/watch?v=bp9PzpGZsWA
this error happens when the file is in use
try to save to a different location
already tried
using g = ...
this would dispose it
but
that's not what we wantim not using "using"
?
pageImage.Image?.Dispose();
try this before savingsame error
and its not even drawing anything in the two case
if you draw nothing happens?
when i move the cursor its not drawingbut when i up the mouse it says the error
the lines are not drawing
but i think its bc of the errors u know
How to: Create Graphics Objects for Drawing - Windows Forms .NET Fr...
Learn now to create a Graphic object that you need to draw lines and shapes, render text, or display and manipulate images with GDI+.
I found this and
if you follow it through
and rewrite your code
it should be errorless
i dont see nothing wrong
this is full code, read the class constructor and the end of the code
@Nasdack do you see anything wrong ?
the error has to do with saving the file
nothing else
make sure you're saving to another location
nah not the issue
what's the issue
send a screenshot
with details
ok
@Nasdack
Scrap this codebase
It's a mess
Just follow the tutorial here