show render.Capture data as image?

Hey! I want to show the data that i get from render.Capture as an image, how i would do this?

[editline]15th February 2015[/editline]

Anyone?

You could create and set an html vgui panel to use this html;


[[<img width="512" height="512" src="data:image/png;base64, ]] .. util.Base64Encode( Data ) .. [["/>]]

change png to jpeg if that’s what you captured as.


function sendScreenshot( )
	local RCD = { }

	RCD.format = "jpeg"
	RCD.h = ScrH()
	RCD.w = ScrW()
	RCD.quality = 190 //100 is max quality, but 70 is good enough.
	RCD.x = 0
	RCD.y = 0

	local Picdata = render.Capture(RCD)
	
	local window = vgui.Create( "DFrame" )
	if ScrW() > 640 then -- Make it larger if we can.
		window:SetSize( ScrW()*0.9, ScrH()*0.9 )
	else
		window:SetSize( 640, 480 )
	end
	window:Center()
	window:SetTitle( "Screenshot" )
	window:SetVisible( true )
	window:MakePopup()

	local html = vgui.Create( "HTML", window )

	local button = vgui.Create( "DButton", window )
	button:SetText( "Close" )
	button.DoClick = function() window:Close() end
	button:SetSize( 100, 40 )
	button:SetPos( (window:GetWide() - button:GetWide()) / 2, window:GetTall() - button:GetTall() - 10 )

	html:SetSize( window:GetWide() - 20, window:GetTall() - button:GetTall() - 50 )
	html:SetHTML( "<img width=" .. "512" .. " height=" .. "512" .. " src=" .. "data:image/jpeg;base64" .. ", ]]" .. util.Base64Encode( Picdata ) .. "[[" .. "/>" .. "]]" )
	html:SetPos( 10, 30 )
end

Doesn’t work :frowning:

If you are going to remove the multiline brackets, remove all of them, your html string is malformed.

No results and errors…

Look at the string I posted…


print( [[<img width="512" height="512" src="data:image/jpeg;base64, ]] .. "SomeData" .. [["/>]] )

>> <img width="512" height="512" src="data:image/png;base64, SomeData"/>

vs yours…


print( "<img width=" .. "512" .. " height=" .. "512" .. " src=" .. "data:image/jpeg;base64" .. ", ]]" .. "SomeData" .. "[[" .. "/>" .. "]]" )

>> <img width=512 height=512 src=data:image/jpeg;base64, ]]SomeData[[/>]]

Never knew about [].

Did


html:SetHTML( [[<img width="512" height="512" src="data:image/jpeg;base64, ]] .. util.Base64Encode( Picdata ) .. [["/>]] )

But it still doesnt show anything, i may be dumb sometimes but i try to understand why it doesnt work.

I copied and pasted your code and it worked fine for me.

Try this in luapad or something…



local jpeg = {
    format = "jpeg";
    quality = 100;
    h = ScrH();
    w = ScrW();
    x = 0;
    y = 0;
}

local function screenshot()
    local capture = render.Capture( jpeg )
    local html = [[<img width="512" height="512" src="data:image/jpeg;base64, ]] .. util.Base64Encode( capture ) .. [["/>]]
    
    local window = vgui.Create( "DFrame" )
    
    window:SetSize( 600, 600 )
    window:Center()
    window:SetTitle( "Screenshot" )
    window:SetVisible( true )
    window:MakePopup()
    
    local dhtml = vgui.Create( "HTML", window )
    
    dhtml:SetSize( window:GetWide() - 37.5, window:GetTall() - 37.5 )
    dhtml:SetPos( 37.5, 37.5 )
    dhtml:SetHTML( html )
end

screenshot()


http://puu.sh/fXePN/bb1f53e59e.jpg