473,544 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Save usercontrol as bitmap

Hello all,

I've got a user control I've created called canvas. Doesn't do much at
the moment.

I've set the background image to a small bitmap using BackgroundImage
and I've set it to tiled using BackgroundImage Layout =
ImageLayout.Til ed.

It all works - I get a tiled image.

What I'd like to do now is save the tiled image (i.e. exactly what I
can see in the window) to disk. The closest I can get is to save the
non-tiled image by referring to BackgroundImage but this isn't much
help!!

Can anyone point me in the right direction? Thanks

gareth

Rectangle areaToSave = new Rectangle();
areaToSave = canCanvas.Clien tRectangle;
Bitmap imageToSave = new Bitmap(areaToSa ve.Width, areaToSave.Heig ht);
Graphics g = Graphics.FromIm age(imageToSave );
g.DrawImage(can Canvas.Backgrou ndImage, areaToSave, areaToSave,
GraphicsUnit.Pi xel);
imageToSave.Sav e(fileName, imageFormatToSa ve);
g.Dispose();
imageToSave.Dis pose();

Feb 9 '06 #1
1 6842
Nevermind, worked it out.

Bitmap imageToSave = new Bitmap(canCanva s.ClientRectang le.Width,
canCanvas.Clien tRectangle.Heig ht);

Graphics g = Graphics.FromIm age(imageToSave );

PaintEventArgs pe = new PaintEventArgs( g, new Rectangle(0, 0,
canCanvas.Clien tRectangle.Widt h, canCanvas.Clien tRectangle.Heig ht));

this.InvokePain tBackground(can Canvas, pe);
this.InvokePain t(canCanvas, pe);

imageToSave.Sav e(fileName, imageFormatToSa ve);

g.Dispose();
imageToSave.Dis pose();

Feb 9 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
61724
by: charsh | last post by:
Hi, I using the code below to draw a text in a pictureBox1. //Start--------------------------------------------------------------- private void button1_Click(object sender, System.EventArgs e) { Graphics g; g = pictureBox1.CreateGraphics(); g.FillRectangle(Brushes.White,0,0,160,160);
9
2630
by: Mark Johnson | last post by:
How can you save all or a portion of the Grafics object to a Image/Bitmap ? I am try to save the Images from Cards.dll to a BitMap file. I can read in the Images to the Grafics, but when I try this with a Bitmap the results are Black. Can you somehow Clip the Grafic and Paste it into the Bitmap ? Mark Johnson, Berlin Germany...
2
2233
by: Frank Trebus | last post by:
I´ve created a Bitmap in C# during runtime from a lbl-Field: Bitmap noise = new Bitmap(lblPaint.Width, lblPaint.Height, PixelFormat.Format16bppRgb555); System.Drawing.Bitmap flag = new System.Drawing.Bitmap(10, 10); for( int x = 0; x < flag.Height; ++x ) { for( int y = 0; y < flag.Width; ++y ) {
1
9526
by: Andy Jacobs | last post by:
Hi, I have a row in a DataTable that contains colums of identifying data and I need to save a bitmap in that row. (I'm going to write the entire DataSet to disk as XML to be used by another application) How do I save a bitmap in the DataTable? Thx. Andy Jacobs
0
3572
by: CroDude | last post by:
Hi all! I have problems when writting bitmap to a byte array and after reading it back form byte to Bitmap object. What I do is this: First I throw Bitmap to a memory-stream and then I write it into byte from a stream. Exception (System.ArgumentException: Invalid parameter used) occurs when reading from byte over a memory-stream back to the...
8
11383
by: RicercatoreSbadato | last post by:
I'm using bmp.Save() and the bmp is in PixelFormat.Format8bppIndexed. But when I open the image with Gimp, it tells me that the image is RGB and not grayscale.
3
8618
by: CSH | last post by:
Hi all, I've run into a small problem opening and saving bitmaps. Concider the following code: Dim oBM as Bitmap Dim cFileName as String ... some code to get the filename etc...
1
1698
by: DSchlichte | last post by:
Hello ' I need some help. I've created a little application to paint, save and load pictures (Bitmap-graphics) into ' a picturebox-object on the desktop. There's no problem to paint or to load pictures, but how can I save the image? ' My load-routine is the following (if I click on the file-menu and chose File open...):
8
3302
by: Nathan Sokalski | last post by:
I am trying to write code to rotate a graphic that I have. Here is the code I am currently using: Dim frogbitmap As New Bitmap(Drawing.Image.FromFile(Server.MapPath("images/frog.gif"))) Dim froggraphic As Graphics = Graphics.FromImage(frogbitmap) froggraphic.RotateTransform(90) frogbitmap.Save(Server.MapPath("images/frog2.gif"),...
0
7437
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7389
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5928
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5306
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4930
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3427
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1848
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
993
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.