Canvas resize

Can any one explain way when Resize Canvas and save a Picture on a file you see the view full size of the canvas and no the resize.
i am lost in this

I am not sure I follow.

If you resize the canvas and have a picture in the canvas you will need to make sure that the picture is redrawn and scaled to the new canvas size.

So in the resize event of the canvas call:

me.invalidate

That will force the paint event to fire.

In the paint event, draw the picture like:

g.DrawPicture(p,0,0,me.width,me.height,0,0,p.width,p.height)

Where p is the picture you are trying to draw.

Doing this will properly scale the picture to the full size of the canvas - whatever size the canvas is at currently.

Probably because you are displaying the picture at a smaller sized (by using g.DrawPicture in the paint event and supplying all the optional parameters to resize the image), but you are saving the Picture itself, which is still the original size. Resizing it when you draw it on the canvas does not change the original image, just the display of it.

You have to resize the image itself, and then save that. The best way would be to create a new Picture object with the new dimensions and then draw the original into the new picture (just like you draw it to the canvas).

dim p as new picture(newWidth, newHeight, 32)
p.graphics.drawpicture(originalPicture, 0, 0, p.width, p.height, 0, 0, originalPicture.width, originalPicture.height)
// save p

If MainBarCode.txtValue.Text.Trim.len=0 Then Exit Sub

barcode.barBackColor=self.barBackColor
barcode.code=self.code
barcode.barFontName=self.barFontName
barcode.barFontSize=self.barFontSize
barcode.barForeColor=self.barForeColor
barcode.barHeight=self.barHeight
barcode.barType=self.barType
barcode.checkCharacter=self.checkCharacter
barcode.Code128Set=self.Code128Set
barcode.H=self.H
barcode.leftMargin=self.leftMargin
barcode.N=self.N
barcode.textOnTop=self.textOnTop
barcode.topMargin=self.topMargin
barcode.X=self.X
barcode.I=self.I
barcode.UPCEANSupplement2=self.UPCEANSupplement2
barcode.UPCEANSupplement5=self.UPCEANSupplement5
barcode.supplement=self.supplement
barcode.UPCESystem=self.UPCESystem
barcode.codeTextTop=self.codeTextTop

barcode.width=self.width
barcode.height=self.height
barcode.textOnTop=false

barcode.paintBarcode(g)

//creates new picture
dim pic as new Picture(width, height, 32)

barcode.paintbarcode(pic.Graphics)

dim min as integer

min=height
if (min>width) then min=width

dim newpic as new Picture(width,height, 32)
dim surf0 as RGBSurface = pic.RGBSurface
dim surf1 as RGBSurface = newpic.RGBSurface
dim x, y as Integer

for y = 0 to height - 1
for x = 0 to width - 1
surf1.Pixel(y, min - x) = surf0.Pixel(x, y)
next x
next y

g.Drawpicture newpic,(g.width-newpic.width)/2,(g.height-newpic.height)/2

//g.DrawPicture(newpic,0,0)
//g.Drawpicture newpic,(100,291)

Dim f,f1 as FolderItem
#If TargetWin32 then
#if DebugBuild then
f=New FolderItem(“C:\GasRb_BarCode\barToPrint.png”)
f1=New FolderItem(“C:\GasRb_BarCode\barToPrint2.png”)
#ELSE
f=New FolderItem(“barToPrint.png”)
#endif
#ELSE
f=New FolderItem(“barToPrint.png”)
#endif

// creates new picture

dim iFormat as integer

dim p as new picture(84, 291, 32) <<<<<<<< this is the size i need but it change to very small the graphics but the box of picture have the normal size of 84,291

iFormat=p.SaveAsPNG
p.graphics.drawpicture(newpic, 0, 0, p.width, p.height, 0, 0, newpic.width, newpic.height)
p.Save(f1,iFormat)

iFormat=Picture.SaveAsPNG

newpic.save(f,iFormat)

the picture have to be Save in 84,291 vertical

https://drive.google.com/file/d/0B-0OCVXucD8Ca2dHU09iYTNjUkU/edit?usp=sharing

You should change

dim newpic as new Picture(width,height, 32)

to

dim newpic as new Picture(height,width, 32)

Hi Tim thanks for you help

still does not work if you like i can send you the Projects so you can see it

i am confused with all this canvas

thanks to all help i found the problem is fix and this is my new code

If MainBarCode.txtValue.Text.Trim.len=0 Then Exit Sub

barcode.barBackColor=self.barBackColor
barcode.code=self.code
barcode.barFontName=self.barFontName
barcode.barFontSize=self.barFontSize
barcode.barForeColor=self.barForeColor
barcode.barHeight=self.barHeight
barcode.barType=self.barType
barcode.checkCharacter=self.checkCharacter
barcode.Code128Set=self.Code128Set
barcode.H=self.H
barcode.leftMargin=self.leftMargin
barcode.N=self.N
barcode.textOnTop=self.textOnTop
barcode.topMargin=self.topMargin
barcode.X=self.X
barcode.I=self.I
barcode.UPCEANSupplement2=self.UPCEANSupplement2
barcode.UPCEANSupplement5=self.UPCEANSupplement5
barcode.supplement=self.supplement
barcode.UPCESystem=self.UPCESystem
barcode.codeTextTop=self.codeTextTop

barcode.width=self.width
barcode.height=self.height
barcode.textOnTop=false

barcode.paintBarcode(g)

//creates new picture

dim pic as new Picture(width, height, 32)
g.Drawpicture pic,(g.width-pic.width)/2,(g.height-pic.height)/2

barcode.paintbarcode(pic.Graphics)

dim min as integer

min=height
if (min>width) then min=width

dim newpic as new Picture(width,height, 32)
dim surf0 as RGBSurface = pic.RGBSurface
dim surf1 as RGBSurface = newpic.RGBSurface
dim x, y as Integer

for y = 0 to height - 1
for x = 0 to width - 1
surf1.Pixel(y, min - x) = surf0.Pixel(x, y)
next x
next y

g.Drawpicture newpic,(2,-25)

Dim f,f1 as FolderItem
#If TargetWin32 then
#if DebugBuild then
f=New FolderItem(“C:\GasRb_BarCode\barToPrint.png”)
#ELSE
f=New FolderItem(“barToPrint.png”)
#endif
#ELSE
f=New FolderItem(“barToPrint.png”)
#endif

dim iFormat as integer
Dim MyPic As New Picture(84,291,32)
iFormat=MyPic.SaveAsPNG
MyPic.graphics.drawpicture(newpic, 2, -25)
MyPic.Save(f,iFormat)

iFormat=MyPic.SaveAsPNG

MyPic.save(f,iFormat)

Alexis, when posting code, click the icon above the text before pasting. This will look much better.

thanks