473,789 Members | 2,694 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to resize the bitmap used for Paint event

This is what I do in a PictureBox New:
b1 = New Drawing.Bitmap( Width, Height, Me.CreateGraphi cs())

g1 = Graphics.FromIm age(b1)

Someplace I do

g1.DrawString.. .......

Then in Paint I do:

e.Graphics.Draw Image(b1, 0, 0)

Do I have to do something in Dispose??

What should I do if the Box is resized??

Thanks

Cal


Nov 20 '05 #1
5 2011
" active" <ac****@REMOV Ea-znet.com> schrieb
This is what I do in a PictureBox New:
b1 = New Drawing.Bitmap( Width, Height, Me.CreateGraphi cs())

g1 = Graphics.FromIm age(b1)

I guess you declared g1 and b1 at class level? (a field in the class)

In Sub New I'd probably write

dim g as graphics
g = me.creategraphi cs
b1 = New Drawing.Bitmap( Width, Height, g)
g.dispose '<- dispose here
g1 = Graphics.FromIm age(b1)
'...

Someplace I do

g1.DrawString.. .......

Then in Paint I do:

e.Graphics.Draw Image(b1, 0, 0)

Do I have to do something in Dispose??
I'd call g1.dispose and b1.dispose.
What should I do if the Box is resized??


I'd call g1.dispose, b1.dispose and recreate the bitmap. So, the Bitmap
creating lines should be a separate proc called from the ctor and in
OnResize.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Nov 20 '05 #2
I realize that the quick test I had did seemed to work but it was not
correct.
I have a usercontrol containing a picturebox that I want to draw on.
What happens is I'm drawing on the UserControl instead.



I guess you declared g1 and b1 at class level? (a field in the class)

In Sub New I'd probably write

dim g as graphics
g = me.creategraphi cs
can't use g1 here? Why do we need g? b1 = New Drawing.Bitmap( Width, Height, g)
I don't understand why dispose and then get a new one.
What is this for?? g.dispose '<- dispose here
g1 = Graphics.FromIm age(b1)
'...
What should I do if the Box is resized??


I'd call g1.dispose, b1.dispose and recreate the bitmap. So, the Bitmap
creating lines should be a separate proc called from the ctor and in
OnResize.


recreate the graphics in the bitmap is not possible. Think of Photoshop and
the user resizes after drawing.
Thanks for helping,
Cal
Nov 20 '05 #3
" active" <ac****@REMOV Ea-znet.com> schrieb
I realize that the quick test I had did seemed to work but it was
not correct.
I have a usercontrol containing a picturebox that I want to draw
on. What happens is I'm drawing on the UserControl instead.


Then you can paint in the Picturebox' paint event.

An alternative is to derive your own class from the Picturebox class and
override OnPaint - but currently this does not make the difference.
I guess you declared g1 and b1 at class level? (a field in the
class)

In Sub New I'd probably write

dim g as graphics
g = me.creategraphi cs


can't use g1 here? Why do we need g?


It was _you_ who created a new Graphics object. In your first posting you
wrote

b1 = New Drawing.Bitmap( Width, Height, Me.CreateGraphi cs())

I changed this and assigned the return value of Me.CreateGraphi cs to the
variable to be able to call the Dispose method afterwards.

b1 = New Drawing.Bitmap( Width, Height, g)


I don't understand why dispose and then get a new one.
What is this for??
g.dispose '<- dispose here
g1 = Graphics.FromIm age(b1)
See comment above: You also created two Graphics objects. I guess you did it
because you wanted this for the reason described in the documentation for
the constructor when passing a graphics object: The resolution of the
graphics object is applied to the bitmap.
What should I do if the Box is resized??


I'd call g1.dispose, b1.dispose and recreate the bitmap. So, the
Bitmap creating lines should be a separate proc called from the
ctor and in OnResize.


recreate the graphics in the bitmap is not possible. Think of
Photoshop and the user resizes after drawing.


What does this mean? You can copy the old Bitmap into the new Bitmap if you
don't want to loose the content.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #4
Then you can paint in the Picturebox' paint event. I had figured that out and it makes sense and works OK.


