Canvas Class

I am looking for a canvas class that can draw a line or circle on picture and save it.

I can pay up to $50.00 for this class

Like Windows paint

big difference between drawing a line or a circle
and the functionality of Microsoft PAINT

I have a RealBasic app called PAINTDS that duplicates everything that MSPAINT can do, plus a lot more… but it is an APP not a class

i only need to mark some point using like circle or line and the save on Db

Class EZCanvas inherits Canvas...


//Property
originalPic As Picture


//Event
Sub Open()
  AcceptFileDrop("")  //receive DropObject events for files
End Sub


//Event
Sub DropObject(obj As DragItem, action As Integer)

  dim p As Picture = Picture.Open(obj.FolderItem) //try to open file (assuming only file drops)
  
  if p = nil then  //not openable as picture
    MsgBox "Couldn't open file: " + obj.FolderItem.Name
    return
  end
  
  originalPic = p //store pic and redraw
  Invalidate

End Sub


//Event
Sub Paint(g As Graphics, areas() As REALbasic.Rect)

  g.ForeColor = &cFFFFFF               //fill background
  g.FillRect 0, 0, g.Width, g.Height
  
  if originalPic <> nil then           //draw pic and extra lines to canvas
    g.DrawPicture originalPic, 1, 1
    drawExtraLines(g, originalPic.Width, originalPic.Height)
  else                                 //else draw instructions
    g.ForeColor = &c333333
    g.DrawString "drop picture file here then context click to save", 10, 30
  end
  
  g.ForeColor = &c808080               //draw border
  g.DrawRect 0, 0, g.Width, g.Height

End Sub


//Method
Sub drawExtraLines(g As Graphics, w As integer, h As integer)
  
  g.PenWidth = 30            //use thick lines
  g.PenHeight = 30
  
  g.ForeColor = &c00FF0044   //arbitrary oval and line
  g.DrawOval 30, 30, w - 60, h - 60
  
  g.ForeColor = &c8000FF44
  g.DrawLine w * 0.2, h * 0.8, w * 0.9, h * 0.3
  
  g.PenWidth = 1             //reset thickness
  g.PenHeight = 1

End Sub


//Event
Function ConstructContextualMenu(base as MenuItem, x as Integer, y as Integer) As Boolean

  if originalPic = nil then return false //if no picture then skip
  
  base.Append new MenuItem("save change...") //add an item and show it
  return true

End Function


//Event
Function ContextualMenuAction(hitItem as MenuItem) As Boolean
  //assume to have selected the single contextual menu item
  
  dim f As FolderItem = GetSaveFolderItem("", "untitled.png") //get a file
  if f = nil then return false
  
  dim editedPic As new Picture(originalPic.Width, originalPic.Height) //duplicate originalPic
  editedPic.Graphics.DrawPicture originalPic, 0, 0
  
  drawExtraLines(editedPic.Graphics, editedPic.Width, editedPic.Height) //draw extra into duplicate
  
  editedPic.Save(f, Picture.SaveAsPNG) //save to file
  
End Function

50$ please :slight_smile: ok, really, will need more specifics

how do you want to mark the points? The user can add and drag them around or are they are coming from a function?

And what picture formats do you need?

mark with the mouse point

Dave’s stuff is spot on to what you want (me thinks).

You already have doofus providing really good help,

Below are some other links to either plugins or code/examples which are probably useful:
http://www.monkeybreadsoftware.de/realbasic/plugin-imagemagick.shtml - Monkeybread’s ImageMagick
http://www.strout.net/info/coding/rb/intro.html - Joe’s MiniPaint
http://garrypettet.com/fgthumbnailcanvas/ - Garry’s FTG Thumbnail class
http://alwaysbusycorner.wordpress.com/2011/09/15/realbasic-canvas-tutorial-lesson-1/ - Alain’s Canvas Tutorials

thanks

Hi doofus can you make this work

I’m not sure what you’re asking.

Do you want to learn how to build it or would you rather just pay to have it done? Either way you’ll need to explain in much more detail.

