|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Resize an image: bug?inside a subroutine i have this code: Me.PictureBox1.Size = New Size(Me.dimensioni.Width * Me.zoom_factor, Me.dimensioni.Height * Me.zoom_factor) When the program goes out of sub I get the error: System.ComponentModel.Win32Exception non è stata gestita Message="Operazione completata" Source="System.Drawing" ErrorCode=-2147467259 NativeErrorCode=0 StackTrace: in System.Drawing.BufferedGraphicsContext.CreateCompatibleDIB(IntPtr hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits) in System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height) in System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle) in System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle) in System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, Rectangle targetRectangle) in System.Windows.Forms.Control.WmPaint(Message& m) in System.Windows.Forms.Control.WndProc(Message& m) in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) in System.Windows.Forms.Application.Run(ApplicationContext context) in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() in Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) in EGF.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:riga 81 in System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() in System.Threading.ThreadHelper.ThreadStart_Context(Object state) in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) in System.Threading.ThreadHelper.ThreadStart() InnerException: I tried to insert the code inside a try catch but without success. Can anyone help me? Thanks Am 26.04.2010 11:20, schrieb zzz:
> Hi to all, Which event handler calles this sub routine?> inside a subroutine i have this code: > > Me.PictureBox1.Size = New Size(Me.dimensioni.Width * Me.zoom_factor, > Me.dimensioni.Height * Me.zoom_factor) What does debug.print(Me.PictureBox1.Size.tostring) output directly after the assignment? -- Armin
Show quote
Hide quote
"Armin Zingler" <az.nospam@freenet.de> ha scritto nel messaggio My code is insidenews:%23Tes8nS5KHA.1932@TK2MSFTNGP05.phx.gbl... > Am 26.04.2010 11:20, schrieb zzz: >> Hi to all, >> inside a subroutine i have this code: >> >> Me.PictureBox1.Size = New Size(Me.dimensioni.Width * Me.zoom_factor, >> Me.dimensioni.Height * Me.zoom_factor) > > Which event handler calles this sub routine? > > What does > > debug.print(Me.PictureBox1.Size.tostring) > > output directly after the assignment? > > > > -- > Armin ..MouseWheel event( is about zooming an image displayed in a form). Private Sub pict_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseWheel try If e.Delta < 0 Then Me.zoom_factor *= 2 Else Me.zoom_factor /= 2 End If Me.PictureBox1.Size = New Size(Me.dimensioni.Width * Me.zoom_factor, Me.dimensioni.Height * Me.zoom_factor) Debug.Print(Me.zoom_factor.ToString) Catch ex As Exception MsgBox(ex.Message) End Try when zoom_factor reaches a 2048 value, I get the error, but the exception is not raised.....so I really don't known where the dll exception is raised. Maybe too large dimension of image makes it up.... Hello,
> when zoom_factor reaches a 2048 value, I get the error, but the exception Looking at the call stack, it seems to happens when the control is painted, > is not raised.....so I really don't known where the dll exception is > raised. not at the time of the change. > Maybe too large dimension of image makes it up.... I would really set a max value for the zoom. 2048 likely means you just see a single pixel on your screen anyway ;-) -- Patrice Am 26.04.2010 14:38, schrieb zzz:
Show quoteHide quote >> Am 26.04.2010 11:20, schrieb zzz: Switch Option Strict On.>>> Hi to all, >>> inside a subroutine i have this code: >>> >>> Me.PictureBox1.Size = New Size(Me.dimensioni.Width * Me.zoom_factor, >>> Me.dimensioni.Height * Me.zoom_factor) >> >> Which event handler calles this sub routine? >> >> What does >> >> debug.print(Me.PictureBox1.Size.tostring) >> >> output directly after the assignment? > > My code is inside > ..MouseWheel event( is about zooming an image displayed in a form). > Private Sub pict_MouseMove(ByVal sender As System.Object, ByVal e As > System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseWheel > > try > > If e.Delta < 0 Then > > Me.zoom_factor *= 2 > > Else > > Me.zoom_factor /= 2 > > End If > > Me.PictureBox1.Size = New Size(Me.dimensioni.Width * Me.zoom_factor, > Me.dimensioni.Height * Me.zoom_factor) > > Debug.Print(Me.zoom_factor.ToString) > > Catch ex As Exception > > MsgBox(ex.Message) > > End Try > when zoom_factor reaches a 2048 value, I get the error, but the exception is It's shown in the call stack you've posted before. The error occurs as soon> not raised.....so I really don't known where the dll exception is raised. as the picturebox is to be repainted. > Maybe too large dimension of image makes it up.... Unanswered:debug.print(Me.PictureBox1.Size.tostring) Anyway, it's too large. What are you trying? I guess you have a picturebox inside another control with Autscroll=true, right? If that large zoom factors are expected, you must do the painting on your own by painting only the section that shall be visible at the current scroll position. -- Armin
Show quote
Hide quote
"Armin Zingler" <az.nospam@freenet.de> ha scritto nel messaggio Ok, I have turned Option Strict ON.news:ePHBSaU5KHA.620@TK2MSFTNGP02.phx.gbl... > Am 26.04.2010 14:38, schrieb zzz: CUT > Unanswered: > > debug.print(Me.PictureBox1.Size.tostring) > > Anyway, it's too large. What are you trying? I guess you have a picturebox > inside another control with Autscroll=true, right? If that large zoom > factors > are expected, you must do the painting on your own by painting only the > section > that shall be visible at the current scroll position. > debug.print(Me.PictureBox1.Size.tostring): {Width=16384, Height=16384} I have a picturebox filling a form...so how can I scroll the image when it is larger than teh form? How can I paint only the visibile section of the form? Thanks Show quoteHide quote :) Am 26.04.2010 16:00, schrieb zzz:
> Ok, I have turned Option Strict ON. Hard to believe. :-) Because:zoom_factor must be of type Single or Double, otherwise this does not compile: > Me.zoom_factor /= 2 And if zoom_factor is Single/Double, the following line does not work becausethe Size constructor doesn't accept floating point values: > Me.PictureBox1.Size = New Size(Me.dimensioni.Width * Me.zoom_factor, Thx.> Me.dimensioni.Height * Me.zoom_factor) > debug.print(Me.PictureBox1.Size.tostring): > > {Width=16384, Height=16384} > I have a picturebox filling a form...so how can I scroll the image when it Put scrollbars on the Form.> is larger than teh form? > How can I paint only the visibile section of the form? By passing the appropriate values as the srcWidth/srcHeight parametersto the graphics.drawimage method called in the Form's paint event. The srcX/srcY argument values depend on the current scroll position. -- Armin "Armin Zingler" <az.nospam@freenet.de> ha scritto nel messaggio I mean: now I have turned on Option Strict :Dnews:uiOVm3U5KHA.6052@TK2MSFTNGP02.phx.gbl... > Am 26.04.2010 16:00, schrieb zzz: >> Ok, I have turned Option Strict ON. > > Hard to believe. :-) Because: > By passing the appropriate values as the srcWidth/srcHeight parameters Can I ask you 3 code rows? ;)> to the graphics.drawimage method called in the Form's paint event. > The srcX/srcY argument values depend on the current scroll position. Am 26.04.2010 16:54, schrieb zzz:
> Can I ask you 3 code rows? ;) Yep, go on asking. :)-- Armin "Armin Zingler" <az.nospam@freenet.de> ha scritto nel messaggio I mean if you can write the 3 code rows about displaying only the visible news:%23QPITZV5KHA.5880@TK2MSFTNGP04.phx.gbl... > Am 26.04.2010 16:54, schrieb zzz: >> Can I ask you 3 code rows? ;) > > Yep, go on asking. :) part of the picturebox avoiding in this way the returned exception Thanks Am 26.04.2010 17:47, schrieb zzz:
> "Armin Zingler" <az.nospam@freenet.de> ha scritto nel messaggio I didn't answer earlier beause the example I was trying to make takes> news:%23QPITZV5KHA.5880@TK2MSFTNGP04.phx.gbl... >> Am 26.04.2010 16:54, schrieb zzz: >>> Can I ask you 3 code rows? ;) >> >> Yep, go on asking. :) > > > I mean if you can write the 3 code rows about displaying only the visible > part of the picturebox avoiding in this way the returned exception > Thanks more than just 3 rows. You have to change the approach by not using a Picturebox. So, I leave only some hints: Draw the image on your own in the control's paint event. You can use a Panel for it; a picturebox is not required. A simple Control would do it also but you can't use the designer for that. Add two scrollbars next to the panel. In the panel's paint event, draw the image using e.graphics.drawimage There are a lot of overloaded methods, so pick out the one letting you specify the source and destination areas of the image resp. the panel. You have to calculate them from the scrollbar's positions and the current zoom factor. Success! -- Armin You got that already.
The main point is that it should result in integers when it are two parameters http://msdn.microsoft.com/en-us/library/system.drawing.size_members.aspx With option strict on, your already used code should go. Be aware that you probably want to size the image itself because with the values you show you need a very big screen as it is about the picturebox, which you do by using streaming the bitmap using a stream and the DrawingClass Show quoteHide quote "zzz" <z**@tin.it> wrote in message news:4bd5a90f$0$1108$4fafbaef@reader2.news.tin.it... > > "Armin Zingler" <az.nospam@freenet.de> ha scritto nel messaggio > news:uiOVm3U5KHA.6052@TK2MSFTNGP02.phx.gbl... >> Am 26.04.2010 16:00, schrieb zzz: >>> Ok, I have turned Option Strict ON. >> >> Hard to believe. :-) Because: > > I mean: now I have turned on Option Strict :D > >> By passing the appropriate values as the srcWidth/srcHeight parameters >> to the graphics.drawimage method called in the Form's paint event. >> The srcX/srcY argument values depend on the current scroll position. > > Can I ask you 3 code rows? ;) > > > Why do you think that this quit standard code which is probably billion
times used has a bug. Or do you mean in your program, that is possible, but then you can simply try it by placing some fixed values instead of the calculation. I assume you have option strict on in top of your program to be sure the correct types are used. Show quoteHide quote "zzz" <z**@tin.it> wrote in message news:4bd55b2d$0$1117$4fafbaef@reader2.news.tin.it... > Hi to all, > inside a subroutine i have this code: > > Me.PictureBox1.Size = New Size(Me.dimensioni.Width * Me.zoom_factor, > Me.dimensioni.Height * Me.zoom_factor) > > When the program goes out of sub I get the error: > > System.ComponentModel.Win32Exception non è stata gestita > Message="Operazione completata" > Source="System.Drawing" > ErrorCode=-2147467259 > NativeErrorCode=0 > StackTrace: > in System.Drawing.BufferedGraphicsContext.CreateCompatibleDIB(IntPtr > hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits) > in System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, > Int32 offsetX, Int32 offsetY, Int32 width, Int32 height) > in System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics > targetGraphics, IntPtr targetDC, Rectangle targetRectangle) > in > System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics > targetGraphics, IntPtr targetDC, Rectangle targetRectangle) > in System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, > Rectangle targetRectangle) > in System.Windows.Forms.Control.WmPaint(Message& m) > in System.Windows.Forms.Control.WndProc(Message& m) > in > System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) > in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& > m) > in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, > Int32 msg, IntPtr wparam, IntPtr lparam) > in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& > msg) > in > System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 > dwComponentID, Int32 reason, Int32 pvLoopData) > in > System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 > reason, ApplicationContext context) > in > System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 > reason, > ApplicationContext context) > in System.Windows.Forms.Application.Run(ApplicationContext context) > in > Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() > in > Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() > in > Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] > commandLine) > in EGF.My.MyApplication.Main(String[] Args) in > 17d14f5c-a337-4978-8281-53493378c1071.vb:riga 81 > in System.AppDomain._nExecuteAssembly(Assembly assembly, String[] > args) > in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence > assemblySecurity, String[] args) > in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() > in System.Threading.ThreadHelper.ThreadStart_Context(Object state) > in System.Threading.ExecutionContext.Run(ExecutionContext > executionContext, ContextCallback callback, Object state) > in System.Threading.ThreadHelper.ThreadStart() > InnerException: > > I tried to insert the code inside a try catch but without success. > Can anyone help me? > Thanks > > >
Show quote
Hide quote
On Apr 26, 4:20 am, "zzz" <z***@tin.it> wrote: Try this:> Hi to all, > inside a subroutine i have this code: > > Me.PictureBox1.Size = New Size(Me.dimensioni.Width * Me.zoom_factor, > Me.dimensioni.Height * Me.zoom_factor) > > When the program goes out of sub I get the error: > > System.ComponentModel.Win32Exception non è stata gestita > Message="Operazione completata" > Source="System.Drawing" > ErrorCode=-2147467259 > NativeErrorCode=0 > StackTrace: > in System.Drawing.BufferedGraphicsContext.CreateCompatibleDIB(IntPtr > hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits) > in System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, > Int32 offsetX, Int32 offsetY, Int32 width, Int32 height) > in System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics > targetGraphics, IntPtr targetDC, Rectangle targetRectangle) > in > System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics > targetGraphics, IntPtr targetDC, Rectangle targetRectangle) > in System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, > Rectangle targetRectangle) > in System.Windows.Forms.Control.WmPaint(Message& m) > in System.Windows.Forms.Control.WndProc(Message& m) > in > System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) > in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& > m) > in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, > Int32 msg, IntPtr wparam, IntPtr lparam) > in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& > msg) > in > System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 > dwComponentID, Int32 reason, Int32 pvLoopData) > in > System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 > reason, ApplicationContext context) > in > System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, > ApplicationContext context) > in System.Windows.Forms.Application.Run(ApplicationContext context) > in > Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() > in > Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() > in > Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] > commandLine) > in EGF.My.MyApplication.Main(String[] Args) in > 17d14f5c-a337-4978-8281-53493378c1071.vb:riga 81 > in System.AppDomain._nExecuteAssembly(Assembly assembly, String[] > args) > in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence > assemblySecurity, String[] args) > in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() > in System.Threading.ThreadHelper.ThreadStart_Context(Object state) > in System.Threading.ExecutionContext.Run(ExecutionContext > executionContext, ContextCallback callback, Object state) > in System.Threading.ThreadHelper.ThreadStart() > InnerException: > > I tried to insert the code inside a try catch but without success. > Can anyone help me? > Thanks http://www.bobpowell.net/zoompicbox.htm Chris Thanks, it helped a lot ;)
Show quoteHide quote "Chris Dunaway" <dunaw***@gmail.com> ha scritto nel messaggio news:cee2c024-420b-4080-8ca3-904df2ddb3b9@e1g2000yqe.googlegroups.com... > On Apr 26, 4:20 am, "zzz" <z***@tin.it> wrote: >> Hi to all, >> inside a subroutine i have this code: >> >> Me.PictureBox1.Size = New Size(Me.dimensioni.Width * Me.zoom_factor, >> Me.dimensioni.Height * Me.zoom_factor) >> >> When the program goes out of sub I get the error: >> >> System.ComponentModel.Win32Exception non è stata gestita >> Message="Operazione completata" >> Source="System.Drawing" >> ErrorCode=-2147467259 >> NativeErrorCode=0 >> StackTrace: >> in >> System.Drawing.BufferedGraphicsContext.CreateCompatibleDIB(IntPtr >> hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits) >> in System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, >> Int32 offsetX, Int32 offsetY, Int32 width, Int32 height) >> in System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics >> targetGraphics, IntPtr targetDC, Rectangle targetRectangle) >> in >> System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics >> targetGraphics, IntPtr targetDC, Rectangle targetRectangle) >> in System.Drawing.BufferedGraphicsContext.Allocate(IntPtr >> targetDC, >> Rectangle targetRectangle) >> in System.Windows.Forms.Control.WmPaint(Message& m) >> in System.Windows.Forms.Control.WndProc(Message& m) >> in >> System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) >> in >> System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& >> m) >> in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr >> hWnd, >> Int32 msg, IntPtr wparam, IntPtr lparam) >> in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& >> msg) >> in >> System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 >> dwComponentID, Int32 reason, Int32 pvLoopData) >> in >> System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 >> reason, ApplicationContext context) >> in >> System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 >> reason, >> ApplicationContext context) >> in System.Windows.Forms.Application.Run(ApplicationContext >> context) >> in >> Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() >> in >> Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() >> in >> Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] >> commandLine) >> in EGF.My.MyApplication.Main(String[] Args) in >> 17d14f5c-a337-4978-8281-53493378c1071.vb:riga 81 >> in System.AppDomain._nExecuteAssembly(Assembly assembly, String[] >> args) >> in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence >> assemblySecurity, String[] args) >> in >> Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() >> in System.Threading.ThreadHelper.ThreadStart_Context(Object state) >> in System.Threading.ExecutionContext.Run(ExecutionContext >> executionContext, ContextCallback callback, Object state) >> in System.Threading.ThreadHelper.ThreadStart() >> InnerException: >> >> I tried to insert the code inside a try catch but without success. >> Can anyone help me? >> Thanks > > Try this: > > http://www.bobpowell.net/zoompicbox.htm > > Chris
form inheritence
Option strict after debug "Can't write dll because a process has it open" Changes not getting saved to data source return value, exit function Add inner control event. send the class type as a parameter. simmulate real rowEnter on DataGridView object. Update command to update field signing certificate error... |
|||||||||||||||||||||||