473,385 Members | 1,528 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,385 software developers and data experts.

Clearing a bitmap

I am a beginner. I need a fast way to clear a bitmap in VB.NET. (Looping around and setting pixel colours to white is too slow). Is there a simple instruction to do this, or is there a fast way of copying another (white) bitmap of the same size into my bitmap?
Oct 31 '08 #1
13 12624
kenobewan
4,871 Expert 4TB
Have you tried bitmap.dispose()?
Oct 31 '08 #2
Plater
7,872 Expert 4TB
Use the Graphics object? It has a .Clear(Color) function
Oct 31 '08 #3
tlhintoq
3,525 Expert 2GB
I am a beginner. I need a fast way to clear a bitmap in VB.NET. (Looping around and setting pixel colours to white is too slow). Is there a simple instruction to do this, or is there a fast way of copying another (white) bitmap of the same size into my bitmap?
I'm a C# guy, not VB sorry. But the process should be the same.

Make a brush
give it properties of solid and white
fill your graphic object using the brush you defined.

Expand|Select|Wrap|Line Numbers
  1.                 Image imgMatte = new Bitmap(100, 100);
  2.                 Rectangle FullSize = new Rectangle(0, 0, imgMatte.Width, imgMatte.Height);
  3.                 Graphics myGraphic = Graphics.FromImage(imgMatte);
  4.                 PaintEventArgs e = new PaintEventArgs(myGraphic, FullSize);
  5.                 SolidBrush MatteBrush = new SolidBrush(Color.Black);
  6.                 e.Graphics.FillRectangle(MatteBrush, e.ClipRectangle);
  7.  
Oct 31 '08 #4
Plater
7,872 Expert 4TB
If you are doing this:
Graphics myGraphic = Graphics.FromImage(imgMatte);

You can just do this:
myGraphic.Clear(Color.White);
Oct 31 '08 #5
Have you tried bitmap.dispose()?
Yes. However, if I now again attempt to write to the bitmap an exception occurs.
Oct 31 '08 #6
kenobewan
4,871 Expert 4TB
Not sure why you would want to write to a bitmap after disposing it? There are two other suggestions by experts, suggest try and let us know the result.
Nov 1 '08 #7
tlhintoq
3,525 Expert 2GB
Not sure why you would want to write to a bitmap after disposing it? There are two other suggestions by experts, suggest try and let us know the result.
Disposing of the bitmap was never part of the OP question. It was a suggestion by someone else. The original question was to clear it (to a color). Which as you point out has been addressed a couple time.
Nov 2 '08 #8
kenobewan
4,871 Expert 4TB
I agree that the sentence,
I need a fast way to clear a bitmap in VB.NET. (Looping around and setting pixel colours to white is too slow).
, is ambiguous. What do you mean by clear?
Nov 2 '08 #9
tlhintoq
3,525 Expert 2GB
I agree that the sentence, , is ambiguous. What do you mean by clear?
The OP states:

or is there a fast way of copying another (white) bitmap of the same size into my bitmap?
So by "clear" I think the OP means to repaint the bitmap in all white so as to start on a fresh canvas.

Moderator Plater gave the following tip:

Expand|Select|Wrap|Line Numbers
  1. myGraphic.Clear(Color.White);
Expand|Select|Wrap|Line Numbers
  1. if (this.Horse == Dead)
  2. {
  3.      Beat();
  4. }
  5.  

Regards,
tlhIn'toQ
Nov 2 '08 #10
JamieHowarth0
533 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. if (this.Horse == Dead)
  2. {
  3.      Beat();
  4. }
  5.  
LMAO XD

codegecko
Nov 2 '08 #11
I agree that the sentence, , is ambiguous. What do you mean by clear?
"clear" means to reset all the pixels to white.
I repeatedly want to create a different graph, eg y=mx. Each time I calculate the y-value for each x-value and set the bitmap pixels x,y to black. When the graph has been completed I then display it on a picturebox. To plot a new graph I must first "clear" the bitmap to save a new set of x,y. The bitmap is quite large and to "clear" it pixel by pixel takes a long time.
Nov 13 '08 #12
tlhintoq
3,525 Expert 2GB
"clear" means to reset all the pixels to white.
I repeatedly want to create a different graph, eg y=mx. Each time I calculate the y-value for each x-value and set the bitmap pixels x,y to black. When the graph has been completed I then display it on a picturebox. To plot a new graph I must first "clear" the bitmap to save a new set of x,y. The bitmap is quite large and to "clear" it pixel by pixel takes a long time.

Don't consider that you have to erase the old graphic.
Just make the new bitmap and put it in the picture box.
It replaces the old graphic.
Manually clearing the picturebox is an unneeded step.
Nov 13 '08 #13
Don't consider that you have to erase the old graphic.
Just make the new bitmap and put it in the picture box.
It replaces the old graphic.
Manually clearing the picturebox is an unneeded step.
Yes, I do just that, but to recreate the bitmap I first have to "clear" it before I can set a new sequence of pixels in the bitmap, thus creating a new graph, ready for display in the picturebox. I do not have a problem in displaying the bitmap in the picturebox, or in clearing the picturebox, this is vitually instantaneous. The delay comes with clearing the bitmap pixel by pixel. I really appreciate your responses!
Nov 13 '08 #14

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

Similar topics

7
by: ljlevend | last post by:
I want to clear all of the byes that are associated with a BitmapData object. I know that one technique would be to do the following: '... Dim bitmapData As Drawing.Imaging.BitmapData =...
8
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...
1
by: asdf | last post by:
I just started my first project where i draw lines and strings on the screen. I sucessfully drew what i needed on the screen, then realized that when it updated it just drew over the same area w/o...
7
by: Fir5tSight | last post by:
Hi All, I used the following code in C#: using System.Drawing; //blah blah blah Bitmap bmp = new Bitmap();
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
8
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the...
6
by: \Frank\ | last post by:
I trying to learn what a Bitmap is. Not a Managed Bitmap Object but one that, for example, comes from the clipboard with CF_BITMAP. I'm guessing that a CompatableBitmap is an array of indices...
2
by: Peter Oliphant | last post by:
I want to create a new Bitmap which is a portion of an existing Bitmap. For example, if I have a Bitmap that is 100x100 in size I might want to create a new Bitmap that is equivalent to the one...
5
by: =?Utf-8?B?QVRU?= | last post by:
I have a bitmap of 100X100. On the load, the bitmap is created by a function (createimage()). On my OnPaint, I draw the image back to the screen (e.Graphics.DrawImage( bitmap, destrect)). Now,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.