Drawing pixels inside a grid in VB.NET -
i have paint program shows zoomed in version of image editing , have interpolation mode set "nearest neighbor". also, have pixel grid drawn on there , grid on each place there pixel on image. shows accurate amount of pixels. added brush draw on picturebox want brush draw on squares in other drawing programs pixel grid views. long mouse pointer within pixel square, fill inside of pixel square in. here codes: (my picturebox named canvaseditor.)
the code generates pixel grid:
private sub canvaseditor_paint(byval sender object, byval e system.windows.forms.painteventargs) handles canvaseditor.paint if not bmpnew nothing e.graphics.drawimage(bmpnew, 0, 0) end if dim g graphics = e.graphics dim pn new pen(color.dimgray) '~~~ color of lines dim x integer dim y integer dim intspacing integer = 8 '~~~ spacing between adjacent lines '~~~ draw horizontal lines x = canvaseditor.width y = 0 canvaseditor.height step intspacing g.drawline(pn, new point(0, y), new point(x, y)) next '~~~ draw vertical lines y = canvaseditor.height x = 0 canvaseditor.width step intspacing g.drawline(pn, new point(x, 0), new point(x, y)) next end sub
here interpolation code: (tl14 1 of many pictureboxes contain original image edited in canvaseditor , scalefactor variable integer set 1)
if tl14.image nothing else canvaseditor.image = nothing canvaseditor.image = tl14.image canvaseditor.width = tl14.width * 8 + 1 canvaseditor.height = tl14.height * 8 + 1 'load , draw image(s) once backgroundimage1 = new bitmap(tl14.image) bmpnew = new bitmap(canvaseditor.width * scalefactor, canvaseditor.height * scalefactor) using g graphics = graphics.fromimage(bmpnew) g.interpolationmode = system.drawing.drawing2d.interpolationmode.nearestneighbor g.pixeloffsetmode = system.drawing.drawing2d.pixeloffsetmode.half g.drawimage(backgroundimage1, 0, 0, bmpnew.width, bmpnew.height) end using canvaseditor.focus() groupbox13.focus() end if
this allows me click on original tl14 picturebox , load image canvaseditor picturebox, scales larger size, draws pixelgrid, , takes away antialiasing when images stretched. in end:
but when draw on it, doesnt line inside squares. draws mouse how restrict that?
Comments
Post a Comment