|
Post by angelo2449 on Sept 18, 2023 11:36:26 GMT -5
Hi guys, I would like to write a part of the program that allows me to insert a scaled image.
So I think it should be a normal window with a graphic part in which to import an image of your choice which should occupy the entire graphic area.
Anyone have any ideas, thanks.
|
|
|
Post by Rod on Sept 18, 2023 12:35:40 GMT -5
Images are of a variable width and height. So are they squished and squashed or cropped to fit a fixed width height ratio display. If cropped. Top left, centred?
|
|
|
Post by tsh73 on Sept 18, 2023 12:59:14 GMT -5
Loading any image except BMP requires windows API
Scaling image requires Windows API (you can do it with math, pixel by pixel, but it'll take forever and a half)
Besides that, you can use sprite background to scale picture UP and believe bmpbutton to scale picture DOWN (not sure, should check)
Oh. You can modify your BMP so LB considers it a sprite, and then use spritescale command, up or down.
(but for all these methods, scaled picture would not look very good, likely no good at all - but should check)
|
|
|
Post by tsh73 on Sept 18, 2023 13:14:29 GMT -5
|
|
|
Post by angelo2449 on Sept 18, 2023 13:39:34 GMT -5
I wrote it like that but I don't like it!
WindowWidth = 1150 WindowHeight = 730 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
BackgroundColor$ = "cyan" ForegroundColor$ = "black"
loadbmp "Vuoto", "C:\AutocadSupporto\CalcoloFV\Default\AziVuoto.bmp" bmpbutton #azim.gra, "C:\AutocadSupporto\CalcoloFV\Default\AziVuoto.bmp", [Apri.Immagine], UL, 220, 140 button #azim.b0, "RESET", [Reset.Immagine], UL, 650, 620, 120, 50 button #azim.b1, "APRI", [Apri.Immagine], UL, 800, 620, 120, 50 button #azim.b2, "SALVA", [Salva.Immagine], UL, 950, 620, 120, 50
open "Azimuth" for window as #azim #azim, "font courier 12 bold" #azim, "trapclose [quit.azim]"
gosub [Input.Committente]
Radice$ = "C:\AutocadSupporto\CalcoloFV\LavoriFV\" + Committente$
if FileExists(Radice$ + "\Azimuth\Indice.dat") then
open Radice$ + "\Azimuth\Indice.dat" for input as #im input #im, ImmagineDaAprire$ close #im
loadbmp "Pieno", ImmagineDaAprire$ #azim.gra, "bitmap Pieno"
end if
wait
' --------------------------
' @[Reset.Immagine]
[Reset.Immagine]
if AiutoGen = 1 then
Help$ = "ResetImmagine" gosub [Aiuto.Rapido] wait
end if
if FileExists("C:\AutocadSupporto\CalcoloFV\LavoriFV\" + Committente$ + "\Azimuth\Indice.dat") then kill "C:\AutocadSupporto\CalcoloFV\LavoriFV\" + Committente$ + "\Azimuth\Indice.dat"
#azim.gra, "bitmap Vuoto" Notice "Info" + chr$(13) + "Reset eseguito"
end if
wait
' --------------------------
' @[Apri.Immagine]
[Apri.Immagine]
if AiutoGen = 1 then
Help$ = "ApriImmagine" gosub [Aiuto.Rapido] wait
end if
Radice$ = "C:\AutocadSupporto\CalcoloFV\LavoriFV\" + Committente$ + "\Azimuth\*.bmp"
filedialog "Open - Apri", Radice$, ImmagineDaAprire$ ImmagineDaAprire$ = trim$(ImmagineDaAprire$) if ImmagineDaAprire$ = "" then wait
loadbmp "Pieno", ImmagineDaAprire$ #azim.gra, "bitmap Pieno"
wait
' ----------------------------
' @[Salva.Immagine]
[Salva.Immagine]
if AiutoGen = 1 then
Help$ = "SalvaImmagine" gosub [Aiuto.Rapido] wait
end if
if ImmagineDaAprire$ = "" then wait print ImmagineDaAprire$ ' C:\AutocadSupporto\CalcoloFV\LavoriFV\Ciprandi Maria Luisa\Azimuth\Azimut Luisa.bmp
Pos = instr(ImmagineDaAprire$, "\Azimuth", 1) NomeFile$ = mid$(ImmagineDaAprire$, Pos + 8)
open "C:\AutocadSupporto\CalcoloFV\LavoriFV\" + Committente$ + "\Azimuth\Indice.dat" for output as #im print #im, ImmagineDaAprire$ close #im
Notice "Info" + chr$(13) + "Immagine salvata"
wait
' --------------------------
|
|
|
Post by tsh73 on Sept 18, 2023 15:34:20 GMT -5
Well, good thing is that bmpbutton scales both up and down Bad thing is that size of BMPBUTTON does not change (defined by bitmap passed in creating line) But that probably could be helped by creating empty bitmap of right size before opening form with bmpbutton. so
what exactly you do not like?
|
|
|
Post by tsh73 on Sept 18, 2023 16:20:12 GMT -5
Proof of concept
'tsh73 Sept 2023 'scaling BMP by BMP BUTTON 'this way should work up or down (spritebg works only up) 'view only (no resave)
'select bitmap 'get dimensions 'ask scale (for simplicity, let it be 50 100 150) 'save blank BMP of that size 'open window with BMPBUTTON from this blank 'load target pic, henseforth scaling it
filedialog "Open BMP", "*.bmp", fileName$ print "File selected: >";fileName$;"<" if fileName$="" then print "User cancelled":end
call GetBmpDimensions fileName$, srcWidth, srcHeight print "Source bitmap is ";srcWidth; "x";srcHeight
msg$="please select scale"+chr$(13)+_ "(1-50%, 2-100%, 3-150%)" prompt msg$; resp$ select case resp$ case "1": scale =.5 case "2": scale =1 case "3": scale =1.5 case else: scale =1: print "Wrong scale, set to 100%" end select print "scale selected is ";scale 'Probably should check if it exceeds DisplayWidth, DisplayHeight trgWidth=srcWidth*scale trgHeight=srcHeight*scale print "Target size would be ";trgWidth; "x";trgHeight
open "aux" for graphics_nsb_fs as #aux #aux "getbmp blank 1 1 ";trgWidth;" ";trgHeight call try2kill "blank.bmp" 'because bmpsave does not truncate bif file while overwriting with small one bmpsave "blank", "blank.bmp" close #aux
BMPBUTTON #main.bmpBtn, "blank.bmp", [dummy], UL, 1, 1 ttl$ = srcWidth; "x";srcHeight;" scaled to ";scale*100;"%" UpperLeftX=1 UpperLeftY=1 WindowWidth = trgWidth+10 WindowHeight = trgHeight+40 open ttl$ for window_nf as #main #main "trapclose [quit]"
loadbmp "src", fileName$ #main.bmpBtn "bitmap src" #main.bmpBtn "disable" 'so it DOES NOT gray out, but prevents from clicking
[dummy] wait
[quit] close #main end
'-------------------------------------------------------- sub GetBmpDimensions fileName$, byref width, byref height open fileName$ for input as #gbd temp$ = input$(#gbd, 24) close #gbd width = asc(mid$(temp$, 19, 1))+asc(mid$(temp$, 20, 1))*256 height = asc(mid$(temp$, 23, 1))+asc(mid$(temp$, 24, 1))*256 end sub
function fileExists(path$, filename$) dim info$(10, 10) files path$, filename$, info$() fileExists = val(info$(0, 0)) 'non zero is true end function
'if we'd rather delete file but do not care much if delete fails sub try2kill fileName$ on error goto [skip] 'problem is non[existent file breaks it if fileExists(DefaultDir$, fileName$ ) then kill fileName$ end if [skip] end sub
|
|
|
Post by meerkat on Sept 19, 2023 5:47:27 GMT -5
I know LB does not have direct access to HTML. However one way is to create a html file and place images in a <table> and create a html output file. In this example you can place images in a <table> and tell it to fill each cell by 100%. It will always fill the table even if you streatch and shrink it. Here is an example. Replace C|/data/temp/a2.jpg with your images. They can be any format.
open "c:\a.html" for output as #f print #f, " <HTML><HEAD> <TITLE>image float</TITLE> </HEAD> <BODY> <TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR> <TD WIDTH=33%></TD><TD WIDTH=33%></TD><TD WIDTH=33%></TD></TR> <TR align=bottom> <TD><IMG SRC=file:///C|/data/temp/a2.jpg WIDTH=100% ></TD> <TD><IMG SRC=file:///C|/data/temp/a2.jpg WIDTH=100% ></TD> <TD><IMG SRC=file:///C|/data/temp/a2.jpg WIDTH=100% ></TD> </TR> </TABLE> </BODY> </HTML>" close #f END Click on the a.html file and it should show up in your browser. Try to streatch or shrink it and the image always fille the cell.
|
|
|
Post by angelo2449 on Sept 19, 2023 12:31:24 GMT -5
In my code I plan to use an 'empty' BMP on which to place the 'full' one. The difficulty is to create a 'full' as big as the 'empty'. Thank you.
|
|
|
Post by Rod on Sept 19, 2023 13:18:43 GMT -5
We are still not getting the info we need. Say your bmp you want to display is 100x50 pixels. Say your display space is 50x100 so landscape v portrait. How do you expect a 100x50 bmp be displayed in a 50x100 space?
|
|
|
Post by Walt Decker on Sept 20, 2023 9:58:51 GMT -5
Are you willing to use API? If so you can use User32.dll function LoadImage() followed by User32.dll function SendMessage() with the handle of the loaded bmp.
|
|