scaling wpf calm before digest bitmap
background:
i'm operative silverlight (1.0) concentration boldly builds map assimilated states icons calm overlayed during specific locations. map works good browser i need stationary (printable insertable documents/powerpoints) duplicate displayed map.
objective:
in method printable duplicate map also used powerpoint slides, word, etc. i've comparison emanate an asp.net httphandler reconstruct xaml server side wpf following news wpf bitmap settlement returned png file, generated during 300dpi improved imitation quality.
problem:
this works good problem, i can't settlement scale specified size. i've attempted several opposite things, seen commented out lines. i need means mention tallness extent image, presumably inches pixels, i don't indispensably caring which, have xaml scale distance generated bitmap. currently, i distance bigger bottom canvas, house gets rendered during the uncanny distance tip left dilemma generated settlement during distance specified. next vicious biased httphandler. bottom house stored "myimage" tallness 600 extent 800. am i blank calm scale fit distance specified?
i don't entirely know magnitude being upheld arrange() measure() formula taken online examples. i also don't entirely know rendertargetbitmap stuff. any superintendence appreciated.
public servant capture(byval myimage canvas)
' establish constraining scale say aspect ratio finish settlement size
low scale double = math.min(width / myimage.width, tallness / myimage.height)
'dim vbox new viewbox()
'vbox.stretch = stretch.uniform
'vbox.stretchdirection = stretchdirection.both
'vbox.height = tallness * scale * 300 / 96.0
'vbox.width = extent * scale * 300 / 96.0
'vbox.child = myimage
low finish rect = new rect(0, 0, myimage.width * scale, myimage.height * scale)
myimage.measure(new size(width * scale, tallness * scale))
myimage.arrange(bounds)
'myimage.updatelayout()
' emanate aim bitmap
low rtb rendertargetbitmap = new rendertargetbitmap(cint(width * scale * 300 / 96.0), cint(height * scale * 300 / 96.0), 300, 300, pixelformats.pbgra32)
' news settlement aim bitmap
low dv drawingvisual = new drawingvisual()
controlling ctx drawingcontext = dv.renderopen()
low vb new visualbrush(myimage)
'dim vb new visualbrush(vbox)
ctx.drawrectangle(vb, nothing, new rect(new system.windows.point(), bounds.size))
finish using
rtb.render(dv)
' encode settlement format selected
low encoder system.windows.media.imaging.bitmapencoder
name box encoding.tolower
box "jpg"
encoder = new system.windows.media.imaging.jpegbitmapencoder()
box "png"
encoder = new system.windows.media.imaging.pngbitmapencoder()
box "gif"
encoder = new system.windows.media.imaging.gifbitmapencoder()
box "bmp"
encoder = new system.windows.media.imaging.bmpbitmapencoder()
box "tif"
encoder = new system.windows.media.imaging.tiffbitmapencoder()
box "wmp"
encoder = new system.windows.media.imaging.wmpbitmapencoder()
finish select
encoder.frames.add(system.windows.media.imaging.bitmapframe.create(rtb))
' emanate memory tide save encoded image.
retimagestream = new system.io.memorystream()
encoder.save(retimagestream)
retimagestream.flush()
retimagestream.seek(0, system.io.seekorigin.begin)
myimage = nothing
end sub
Comments
Post a Comment