Hi
I would like to convert a smaller area from a larger image into a separate image and print it out. But I can only choose the same or smaller size.
Dim pic As New Picture(300 , 300)
How can I move this NewPicture to a specific position of the large image to copy that exact area?
Dim pic As New Picture(300 , 300)
// (300 , 300, 32) if you dont want it to be transparent
//draw on it..
pic.graphics.fillrect 20,30,100,100
dim biggerpic as new picture (2000,2000)
biggerpic.graphics.forecolor = &cff0000
// red. (probably Drawcolor or something similar in API2)
biggerpic.graphics.fillrect 0,0,2000,200 //filled with red
biggerpic.graphics.drawpicture pic,18,531 // put 'Pic' at some position of biggerpic
I need the reverse. I have a large picture and need to copy a small one from it.
As I understand your example, you draw a small picture in a large one.
I’ve build this method to resize a picture
Public Function ResizePicture(inPicture as picture, newWidth as integer, newHeight as integer) As picture
'-------------------------------------------------------------------------------------
'- Bildgröße anpassen (skalieren) / adapt size of a picture -
'-------------------------------------------------------------------------------------
if inPicture = nil then
return inPicture
end if
var r as new picture( newWidth, newHeight, 32 )
'r.HorizontalResolution
'r.VerticalResolution
r.Transparent = 1
r.graphics.drawpicture inPicture, 0, 0, newWidth, newHeight, 0, 0, inPicture.width, inPicture.height
return r
End Function
I need a selected part of a bigger picture.
Wait, it should be able to be realized with: g.DrawPicture(MyImage, 0, 0, MyImage.Width * scale, MyImage.Height * scale, 0, 0, MyImage.Width, MyImage.Height)
I am experimenting…
Use DrawPicture.
You can specify the source x,y,width,height and also specify destination x,y,width,height (use 0,0,source width,source height).
All of this should be explained in the documentation.
With this code in a canvas :
g.DrawPicture(mPict, 0, 0, me.Width, me.Height, 30, 30, 100, 100)
You will have only a part (square 100 x 100 pixels from x = 30 and y = 30) of mPict drawn if mPict is bigger than the canvas
Use this syntax:
Graphics.DrawPicture(Image As Picture, x As Double, y As Double [, destWidth As Double] [, destHeight As Double] [, sourceX As Double] [, sourceY As Double] [, sourceWidth As Double ] [, sourceHeight As Double])
It’s a bug in the docs, I’ve reported it. The old documentation is still available on this URL:
with the new one currently on:
Which allows find in page (command-f / control-f) to work, which doesn’t in the built in docs.
I use my method for these purposes
Public Function CropPicture(inPicture as picture, xVon as integer, yVon as integer, xBis as integer, yBis as integer) As picture
// ------------------------------------------------------------------------------------------------------------
// Bildausschnitt erzeugen
// ------------------------------------------------------------------------------------------------------------
if inPicture is nil then
return nil
end if
Dim r as new picture( xBis-xVon, yBis-yVon, 32 )
r.graphics.drawpicture inPicture, _ 'das zu malende Bild
0, 0, inPicture.width, inPicture.height , _ 'die zu skalierende Größe (die Bildgröße bleibt gleich)
xVon, yVon, xBis, yBis 'der Bildausschnitt
return r
End Function
It works!
Dim pic As New Picture(Display.Width , Display.Height) // beim Ändern der Maße wird abgeschnitten
Display.DrawInto( pic.Graphics,0 ,0 )
g.DrawPicture(pic,0, 0, CanvasPicture.Width, CanvasPicture.Height, CanvasPicture.Left-display.Left , Me.top, CanvasPicture.Width, Me.Height)
Thank’s!