run-time error 480 can't create autoredraw image

  • 13 years ago

    Hi ! everyones Huh? [:^)]I'm using vb5

    Here is my problem

    I've made a program that load a big scanned image like 9600 x 7200 pixels

    into a picturebox i need to draw lines and textboxes create at runtime over the picture

    everything work fine for picture like 4800 x 3600 pixels which is the halfsize of the picture mentioned above.

    I'm wondering if there is any limitations for the size of an image load into a picture box.

    The definition of the error message is:Visual Basic can't create a persistent bitmap for automatic redraw of the form or picture. This error has the following cause and solution:

    · There isn't enough available memory for the AutoRedraw property to be set to True.

    Set the AutoRedraw property to False and perform your own redraw in the Paint event procedure or make the PictureBox control or Form object smaller and try the operation again with AutoRedraw set to True.

    ""The following is where the event to draw lines and textboxes is triggered""Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If dimrefcheck = False Then

    If Clk1% = 0 Then check if it's the first click
      Clk1% = 1
      FrstX! = X
      FrstY! = Y
      Text2.Text = ""
      Picture1.Circle (FrstX!, FrstY!), 10, RGB(255, 0, 0)
      showrubber = True
     
    Else
      Clk1% = 0
      Course% = (CourseHeading(FrstX!, FrstY!, X, Y, FullHeading#, Distance!))
      Text2.Text = Format(CStr(Distance!), "###0.00")
      Picture1.AutoRedraw = True
      Picture1.Circle (X, Y), 10, RGB(255, 0, 0)
      Picture1.Line (FrstX!, FrstY!)-(X, Y), vbRed
      trouve_midpoint FrstX!, X, FrstY!, Y
      i = i + 1
      Load lbldim(i)
      Set lbldim(i).Container = Picture1
      lbldim(i).BorderStyle = 1
      lbldim(i).Visible = True
      lbldim(i).Caption = "Réf: " & ref 'Format(Text1.Text / Text2.Text * Text3.Text, "###0.00")
      lbldim(i).Top = midpointy
      lbldim(i).Left = midpointx
      showrubber = False
      dimrefcheck = True
     
     
    End If
    Else
    If Clk1% = 0 Then
      Clk1% = 1 'verifie si c'est le premier clic de 2iem reference
      FrstX! = X
      FrstY! = Y
      Text3.Text = ""
      Picture1.Circle (FrstX!, FrstY!), 2.5, RGB(0, 255, 0)
      trouve_midpoint FrstX!, X, FrstY!, Y
      i = i + 1
      Load lbldim(i)
      Set lbldim(i).Container = Picture1
     
      showrubber = True
    Else









































      Clk1% = 0
      Course% = (CourseHeading(FrstX!, FrstY!, X, Y, FullHeading#, Distance!))
      Text3.Text = Format(CStr(Distance!), "###0.00")
      'Picture1.FillStyle = 1
      'Picture1.AutoRedraw = False
      Picture1.Circle (X, Y), 2.5, RGB(0, 255, 0)
      Picture1.Line (x1, y1)-(x2, y2)
      Picture1.Line (FrstX!, FrstY!)-(X, Y), vbMagenta
      If CHKDIM.Value = 1 Then
      trouve_midpoint FrstX!, X, FrstY!, Y
      i = i + 1
      Load lbldim(i)
      Set lbldim(i).Container = Picture1
      lbldim(i).BorderStyle = 1
      lbldim(i).Visible = True
      lbldim(i).Caption = Format(Text1.Text / Text2.Text * Text3.Text, "###0.00")
      lbldim(i).Top = midpointy
      lbldim(i).Left = midpointx
      showrubber = False
      Picture1.AutoRedraw = True ' Here is the place where the autoredraw suck!

      Else
      Picture1.AutoRedraw = True
      showrubber = False
      refreshdim
      End If
     End If
    End If
    xs = X: ys = Y 'Rectangle start position
    xl = X: yl = Y 'Rectangle Last position


























    End Sub

     Thank's to anyone that have an idea to solve this, help would be greatly appreciate.

    Georges.

     

  • 13 years ago

    The error message says it all.

    Setting autoredraw to true makes VB create a backup image which it then paints onto the screen every time Windows tells it that it needs to be redrawn. Normally this is set at design time, not in code as you are doing here.

    You probably need to  'do it yourself'

    Inside the PAINT event, copy the image held in memory to the picturebox or form, then use the drawing commands to add the lines.

    Or, draw the lines on an 'off screen image' too, and copy the offscreen image to the screen, lines and all.

    Remember most displays do not show images of this size at full resolution: the display image can only really be as large as the screen. (1024 x 768 on a typical older laptop for example..)

    Even if you use a zoom function, you can only display an area the size of the screen, so the display image does not have to match the source image pixel for pixel.

     

     

     

     

     

  • 13 years ago

    Confused [8-)]Thank's Jeff to take the time responding my question.

    Because i'm not sure to understand what it will happen with  the lines if i zoom or scroll in the picturebox, i'm suppose to implementing a zoom command and a panning method that will move the drawing on and off inside the picturebox .

    The lines are in fact dimension lines and the textboxes created at runtime are the dimensions that are positionned on the midpoint of the line that has been created.

    should i put the coordinate of the lines and the textboxes in an array to be able to redraw the lines that are already on the drawing?

    Could you give me an example of what you are saying!

    Thank's

    Georges

     

     

  • 13 years ago

    See if this helps...

    I have to make some assumptions here because I dont know what you are trying to do.

    So I am assuming you have a picture that represents a physical output, like a 150 x 100  photograph.

    To represent the image as a 15 x 10 cm grid, you need to know how many pixels equal a cm. (This is effectively the dpi of the output)

    Lets say your source image is a nice easy 1500 x 1000 pixel image.

    That means that every 100 pixels equals a cm on the page.

    Now, if you draw a grid on the source image every 100 pixels, and display some part of the image at full size, you will see a one pixel line every 100 pixels.

    If you zoom out, that single line grid will vanish among the much larger number of pixels from the raw image. Zoom in, and the grid line will widen to more than one pixel wide.

    So ideally, you draw the grid onto the zoomed image, so that the lines remain one pixel wide.

    If you display the image at 50% of the orginal, the lines are drawn every 50 pixels.

    eg 100 times the scale factor of 0.5

    If you zoom in to 3 times the size, the grid lines are drawn at 100 x scale factor of 3.0.

    The lines themselves start at 0,0 on the original.

    However, if you scroll, then 0,0 of the display is no longer the right place to start.

    You can either continue to draw the whole grid, offset by the scroll (so a lot of the grid lines are drawn 'offscreen')

    Or you work out where the first visible line should be, and draw the remainder at the correct distance away from that.

     

  • 13 years ago

    Ok! Jeff

    I will explain exactly my problem.

    The program that i am trying to do is loading into a picture box a big scanned drawing like 36"x48" (9600 x 7200 pixels) i am working in a construction company,and we always work with drawing of that size,so after the dwg. is load into the pict. box i have to look on the drawing to find a dimension that is already on the drawing(Reference Dimension.),those drawing are "TIFF"picture, i put this dimension in a text box and i use it as a reference to build a new scale for the picture in the pict. box.,after this i pick the two dimension line that are delimiting the Reference Dimension and i calculate the distance between these two points and i draw a magenta line meaning that is the ref. line.

    After this step, every two picks into the picture box create a new line between these picks and put the lenght of this line in a textboxe create at runtime and so on , and so on .

    The application work perfectly for pictures that are the half of the big one so (4800 x 3600) but bigger than that, i have the error message "run-time error 480 can't create autoredraw image" as soon as i first pick into the pict.box,i absolutely need the autoredraw property set to true otherwise when i scroll the drawing the dimension lines and the textboxes containing the lenght that has been created disapear.

    I 'm wondering if there is a way to bypass this memory leak with other methods like special API call or something,

    ps.You told me  "Inside the PAINT event, copy the image held in memory to the picturebox or form, then use the drawing commands to add the lines." i like this idea but i did'nt know how to this that why i ask you an exemple...

    Thank!

     Georges

  • 12 years ago

    Georges,

    I have a very similar problem. I did load pictures (roadmaps) into a picturebox and did draw biking routes on it. Maps around 5000*4000. Operating system Windows 2000

    Now I installed XP and experience your problem too. Since I do have a dual boot machine now I still can woork when 2000 is active, but cannot run in XP.

     I will keep on looking to solve the problem.

    Henk.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.” - Dennis Ritchie