i like to learn

but if i no get it to work i can pay to get this done.

i need to use the mouse to draw like a circle on the picture to mark some bad spots of the picture

thanks

How do you want to the user to draw a circle? Click center and drag out radius or click a bounding box corner and drag out the other corner? Once initially set can the circle be selected and edited, and if so how to select? Are circle color, line thickness and transparency options? Will there be multiple circles? How should the image be shown: upper-left aligned, centered, scaled to fit, zoomable with scrollbars? What sort of edited image output do you need: a picture object, png file, jpg data, etc.

the picture is scaled to canvas size and the user need to draw pixels around the area

Build this class and drop it on a window. Call setPicture(myImage) to load and display myImage scaled to the Canvas size. The user can scribble on it then call getPicture() for the edited picture.

[code]Class EZCanvas2 inherits Canvas

Protected thePic As Picture //Property - the current image

Protected lastXY(1) As Integer //Property - last mouse coordinates

Sub setPicture(p As Picture) //Method - load or clear the current image
if p = nil then
thePic = nil
else
thePic = new Picture(Width, Height, 32)
thePic.Graphics.DrawPicture p, 0, 0, Width, Height, 0, 0, p.Width, p.Height
end
Invalidate
End Sub

Function getPicture() As Picture //Method - get edited pic
return thePic
End Function

Sub Paint(g As Graphics, areas() As REALbasic.Rect) //Event - draw the scene
if thePic <> nil then
g.DrawPicture thePic, 0, 0
else
g.ForeColor = &cFFFFFF
g.FillRect 0, 0, Width, Height
end
End Sub

Function MouseDown(X As Integer, Y As Integer) As Boolean //Event - store mouse coordinates
if thePic = nil then return false
lastXY(0) = X
lastXY(1) = Y
return true
End Function

Sub MouseDrag(X As Integer, Y As Integer) //Event - draw line to new coordinates
thePic.Graphics.ForeColor = &c0
thePic.Graphics.DrawLine lastXY(0), lastXY(1), X, Y
lastXY(0) = X
lastXY(1) = Y
Invalidate
End Sub

//========================= for easy testing, drop in image file
Sub Open()
AcceptFileDrop("")
End Sub

Sub DropObject(obj As DragItem, action As Integer)
setPicture(Picture.Open(obj.FolderItem))
End Sub[/code]

hi thanks

is working perfects it flick but it works

hi send me you paypal email

thanks

hi doofus
way this no works
window1.EZCanvas21.setPicture= Picture.Open(f) <<< this item does not exist

It looks like you should use window1.EZCanvas21.setPicture Picture.Open(f) - remove the =

thanks

For flickering on MS Windows I think you turn on DoubleBuffer and turn off EraseBackground in the Canvas. And in Invalidate use False for the eraseBackground parameter. I don’t really know though, only have macs.

If you prefer the syntax “EZCanvas21.setPicture = myPic” then change the setPicture parameter to have assigns…
Sub setPicture(Assigns p As Picture)

And for more efficient drawing change the MouseDrag and Paint events to this…

[code]Sub MouseDrag(X As Integer, Y As Integer)
thePic.Graphics.DrawLine lastXY(0), lastXY(1), X, Y

Invalidate( Min(X,lastXY(0)), Min(Y,lastXY(1)), Abs(X-lastXY(0))+1, Abs(Y-lastXY(1))+1, False ) //dirty rect

lastXY(0) = X
lastXY(1) = Y
End Sub

Sub Paint(g As Graphics, areas() As REALbasic.Rect)
if thePic <> nil then
if areas.Ubound = -1 then //full redraw
g.DrawPicture thePic, 0, 0
else //redraw just dirty rects
for each r As REALbasic.Rect in areas
g.DrawPicture thePic, r.Left, r.Top, r.Width, r.Height, r.Left, r.Top, r.Width, r.Height
next
end
else
g.ForeColor = &c000000
g.FillRect 0, 0, g.Width, g.Height
end
End Sub[/code]