The following code will display a tif file on a form. When another form is
moved over the tif image, the tif image is erased where the form was moved.
A paint event occurs when this happens. My question is..how would I save the
tif images as soon as it is initially painted, and then restore the image in
a paint event. It seems to me that there should be some sort of a SaveImage
method and a RestoreImage method that would be fast. Note: Page1 is the form
name, and FileName is passed from a routine on another form.
Public Filename as string
dim gr as graphics
Public Sub DrawTif()
Dim bm As Bitmap
bm = Bitmap.FromFile (FileName)
gr = Me.CreateGraphi cs
gr.Interpolatio nMode = Drawing2D.Inter polationMode.Hi ghQualityBicubi c
gr.DrawImage(bm , New Rectangle(0, 0, 400, 500)) can I save the image here
End Sub
sub Page1_paint> and restore it here
end sub
sub Page1_Closing
gr.dispose
end sub 7 1823
Hi,
"hamil" <ha***@discussi ons.microsoft.c om> wrote in message
news:ED******** *************** ***********@mic rosoft.com... The following code will display a tif file on a form. When another form is moved over the tif image, the tif image is erased where the form was moved. A paint event occurs when this happens. My question is..how would I save the tif images as soon as it is initially painted, and then restore the image in a paint event. It seems to me that there should be some sort of a SaveImage
But why would you want to save and restore it, it is already in a Bitmap,
just (re)draw it inside OnPaint. Also, never store a Graphics object
obtained with CreateGraphics, you must always Dispose it before the
eventhandler finishes.
See code below.
method and a RestoreImage method that would be fast. Note: Page1 is the form name, and FileName is passed from a routine on another form.
Public Filename as String
Dim bm As Bitmap
Public Sub DrawTif()
bm = Bitmap.FromFile (FileName)
End Sub
Sub Page1_paint
If ( Not bm Is Nothing ) Then
e.Graphics.Inte rpolationMode =
Drawing2D.Inter polationMode.Hi ghQualityBicubi c
e.DrawImage(bm, New Rectangle(0, 0, 400, 500))
End If
End sub
Sub Page1_Closing
bm.Dispose
bm = Nothing
End Sub
HTH,
Greetings
"Bart Mermuys" wrote: Hi,
"hamil" <ha***@discussi ons.microsoft.c om> wrote in message news:ED******** *************** ***********@mic rosoft.com... The following code will display a tif file on a form. When another form is moved over the tif image, the tif image is erased where the form was moved. A paint event occurs when this happens. My question is..how would I save the tif images as soon as it is initially painted, and then restore the image in a paint event. It seems to me that there should be some sort of a SaveImage
But why would you want to save and restore it, it is already in a Bitmap, just (re)draw it inside OnPaint. Also, never store a Graphics object obtained with CreateGraphics, you must always Dispose it before the eventhandler finishes.
See code below.
method and a RestoreImage method that would be fast. Note: Page1 is the form name, and FileName is passed from a routine on another form.
Public Filename as String Dim bm As Bitmap
Public Sub DrawTif() bm = Bitmap.FromFile (FileName) End Sub
Sub Page1_paint If ( Not bm Is Nothing ) Then e.Graphics.Inte rpolationMode = Drawing2D.Inter polationMode.Hi ghQualityBicubi c e.DrawImage(bm, New Rectangle(0, 0, 400, 500)) End If End sub
Sub Page1_Closing bm.Dispose bm = Nothing End Sub
HTH, Greetings
Bert..
Your code works, but the paint event is slow. My image is a tif that was
originally an 8-1/2 X 11 page, black-white sheet scanned at 300 DPI, that
results in about 8,200,000 pixels. I use a Group four Fax compression that
makes the file about 50K bytes. The code " bm = bitmap.from file..." will
decompress and regenerate the 8,200,000 bit image. Since I am now displaying
the image on a form on by screen at about 1100 X 850 pixels, (935,000 bits),
interpolation must be used along with the scaling to get a good image. I am
pretty sure the scaling and interpolation is what is taking up most of the
time as this is done at every paint event.
It seems to me that there should be some way to scale, interpolate, and draw
the image to a buffer that is saved. Then at the paint event, the buffer
could be read and drawn without having to go through the scaling and
interpolation every time.
Any thoughts here? Maybe this cannot be done in VB.
Hamil.
Hi,
"hamil" <ha***@discussi ons.microsoft.c om> wrote in message
news:D4******** *************** ***********@mic rosoft.com...
"Bart Mermuys" wrote:
Hi,
"hamil" <ha***@discussi ons.microsoft.c om> wrote in message news:ED******** *************** ***********@mic rosoft.com... > The following code will display a tif file on a form. When another form > is > moved over the tif image, the tif image is erased where the form was > moved. > A paint event occurs when this happens. My question is..how would I > save > the > tif images as soon as it is initially painted, and then restore the > image > in > a paint event. It seems to me that there should be some sort of a > SaveImage But why would you want to save and restore it, it is already in a Bitmap, just (re)draw it inside OnPaint. Also, never store a Graphics object obtained with CreateGraphics, you must always Dispose it before the eventhandler finishes.
See code below.
> method and a RestoreImage method that would be fast. Note: Page1 is the > form > name, and FileName is passed from a routine on another form.
Public Filename as String Dim bm As Bitmap
Public Sub DrawTif() bm = Bitmap.FromFile (FileName) End Sub
Sub Page1_paint If ( Not bm Is Nothing ) Then e.Graphics.Inte rpolationMode = Drawing2D.Inter polationMode.Hi ghQualityBicubi c e.DrawImage(bm, New Rectangle(0, 0, 400, 500)) End If End sub
Sub Page1_Closing bm.Dispose bm = Nothing End Sub
HTH, Greetings Bert..
Your code works, but the paint event is slow. My image is a tif that was originally an 8-1/2 X 11 page, black-white sheet scanned at 300 DPI, that results in about 8,200,000 pixels. I use a Group four Fax compression that makes the file about 50K bytes. The code " bm = bitmap.from file..." will decompress and regenerate the 8,200,000 bit image. Since I am now displaying the image on a form on by screen at about 1100 X 850 pixels, (935,000 bits), interpolation must be used along with the scaling to get a good image. I am pretty sure the scaling and interpolation is what is taking up most of the time as this is done at every paint event.
It seems to me that there should be some way to scale, interpolate, and draw the image to a buffer that is saved. Then at the paint event, the buffer could be read and drawn without having to go through the scaling and interpolation every time.
You can draw the Bitmap from file into a memory Bitmap and then paint the
memory Bitmap inside onpaint, eg.:
Public Filename as String
Dim bm As Bitmap ' memory bitmap
Public Sub DrawTif()
Dim fileBitmap As Bitmap = Bitmap.FromFile (FileName)
' create memory bitmap
Dim gfx As Graphics = CreateGraphics( )
bm = New Bitmap( 400, 500, gfx )
gfx.Dispose()
' draw file-bitmap scaled into memory-bitmap
gfx = Graphics.FromIm age( bm )
gfx.Interpolati onMode = Drawing2D.Inter polationMode.Hi ghQualityBicubi c
gfx.DrawImage(f ileBitmap, New Rectangle(0, 0, 400, 500))
gfx.Dispose()
' dispose file bitmap
fileBitmap.Disp ose();
' trigger onpaint
Invalidate()
End Sub
Sub Page1_paint
If ( Not bm Is Nothing ) Then
e.Graphics.Draw ImageUnscaled(b m, 0, 0, 0, 0, 0 )
End If
End Sub
Sub Page1_Closing
bm.Dispose
bm = Nothing
End Sub
HTH,
Greetings Any thoughts here? Maybe this cannot be done in VB.
Hamil.
If it's a large bitmap, wouldn't using BitBlt to copy the bitmap to the
graphics object passed in the paint event be much faster instead of drawimage?
--
Dennis in Houston
"Bart Mermuys" wrote: Hi,
"hamil" <ha***@discussi ons.microsoft.c om> wrote in message news:D4******** *************** ***********@mic rosoft.com...
"Bart Mermuys" wrote:
Hi,
"hamil" <ha***@discussi ons.microsoft.c om> wrote in message news:ED******** *************** ***********@mic rosoft.com... > The following code will display a tif file on a form. When another form > is > moved over the tif image, the tif image is erased where the form was > moved. > A paint event occurs when this happens. My question is..how would I > save > the > tif images as soon as it is initially painted, and then restore the > image > in > a paint event. It seems to me that there should be some sort of a > SaveImage
But why would you want to save and restore it, it is already in a Bitmap, just (re)draw it inside OnPaint. Also, never store a Graphics object obtained with CreateGraphics, you must always Dispose it before the eventhandler finishes.
See code below.
> method and a RestoreImage method that would be fast. Note: Page1 is the > form > name, and FileName is passed from a routine on another form.
Public Filename as String Dim bm As Bitmap
Public Sub DrawTif() bm = Bitmap.FromFile (FileName) End Sub
Sub Page1_paint If ( Not bm Is Nothing ) Then e.Graphics.Inte rpolationMode = Drawing2D.Inter polationMode.Hi ghQualityBicubi c e.DrawImage(bm, New Rectangle(0, 0, 400, 500)) End If End sub
Sub Page1_Closing bm.Dispose bm = Nothing End Sub
HTH, Greetings Bert..
Your code works, but the paint event is slow. My image is a tif that was originally an 8-1/2 X 11 page, black-white sheet scanned at 300 DPI, that results in about 8,200,000 pixels. I use a Group four Fax compression that makes the file about 50K bytes. The code " bm = bitmap.from file..." will decompress and regenerate the 8,200,000 bit image. Since I am now displaying the image on a form on by screen at about 1100 X 850 pixels, (935,000 bits), interpolation must be used along with the scaling to get a good image. I am pretty sure the scaling and interpolation is what is taking up most of the time as this is done at every paint event.
It seems to me that there should be some way to scale, interpolate, and draw the image to a buffer that is saved. Then at the paint event, the buffer could be read and drawn without having to go through the scaling and interpolation every time.
You can draw the Bitmap from file into a memory Bitmap and then paint the memory Bitmap inside onpaint, eg.:
Public Filename as String Dim bm As Bitmap ' memory bitmap
Public Sub DrawTif() Dim fileBitmap As Bitmap = Bitmap.FromFile (FileName)
' create memory bitmap Dim gfx As Graphics = CreateGraphics( ) bm = New Bitmap( 400, 500, gfx ) gfx.Dispose()
' draw file-bitmap scaled into memory-bitmap gfx = Graphics.FromIm age( bm ) gfx.Interpolati onMode = Drawing2D.Inter polationMode.Hi ghQualityBicubi c gfx.DrawImage(f ileBitmap, New Rectangle(0, 0, 400, 500)) gfx.Dispose()
' dispose file bitmap fileBitmap.Disp ose();
' trigger onpaint Invalidate() End Sub
Sub Page1_paint If ( Not bm Is Nothing ) Then e.Graphics.Draw ImageUnscaled(b m, 0, 0, 0, 0, 0 ) End If End Sub
Sub Page1_Closing bm.Dispose bm = Nothing End Sub
HTH, Greetings
Any thoughts here? Maybe this cannot be done in VB.
Hamil.
Hi,
"Dennis" <De****@discuss ions.microsoft. com> wrote in message
news:3A******** *************** ***********@mic rosoft.com... If it's a large bitmap, wouldn't using BitBlt to copy the bitmap to the graphics object passed in the paint event be much faster instead of drawimage?
BitBlt is GDI and DrawImage is GDI+, BitBlt will not scale but i guess you
could use it to transfer the memory Bitmap to the screen and maybe it will
be faster (i've heard GDI is faster then GDI+). Haven't tried it though.
HTH,
Greetings
-- Dennis in Houston
"Bart Mermuys" wrote:
Hi,
"hamil" <ha***@discussi ons.microsoft.c om> wrote in message news:D4******** *************** ***********@mic rosoft.com... > > > "Bart Mermuys" wrote: > >> Hi, >> >> "hamil" <ha***@discussi ons.microsoft.c om> wrote in message >> news:ED******** *************** ***********@mic rosoft.com... >> > The following code will display a tif file on a form. When another >> > form >> > is >> > moved over the tif image, the tif image is erased where the form was >> > moved. >> > A paint event occurs when this happens. My question is..how would I >> > save >> > the >> > tif images as soon as it is initially painted, and then restore the >> > image >> > in >> > a paint event. It seems to me that there should be some sort of a >> > SaveImage >> >> But why would you want to save and restore it, it is already in a >> Bitmap, >> just (re)draw it inside OnPaint. Also, never store a Graphics object >> obtained with CreateGraphics, you must always Dispose it before the >> eventhandler finishes. >> >> See code below. >> >> > method and a RestoreImage method that would be fast. Note: Page1 is >> > the >> > form >> > name, and FileName is passed from a routine on another form. >> >> Public Filename as String >> Dim bm As Bitmap >> >> Public Sub DrawTif() >> bm = Bitmap.FromFile (FileName) >> End Sub >> >> Sub Page1_paint >> If ( Not bm Is Nothing ) Then >> e.Graphics.Inte rpolationMode = >> Drawing2D.Inter polationMode.Hi ghQualityBicubi c >> e.DrawImage(bm, New Rectangle(0, 0, 400, 500)) >> End If >> End sub >> >> Sub Page1_Closing >> bm.Dispose >> bm = Nothing >> End Sub >> >> HTH, >> Greetings >> >> >> > Bert.. > > Your code works, but the paint event is slow. My image is a tif that > was > originally an 8-1/2 X 11 page, black-white sheet scanned at 300 DPI, > that > results in about 8,200,000 pixels. I use a Group four Fax compression > that > makes the file about 50K bytes. The code " bm = bitmap.from file..." > will > decompress and regenerate the 8,200,000 bit image. Since I am now > displaying > the image on a form on by screen at about 1100 X 850 pixels, (935,000 > bits), > interpolation must be used along with the scaling to get a good image. > I > am > pretty sure the scaling and interpolation is what is taking up most of > the > time as this is done at every paint event. > > It seems to me that there should be some way to scale, interpolate, and > draw > the image to a buffer that is saved. Then at the paint event, the > buffer > could be read and drawn without having to go through the scaling and > interpolation every time.
You can draw the Bitmap from file into a memory Bitmap and then paint the memory Bitmap inside onpaint, eg.:
Public Filename as String Dim bm As Bitmap ' memory bitmap
Public Sub DrawTif() Dim fileBitmap As Bitmap = Bitmap.FromFile (FileName)
' create memory bitmap Dim gfx As Graphics = CreateGraphics( ) bm = New Bitmap( 400, 500, gfx ) gfx.Dispose()
' draw file-bitmap scaled into memory-bitmap gfx = Graphics.FromIm age( bm ) gfx.Interpolati onMode = Drawing2D.Inter polationMode.Hi ghQualityBicubi c gfx.DrawImage(f ileBitmap, New Rectangle(0, 0, 400, 500)) gfx.Dispose()
' dispose file bitmap fileBitmap.Disp ose();
' trigger onpaint Invalidate() End Sub
Sub Page1_paint If ( Not bm Is Nothing ) Then e.Graphics.Draw ImageUnscaled(b m, 0, 0, 0, 0, 0 ) End If End Sub
Sub Page1_Closing bm.Dispose bm = Nothing End Sub
HTH, Greetings
> > Any thoughts here? Maybe this cannot be done in VB. > > Hamil. >
Hi,
<snipped> It seems to me that there should be some way to scale, interpolate, and draw the image to a buffer that is saved. Then at the paint event, the buffer could be read and drawn without having to go through the scaling and interpolation every time. You can draw the Bitmap from file into a memory Bitmap and then paint the memory Bitmap inside onpaint, eg.:
Public Filename as String Dim bm As Bitmap ' memory bitmap
Public Sub DrawTif() Dim fileBitmap As Bitmap = Bitmap.FromFile (FileName)
' create memory bitmap Dim gfx As Graphics = CreateGraphics( ) bm = New Bitmap( 400, 500, gfx ) gfx.Dispose()
' draw file-bitmap scaled into memory-bitmap gfx = Graphics.FromIm age( bm ) gfx.Interpolati onMode = Drawing2D.Inter polationMode.Hi ghQualityBicubi c gfx.DrawImage(f ileBitmap, New Rectangle(0, 0, 400, 500)) gfx.Dispose()
' dispose file bitmap fileBitmap.Disp ose();
' trigger onpaint Invalidate() End Sub
Because Dennis asked something about the speed of DrawImage, i was thinking
that OnPaint could be faster if you do not draw the whole memory Bitmap but
just the invalidated part.
Sub Page1_paint
If ( Not bm Is Nothing ) Then
e.Graphics.Draw Image(bm, e.ClipRectangle , e.ClipRectangle ,
GraphicsUnit.Pi xel)
End If
End Sub
HTH,
Greetings Sub Page1_Closing bm.Dispose bm = Nothing End Sub
HTH, Greetings
Any thoughts here? Maybe this cannot be done in VB.
Hamil.
Thanks to both of you..
Barts first suggestion was much better than the way I was doing theonPaint.
Barts second suggestion was even better.
I looked into the BitBlt approach and I think it might be even faster but I
think this method would require me operating "outside" of VB.net exclusively,
i.e. require a Win API call.
Barts second suggeston where only the required part is repainted works very
well even on my slow 1 GHz Pentium III.
Thanks again.
Hamil.
"hamil" wrote: The following code will display a tif file on a form. When another form is moved over the tif image, the tif image is erased where the form was moved. A paint event occurs when this happens. My question is..how would I save the tif images as soon as it is initially painted, and then restore the image in a paint event. It seems to me that there should be some sort of a SaveImage method and a RestoreImage method that would be fast. Note: Page1 is the form name, and FileName is passed from a routine on another form.
Public Filename as string dim gr as graphics
Public Sub DrawTif() Dim bm As Bitmap
bm = Bitmap.FromFile (FileName)
gr = Me.CreateGraphi cs gr.Interpolatio nMode = Drawing2D.Inter polationMode.Hi ghQualityBicubi c gr.DrawImage(bm , New Rectangle(0, 0, 400, 500)) >>> can I save the image here End Sub
sub Page1_paint>> and restore it here
end sub
sub Page1_Closing gr.dispose end sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: DraguVaso |
last post by:
Hi,
I 'wrote' my own DataGrid, using the normal DataGrid, and overriding some of
the DataGridTextBoxColumn-methods (mostly the Paint-method). I based most of
my changes on the Windows Form FAQ:
- http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q745q
- http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q758q
- http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q837q
Basicly it works like this: Every time a cell has...
|
by: Tamir Khason |
last post by:
How I can paint something onClick event?
I need PaintEventArgs event in order to paint and raise Graphics, but
onClick I have only EventArgs Event...
Thanx
|
by: vooose |
last post by:
Consider a UserControl to which you do
userControl.Paint += new PaintEventHandler(paint_method)
If you don't like that way, and prefer to override onPaint( ) then the
problem stated below still exists (I tried both ways).
Imagine you have a Console.WriteLine( ) in the paint method so you know
when its getting called. Also there is no place in the code that
userControl.Paint is -+ so the event is *never* removed.
|
by: Mike Cooper |
last post by:
I have been staring at the above error for over a week now! I have a
an inherited data class looking like thus:
Public Class DataGridBoolColumnInherit
Inherits System.Windows.Forms.DataGridBoolColumn
Protected Overloads Overrides Sub Paint(ByVal g As Graphics, ByVal
bounds As Rectangle, ByVal As CurrencyManager, ByVal rowNum
As Integer, ByVal backBrush As Brush, ByVal foreBrush As Brush, ByVal
alignToRight As Boolean)
|
by: WStoreyII |
last post by:
i am using this code to try to paint a line on my form and it wont work i
get an object not set to a reference error
Dim myPen As New System.Drawing.Pen(System.Drawing.Color.Red)
Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.DrawLine(myPen, 0, 0, 200, 200)
| |
by: jcrouse |
last post by:
I am rotating some text is some label controls. In the one place I use it it
works fine. In the other place I use it I can't figure out the syntax. I
don't really understand the event. Where it works fine, it seems to fire
when the form changes visibility. Here is the code.
Private Sub lblP1JoyUp_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles lblP1JoyUp.Paint
If lblP1JoyUp.Visible = True Then
Dim...
|
by: Sam |
last post by:
Hai,
I use a paintbox paint event to draw some images in a paintbox. I call
the paint event by refreshing the paintbox using paintboxname.refresh()
or paintboxname.update().
Problem with this kind of paint event is that the event is not raised
when the application is run in a minimized state. So, my question is:
How can you make sure that the paint event is called even when the
application is running in the minimized state.
|
by: Rotsey |
last post by:
Hi,
I have a interface that I use for a form so I can pass the form
to another object.
How do I add the Paint event to the interface and subsequently
handle the paint event in my other object.?
I am not sure of the syntax required to do this?
|
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= |
last post by:
Hi,
On a usercontrol I've put a set of radiobuttons within a groupbox. These
radiobuttons have visual style enables, i.e. they turn orange when hovering
over them and green when pushed.
Normally I put my updation of data shown in the controls on the usercontrol
in the Paint event handler of the usercontrol. When it comes to the
radiobuttons, a paint event for the usercontrol is fired whenever hovering
over the radiobuttons, making...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| |