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?
13 12624
Have you tried bitmap.dispose()?
Use the Graphics object? It has a .Clear(Color) function
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. - Image imgMatte = new Bitmap(100, 100);
-
Rectangle FullSize = new Rectangle(0, 0, imgMatte.Width, imgMatte.Height);
-
Graphics myGraphic = Graphics.FromImage(imgMatte);
-
PaintEventArgs e = new PaintEventArgs(myGraphic, FullSize);
-
SolidBrush MatteBrush = new SolidBrush(Color.Black);
-
e.Graphics.FillRectangle(MatteBrush, e.ClipRectangle);
-
If you are doing this:
Graphics myGraphic = Graphics.FromImage(imgMatte);
You can just do this:
myGraphic.Clear(Color.White);
Have you tried bitmap.dispose()?
Yes. However, if I now again attempt to write to the bitmap an exception occurs.
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.
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.
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?
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: - myGraphic.Clear(Color.White);
- if (this.Horse == Dead)
-
{
-
Beat();
-
}
-
Regards, tlhIn'toQ - if (this.Horse == Dead)
-
{
-
Beat();
-
}
-
LMAO XD
codegecko
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.
"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.
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!
Sign in to post your reply or Sign up for a free account.
Similar topics
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 =...
|
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...
|
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...
|
by: Fir5tSight |
last post by:
Hi All,
I used the following code in C#:
using System.Drawing;
//blah blah blah
Bitmap bmp = new Bitmap();
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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$) {
}
...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
| |