honky
Junior Member
Posts: 62
|
Post by honky on Dec 9, 2022 4:35:29 GMT -5
Hello, With gdi32.dll we can transform a: ".jpg" into: ".bmp"? good. When I pass the mouse over a: ".jpg", Windows shows me its dimensions. Does anyone know how to extract the dimensions of a: ".jpg" with gdi32.dll or other dll?
Another question: If I put the: "gdi32.dll" in the ".bas" folder. Will the "call" take the dll from the folder or will it take the one from: "system32" Thank you for.
|
|
|
Post by Walt Decker on Dec 9, 2022 7:17:15 GMT -5
gdi32.dll will NOT translate a jpg to a bmp. For that you need gdiplus.
Do not move windows dlls to different directories. You will confuse the search engine.
|
|
honky
Junior Member
Posts: 62
|
Post by honky on Dec 9, 2022 7:27:07 GMT -5
Is it possible to have the dimensions of a: ".jpg" with: "gdiplus" And if yes, how ? I conclude that it is useless to put the ".dll" in the ".bas" folder It's not a deplacment it's a copy
|
|
|
Post by Walt Decker on Dec 9, 2022 7:41:34 GMT -5
Yes, but for what purpose? Windows does not work with image formats other than BMP so you might as well translate the other format to bmp and get the size from that, then you can work with the result.
|
|
|
Post by tsh73 on Dec 9, 2022 8:00:46 GMT -5
There probably an API way of getting JPG dimensions but I found non-API way on stackOverflow and translated it to native LB. Here it is (put in DATA section some real Jpegs, I just saved some from Paint):
1000x10.jpg 1000 x 10 pixels 10x1000.jpg 10 x 1000 pixels 10x20.bmp Likely not a Jpeg file! 10x20.jpg 10 x 20 pixels 40000x10.jpg 40000 x 10 pixels photo355x474.jpg 355 x 474 pixels photo355x474bw.jpg 355 x 474 pixels, greyscale
'reading jpeg size from jpeg file, without library 'translation of C code from ' https://stackoverflow.com/questions/2517854/getting-image-size-of-jpeg-from-its-binary
data "1000x10.jpg" data "10x1000.jpg" data "10x20.bmp" data "10x20.jpg" data "40000x10.jpg" data "photo355x474.jpg" data "photo355x474bw.jpg" data "XYZZY"
read fileName$ do print fileName$, res$=getJpegProps$(fileName$) 'print res$ if word$(res$, 4)="0" then print "Likely not a Jpeg file!" else print word$(res$, 1) ;" x "; word$(res$, 2) ; " pixels"; if word$(res$, 4) ="1" then print ", grayscale"; print 'finally break that line end if read fileName$ loop until fileName$="XYZZY"
'---------------------------------------------------- function getJpegProps$(fileName$) ' ret$= w;" "; h;" "; bpc;" ";cps ' so word$(getJpegProps$(fileName$),1) , width in pixels, (,2) height, (,3) is bits per channel, ' (,4) is color components (3 is color, 1 is grayscale)
open fileName$ for binary as #1 dataLength = lof(#1) data$=input$(#1, dataLength) close #1 getJpegProps$ ="0 0 0 0" if mid$(data$,7,4)<>"JFIF" then exit function 'likely not a Jpeg file!
off = 1 'BASIC numbers characters from 1 'some constants Oxff=hexdec("ff") Oxd0=hexdec("d0") Oxd7=hexdec("d7") Oxd8=hexdec("d8") Oxd9=hexdec("d9") Ox01=hexdec("01") Oxc0=hexdec("c0")
while (off<=dataLength) while(asc(mid$(data$,off,1))=Oxff) off=off+1 wend mrkr = asc(mid$(data$,off,1)):off=off+1 if(mrkr=Oxd8) then [continue] '// SOI if(mrkr=Oxd9) then exit while '// EOI if(Oxd0<=mrkr AND mrkr<=Oxd7) then [continue] if(mrkr=Ox01) then [continue] '// TEM secLen = asc(mid$(data$,off,1))*256 + asc(mid$(data$,off+1,1)) off=off+2 if(mrkr=Oxc0) then bpc = asc(mid$(data$,off,1)) '// precission (bits per channel) h = asc(mid$(data$,off+1,1))*256 + asc(mid$(data$,off+2,1)) w = asc(mid$(data$,off+3,1))*256 + asc(mid$(data$,off+4,1)) cps = asc(mid$(data$,off+5,1)) '// number of color components 'ret$=bpc;" "; h;" "; w;" "; cps ret$= w;" "; h;" "; bpc;" ";cps 'print ret$ getJpegProps$ = ret$ 'end exit function end if off=off+secLen-2 [continue] wend
end function
'sorce C code ' https://stackoverflow.com/questions/2517854/getting-image-size-of-jpeg-from-its-binary
' function jpegProps(data$) { // data$ is an array of bytes ' var off = 0; ' while(off<data$.length) { ' while(data$[off]==0xff) off++; ' var mrkr = data$[off]; off++; ' if(mrkr==0xd8) continue; // SOI ' if(mrkr==0xd9) break; // EOI ' if(0xd0<=mrkr && mrkr<=0xd7) continue; ' if(mrkr==0x01) continue; // TEM ' var len = (data$[off]<<8) | data$[off+1]; off+=2; ' if(mrkr==0xc0) return { ' bpc : data$[off], // precission (bits per channel) ' h : (data$[off+1]<<8) | data$[off+2], ' w : (data$[off+3]<<8) | data$[off+4], ' cps : data$[off+5] // number of color components ' } ' off+=len-2; ' } ' }
|
|
honky
Junior Member
Posts: 62
|
Post by honky on Dec 9, 2022 8:54:04 GMT -5
Oh yess it'work !
|
|
|
Post by Rod on Dec 9, 2022 11:19:11 GMT -5
|
|
honky
Junior Member
Posts: 62
|
Post by honky on Dec 10, 2022 3:21:56 GMT -5
@ tsh73: Thank you for your code @ Rod: Thank you for the link I have everything I need to transform from: ".jpg" to: ".bmp", on the fly. This will make to considerably lighten the image files. And opens up great prospects for games.
|
|
|
Post by Rod on Dec 10, 2022 6:32:29 GMT -5
Unfortunately .jpg are pretty useless for games. Especially if you have to mask an image. The .jpg never leaves your graphics alone it always reduces color or recolors pixels to help reduce storage. You will find that for sprites and for transparent blitting that there is nothing better than pixel perfect .bmps that hold their color. Transparency and sprite masking relies on perfect black or masking color placement. The LBPE has a short tutorial on blitting, alycesrestaurant.com/lbpe/Fun%20with%20the%20blitter.htmlYou will need this .bmp gamebin.webs.com/Ocean.bmp
|
|
honky
Junior Member
Posts: 62
|
Post by honky on Dec 10, 2022 9:22:32 GMT -5
I did a test with a ".jpg" transformed into: ".bmp", and from: ".bmp" I made a sprite. And it works great for all sizes. The goal is to be able to integrate a lot of images or large images in a game, without the whole thing weighing megatons.
|
|