473,394 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to save a file from a Panel? (complicated sorta)

Ok so i was following this tutorial here: http://www.youtube.com/watch?v=Ezea99FtCCE to make a little paint software. But When I go to save the picture on the Panel (not a PictureBox) It only saves the image or a blank file. Not the drawings i made. So i need help so it saves the image and the drawing. I dont know what code i have to paste since its basically the same as the videos.
Except i save the images as jpgs or pngs.
Feb 5 '11 #1
4 5077
HaLo2FrEeEk
404 256MB
Well, apart from the fact that that "tutorial" was completely...crap, I think I can help you. I don't know how exactly you're drawing on your panel. Are you using the mousedown/mouseup event handlers and a graphics object? If so then the solution should be pretty simple. Within the method that saves the image, after you draw the panel to the bitmap, use the graphics object to redraw your drawing to the bitmap.

Take a look at this program I wrote and look at the File > Save to PNG option:

http://infectionist.com/extras/cshar...Test_2.2.0.zip

Click and hld your mouse to start drawing. Scroll the wheel to resize the pen, release the mouse button to stop drawing. Right click to change either the bakground or pen color. Look at the options in the "Options" menu. As you draw each point that your mouse moves to is saved to a list, along with the amount of time between the current point and the previous point. This allows you to draw the drawing back, with the exact same timing as when it was first drawn, if you select that option. Is this something like what you're looking for?

(make sure you do the Save to PNG option, not just "Save", that option will save the drawing to a .draw file that will only open in this program.)
Feb 5 '11 #2
How about i upload my project. Because its a bit differnet...
Attached Files
File Type: zip ImagePaint.zip (51.7 KB, 392 views)
Feb 5 '11 #3
HaLo2FrEeEk
404 256MB
It's not complicated, you're just not doing things right. There area few ways you can fix this.

The first is by keeping a list of points that the user has drawn, then when you go to save loop though that list and draw each of those points to your bitmap (the one that you get from the panel1.DrawToBitmap() method). That's a better choice.

The second option is create a global Bitmap and Graphics object, call their constructors in the Form constructor (Form1()). Construct the bitmap to be the same width and height of the panel. set panel1's backgroundimage to the bitmap. Finally, Set the graphics object to Graphics.fromImage(panel1.BackgroundImage).

Now, in your mouse move event remove the Graphics g = panel1.CreateGraphics() and g.Dispose() calls (that's where you were going wrong), just do the g.Fillllipse(), then add this line:

panel1.Invalidate(new Rectangle(e.x, e.y, 10, 10));

Which will force the panel to repaint itself when you draw a point.

Finally in your loadToolStripMenuIem_Click event handler, comment out the panel1.BackgroundImage = Im line and add this one:

g.DrawImage(Im, 0, 0, panel1.Width, panel1.Height);

Basically what you're doing is creating a bitmap the same size as the panel, setting it as the background image, then creating a graphics object out of that image. Using any of the Graphics methods will draw to the bitmap (which is the panel's background image). You're literally drawing directly onto the background image. In your save event comment ut everything in the try block and do this:

panel1.BackgroundImage.Save(save.FileName);

That's it. Now, keep in mind, this is a hacked together solution so that I wouldn't have to modify too much of your existing code. There are MUCH better (more efficient) ways of doing this (like the first option I gave you). I really recommend you take another look at my application, turn on the file list option and watch what happens as you draw. The source code for that program is available, but I don't want to give it to you just yet. Play around with what I've taught you here and see if you can learn anything.
Feb 6 '11 #4
Thanks that helped. I would like to see your code.
Feb 6 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: juli jul | last post by:
Hello,how can I override(save) file in c#? (I am working with XmlDocumnet) Thanks! *** Sent via Developersdex http://www.developersdex.com ***
9
by: Ivan Demkovitch | last post by:
Hi! I would like to know if I can save File on Server using server-side code? For example, I like to create thumbnail images and populate specific directory. Do I need specific permissions...
1
by: Kapil | last post by:
Hi All can u tell me how to save dynamically generated file in asp.net. like save file dialog in asp.net. kapil
6
by: Mike | last post by:
can i open the save file dialog box from a asp.net web page? thx
4
by: Jonny | last post by:
Hello Group How do I open a Save File Dialog from an ASPX page behind a browse button? Any help would be fantastic!! I am using ASP.NET 1.1 using VB.NET as the coding language TIA
3
by: mse07 | last post by:
hi for every one i want to save text file in specified bath without show the save window i write code that save file but that code show save window : CommonDialog1.FileName =...
2
by: AccessHunter | last post by:
Hi, In my VBA code I am saving an excel spreadsheet with data from a table. I would like to prompt the Save File or Save As Dialog box with a default File Name, after opening the spreadsheet. ...
3
by: vedika | last post by:
hi, I created one application in which there is export functionality. I am using sqlCE as database . When user click on "export" a save file dialog appeare and file saved in html format from...
2
by: simonyong | last post by:
Hello, anyone I had search for few days with how to save file when user choose a file name from listbox and i will search the file from database and user can save it into their desktop what I had...
1
by: mihir0288 | last post by:
I want to save HTML file that i open in web browser on my hard disk without using save file dialog box. I want to save it as html page through only code and without user interactions.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.