dim g as graphics
g = me.creategraphi cs


can't use g1 here? Why do we need g?


It was _you_ who created a new Graphics object. In your first posting you
wrote

b1 = New Drawing.Bitmap( Width, Height, Me.CreateGraphi cs())

I changed this and assigned the return value of Me.CreateGraphi cs to the
variable to be able to call the Dispose method afterwards.

Got it! Thanks
> What should I do if the Box is resized??

recreate the graphics in the bitmap is not possible. Think of
Photoshop and the user resizes after drawing.


What does this mean? You can copy the old Bitmap into the new Bitmap if

you don't want to loose the content.
Sounds good to me. thanks


Thank a lot
Cal
Nov 20 '05 #5
* " active" <ac****@REMOV Ea-znet.com> scripsit:
This is what I do in a PictureBox New:
b1 = New Drawing.Bitmap( Width, Height, Me.CreateGraphi cs())

g1 = Graphics.FromIm age(b1)

Someplace I do

g1.DrawString.. .......

Then in Paint I do:

e.Graphics.Draw Image(b1, 0, 0)

Do I have to do something in Dispose??
You will have to dispose 'g1'.

\\\
g1.Dispose()
///
What should I do if the Box is resized??


Who knows what you want to do?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

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

Similar topics

2
5247
by: Joao Santa Barbara | last post by:
Hi all i need to resize a background image in a mdi parent form ? how can i do this i have tryed to do in the resize event, and, in the overload background paint, bla, bla .. and it didn´t show nothing.. can someone help me ???? thks JSB
0
1307
by: Dave Veeneman | last post by:
I'm creating a custom control that uses the OnPaint event to paint a graphic. The graphic needs to resize itself when the control is resized. Right now, I'm trapping the Resize event to trigger the paint. However, the Resize event appears to fire repeatedly as the control is being resized, which causes the control to repaint repeatedly, chewing up CPU capacity. I'd like to have the control redraw only when the resize is complete, not...
8
5434
by: Ian Stiles | last post by:
If you have "Show window contents while dragging" turned on (Right-click desktop, Appearance, Effects) then you get horrible flashing and flickering on a CSharp form when the form hosts a TreeView or WebBrowser control and then you resize the form. Here is what I've tried so far: 1. Turning off CS_VREDRAW and CS_HREDRAW in both the parent form and a subclass of the control via the "override CreateParams" property (these values were...
7
2026
by: Dennis | last post by:
I am trying to implement drawing on a bitmap and using bitblt to transfer it to the control graphics object in the paint event. It seems to draw on the bitmap ok but doesn't get transferred to the control graphics object in the paint event. Any help would be appreciated. Here is my code: public class as mycontrol Private Declare Auto Function BitBlt Lib "GDI32.DLL" (ByVal hdcDest As IntPtr, ByVal nxDest As Integer, ByVal nyDest As...
15
5367
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
0
1253
by: AlVis1515 | last post by:
We had a VB6 program that was used to take a scanned signature image as a set of screen coordinates. The VB6 program then converted this into a bitmap file which we used to embed the signature in certain documents such as invoices. The code was recently ported to VB.NET. We are using the BitMap and DataPoint objects to convert the data to a bitmap file, then saving it using a .NET PictureBox. The problem is that apparently the bitmap...
15
1853
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
6
2475
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 that point to the colors in a Palette of the display driver. So if I get a bitmap via CF_BITMAP I need to also get a Palette off the clipboard and realize it then display the bitmap. I believe "Realize it" means to put it into the display driver.
1
5600
by: martinsmith160 | last post by:
Hi all I am trying to create a level builder tool for a final year project and im having some problems drawing. I have placed a picture box within a panel so i can scroll around the image which is working fine. My aim is to double click the picture box and the desired image will be drawn at the mouse position. This works fine unless I scroll or minimise the form because the image isnt repainted after movement. I looked up drawing the image to...
0
10195
jinu1996
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...
1
10136
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,...
0
9979
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 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...
0
9016
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7525
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5415
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4090
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
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.