Forum > Graphics
Is it possible to Canvas.Textout and Render is scaled (stretch==true)?
ozznixon:
I am working on a project where I need to render 5 to 8 telnet sessions like little "view screens". I have all of the code ready... but, it does not work. Could someone help (explain the mistake and makes a working example?).
Basically, I create a TImage (640x480) scaled down to div 4, click a toolbar button and mimic a session. In that event, I do:
[/code]
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- var w, h: Integer;begin if ssLeft in Shift then begin ReleaseCapture; Perform(WM_SysCommand, $F012, 0); end; Image1.Canvas.Brush.Color:=clBlack; Image1.Canvas.Font.Color:=clYellow; Image1.Canvas.Font.Size := 12; h := Image1.Canvas.Font.Height; // in pixels Image1.Canvas.TextOut(0, 20 + h, 'Superior'); w := Image1.Canvas.TextWidth('Big')+12; Image1.Canvas.Font.Color:=clLime; Image1.Canvas.Font.Size := 6; h := Image1.Canvas.Font.Height; // in pixels //Image1.Canvas.Font.Style := Image1.Canvas.Font.Style + [fsBold]; Image1.Canvas.TextOut(W, 20 + h, 'Bulletin Board Software');
The flaw is, it is rendering at 12, and 6 pixels respectively - on the small TImage. Instead of running the code, and rendering scaled. * Or am I using the wrong Component/Canvas?
Thanks!
Ozz
KodeZwerg:
I do not fully understand yet what you try to do.
In most cases I do use a TBitmap (or similar) and draw on that what I want and when done I copy it to a TImage.
If you can show on an Image what you want to have when done, it would simplify to help you.
ozznixon:
Okay Screenshot 1 - is what I am getting with the code in my first post. (I will fix the overlap later)...
Screenshot 2 - is what I am trying to achieve. I was able to produce screenshot 2, by doing everything in screenshot 1 - at 640x480, then added a new button that changes the size to "div 4" - to get what I am trying to produce. (Which makes me think I need to do some type of Double Buffering, or Offscreen Paint, Copy, Paste to the scaled one? - And avoid flickering, as this will run all day).
Thaddy:
What you want to achieve needs the font to be scaled in pixels, not points. That means the font needs to have a negative value (pixels) instead of points (positive value). That is the ONLY way to be accurate.
Formula's are like this:
(Given LOGFONT structure on Windows)
--- Code: ---lfHeight := -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72); // pixels
PointSize := MulDiv(-lfHeight, 72, GetDeviceCaps(hDC, LogPixelsY);// points
--- End code ---
But note that for high resolution screens you should call GetDeviceCaps first. The above formulae are for Windows only, but may be Lazarus supports it cross-platform.
KodeZwerg:
Thats how I calculate the Size field of font.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Round((Abs(GetFontData(AFont.Handle).Height) * 72 / AFont.PixelsPerInch));While AFont is a TFont, crossplatform.
Navigation
[0] Message Index
[#] Next page