dkl
Full Member
Posts: 234
|
Post by dkl on Jun 9, 2021 20:25:10 GMT -5
When displaying a bmp in a graphicbox is there a command to resize the BMP to fit the box? I am presuming that the graphicbox has to be set at a size to fit the BMP. Am I correct?
I see that there is a 'print #handle "autosize"' command as well as 'print #handle, "getbmp bmpName x y width height"', but I'm not sure how to use these or if they will do the job. I have tried, but with little success!
|
|
|
Post by honkytonk on Jun 10, 2021 1:30:52 GMT -5
To set window at bmp:
NOMAINWIN Filedialog "Open Bitmap","*.bmp", picFile$ if picFile$="" then wait Open picFile$ for Input as #pic pic$=Input$(#pic, LOF(#pic)) Close #pic picWidth = Asc(Mid$(pic$, 19, 1)) + (Asc(Mid$(pic$, 20, 1)) * 256) picHeight = Asc(Mid$(pic$, 23, 1)) + (Asc(Mid$(pic$, 24, 1)) * 256) if picWidth+220 > DisplayWidth-10 then notice,"L'image est trop large pour l'écran": wait if Height+50 > DisplayHeight-20 then notice,"L'image est trop haute pour l'écran": wait if picWidth <100 then notice,"Limite inférieure 100 x 100pxl": wait if picHeight <100 then notice,"Limite inférieure 100 x 100pxl": wait '------------------- mapWidth=picWidth: mapHeight=picHeight+65 WindowWidth = mapWidth+15: WindowHeight = mapHeight UpperLeftX = 10: UpperLeftY = 20 GRAPHICBOX #w.m 5, 5, WindowWidth-15, WindowHeight-60 '.........
|
|
|
Post by tsh73 on Jun 10, 2021 3:02:00 GMT -5
No, there is no native command
You don't have to. There is a couple of workarounds and universal API solution.
Workaround #one if you designate your bitmap to be sprite background, it will scale to fill whole graphicbox But it only scales UP (and if your bitmap is narrow strip it will scale up only on one dimension) and you can have only ONE sprite graphicbox in LB program.
nomainwin
open "click me" for graphics_nsb_nf as #main #main "trapclose [quit]" #main "down" #main "when leftButtonUp [Clk]"
wait
[quit] close #main end
[Clk] FILEDIALOG "Open a bitmap","BMP\*.BMP", file$ if file$="" then wait loadbmp "pic", file$ #main "background pic" 'scales up or down to initial button size #main "drawsprites" wait
Workaround #two There is a way to load bmp to bmpbutton. It will scale up or down to initial button size (which is defined by picture you load in BMPBUTTON first) You can "disable" bmpbutton so it does not flash then clicked.
nomainwin
file1$="BMP\BLANK.BMP" 'initial button. Other pictures will be scaled to it bmpbutton #main.bmpBtn, file1$, [Clk], UL, 10, 10 open "test" for window as #main #main "trapclose [quit]"
wait
[quit] close #main end
[Clk] FILEDIALOG "Open a bitmap","BMP\*.BMP", file$ if file$="" then wait loadbmp "pic", file$ #main.bmpBtn "bitmap pic" 'scales up or down to initial button size wait
Probably someone will provide API solution or a link.
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on Jun 10, 2021 7:14:21 GMT -5
Thank you, Honky for your code and showing me how to determine pic size and also to tsh73 for those 2 workarounds. I had never thought of using a bmpbutton to do that. Your time and help was much appreciated Gentlemen
|
|
|
Post by mknarr on Jun 10, 2021 8:42:21 GMT -5
I have a different method. I have pictures of many different sizes. The graphic box has to be as large as the largest picture you are going to display. I clear it and fill it with buttonface then it doesn't appear. Then when you place the picture in it, it looks like the picture has filled the graphicbox. I put the names of all the pictures in an array I define the graphic box,
graphicbox #breedlist.grb1,325,250,190,210 Stylebits #breedlist.grb1,0, _WS_BORDER,0,0
Then when I want to display a picture I call this subroutine and I hope it makes some sense.
if LastPicture>0 then call PlacePicture breed$, LastPicture
sub PlacePicture brdname$, lastpic 'Place breed pictures. #breedlist.grb1, "cls; fill buttonface" for x=1 to lastpic a$=upper$(upto$(ListBox$(x),".")) if upper$(brdname$)=a$ then exit for next if x>lastpic then 'No picture found. loadbmp "picture", DefaultDir$+"\bmp\"+"No Picture.bmp" else 'Picture found. loadbmp "picture", DefaultDir$+"\"+FOLDER$+" Pictures\"+brdname$+".bmp" end if #breedlist.grb1, "drawbmp picture 0, 0; flush" unloadbmp "picture" end sub
|
|
|
Post by Rod on Jun 10, 2021 9:33:19 GMT -5
|
|
dkl
Full Member
Posts: 234
|
Post by dkl on Jun 16, 2021 1:17:18 GMT -5
Thank you for everyone’s help. I went for Rod’s suggestion this time. It worked nicely 👍🏻
|
|