March 29, 2024, 07:23:59 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


JPG file specs

Started by billhsln, February 20, 2007, 11:27:40 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

billhsln

I know there is a command to get the height and width of a BMP (GETBITMAPSIZE).  Is there an equivalent for JPG and other format graphic files?

Thanks,
Bill
When all else fails, get a bigger hammer.

LarryMc

I use a 3rd party dll that allows me load various types of images as bitmaps.  It also allows me to scale the images, and adjust contrast/brightness and other various functions
You can find the dll and the source for a program that I use it in at the following location.

http://www.codingmonkeys.com/index.php?action=tpmod;dl=item31


LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

February 20, 2007, 02:17:07 PM #2 Last Edit: February 20, 2007, 02:19:10 PM by billhsln
The program will load the file, what I want to do is display it's height and width.

I started with IMGVIEW.EBA and modified it to display 2 graphic files side by side with the dimensions on top.  However GETBITMAPSIZE only seems to work for BMP's and I am using JPG's.  JPG's return 0x0 from GETBITMAPSIZE.   So, what I am looking for is a subroutine to get a JPG's dimensions.

Bill

Here is my code.

REM image viewer v1.1 Requires EBASIC Version 1.0 or greater
REM Shows usage of a @NOAUTODRAW window and manipulation of loaded images
REM Compile as a WINDOWS target

def w1:window
def bitmap1,bitmap2:uint
def bmw1,bmh1,bmw2,bmh2:uint
def x,y,w,h,mw,mh,scale:int
def filename,filter:string

getscreensize(w,h)
w-=40
h-=40

OPENWINDOW w1,0,0,w,h,@MINBOX|@MAXBOX|@SIZE|@NOAUTODRAW,0,"Image viewer",&mainwindow
BEGINMENU w1
MENUTITLE "&File"
MENUITEM "&Load Image 1",0,1
MENUITEM "Load &Image 2",0,2
MENUITEM "&Quit",0,3
MENUTITLE "Options"
MENUITEM "Scale To Window",0,4
ENDMENU

x=0
y=0
scale = 1
run = 1

waituntil run = 0

DeleteImage bitmap1,@IMGSCALABLE
DeleteImage bitmap2,@IMGSCALABLE

closewindow w1
end

SUB mainwindow
select @CLASS
case @IDMENUPICK
select @MENUNUM
case 1
filter = "Image files (*.bmp *.jpg *.gif)|*.bmp;*.jpg;*.gif|All Files (*.*)|*.*||"
filename = filerequest("Load Bitmap",w1,1,filter,"bmp")
if (len(filename) > 0)
    if (bitmap1)
DeleteImage bitmap1,@IMGSCALABLE
RECT w1,x,y,w,h,RGB(255,255,255),RGB(255,255,255)
endif
bitmap1 = LoadImage(filename,@IMGSCALABLE)
getbitmapsize(bitmap1,bmw1,bmh1)
UpdateImage()
move w1,0,0
print w1, str$(bmw1) + "x" + str$(bmh1)
endif
case 2
filter = "Image files (*.bmp *.jpg *.gif)|*.bmp;*.jpg;*.gif|All Files (*.*)|*.*||"
filename = filerequest("Load Bitmap",w1,1,filter,"bmp")
if (len(filename) > 0)
    if (bitmap2)
DeleteImage bitmap2,@IMGSCALABLE
RECT w1,x,y,w,h,RGB(255,255,255),RGB(255,255,255)
endif
bitmap2 = LoadImage(filename,@IMGSCALABLE)
getbitmapsize(bitmap2,bmw2,bmh2)
UpdateImage()
move w1,mw,0
print w1, str$(bmw2) + "x" + str$(bmh2)
endif
case 3
run = 0
case 4
IF scale THEN scale = 0 ELSE scale = 1
RECT w1,x,y,w,h,RGB(255,255,255),RGB(255,255,255)
UpdateImage()
endselect
case @IDMENUINIT
CheckMenuItem w1,4,(scale = 1)
case @IDCLOSEWINDOW
run=0
case @IDSIZE
GetClientSize w1,x,y,w,h
mw = (w - x)/2
mh = (h - y)/2
if (scale)
UpdateImage()
endif
case @IDPAINT
UpdateImage()
case @IDCREATE
CenterWindow w1
endselect
return
ENDSUB

SUB UpdateImage
if (bitmap1)
if (scale)
ShowImage w1,bitmap1,@IMGSCALABLE,x,y+20,mw-5,h-20
else
ShowImage w1,bitmap1,@IMGSCALABLE,x,y+20
endif
endif
if (bitmap2)
if (scale)
ShowImage w1,bitmap2,@IMGSCALABLE,mw+5,y+20,mw-5,h-20
else
ShowImage w1,bitmap2,@IMGSCALABLE,mw+5,y+20
endif
endif
RETURN
ENDSUB
When all else fails, get a bigger hammer.

Ionic Wind Support Team

You need to use an image library, or some other method.  GETBITMAPSIZE does just what the name indicates.  Returns the size of a bitmap format image. 

There used to be some code on the old IBasic forums, written by Trondoc (god rest his soul), that would extract the sizes from a jpg file itself.

Paul.
Ionic Wind Support Team

LarryMc

Quote from: Paul Turley on February 20, 2007, 02:38:20 PM
There used to be some code on the old IBasic forums, written by Trondoc (god rest his soul), that would extract the sizes from a jpg file itself.

Paul.

Here's the link to the code Paul is talking about.http://www.web-helper.net/PyxiaSAQ/ViewArticle.asp?1
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

Thanks Larry and Paul.  That was exactly what I was looking for.

Bill
When all else fails, get a bigger hammer.

Ionic Wind Support Team

It's in IBasic Standard code so will probably need some tweaking to make run in Emergence.
Ionic Wind Support Team

billhsln

Compiled clean in EBasic.  Will be using it as a subroutine, so might not be too much of a problem.

Thanks again,
Bill
When all else fails, get a bigger hammer.

barry

I had similar questions some time back in IBasic and someone posted the following code, which I used.  It worked just fine.  It compiled in a version of EBasic when I first got it and probably still will.

Barry


'GetPicSize

GLOBAL GetPicSize
SUB GetPicSize(filename:STRING, w:INT byref, h:INT byref),INT
string tmpstring

tmpstring = ucase$(right$(filename,3))
if tmpstring = "BMP"
GetBmpSize(filename, w, h)
else
if tmpstring = "JPG"
GetJpegSize(filename, w, h)
else
GetGifSize(filename, w, h)
endif
endif
return 0
EndSub

'GetJpegSize.inc

Sub GetJpegSize(FileName:string, W:int byref, H:int byref),int
BFILE F
ISTRING tmp[256]
INT a, b
IF OpenFile(F, FileName, "r") Then Return 0
__read F, tmp, 256
CloseFile F
b=0
For a = 0 to 255
IF tmp[a] = 255
b++
IF (b = 5) and (a<252)
a += 5
H = tmp[a] * 256 + tmp[a+1] :' reversed order
W = tmp[a+2] * 256 + tmp[a+3]
Return ( (W*H) <> 0)
Endif
Endif
Next a
Return 0
EndSub

' GetGifSize

Sub GetGifSize(FileName:string, W:word byref, H:word byref),int
  BFILE F
  if openfile(F, FileName, "r") then return 0
  read F, W
  read F, W
  read F, W
  read F, W
  read F, H
  closefile F
  return 0
endsub

'GetBmpSize
Sub GetBmpSize(FileName:string, W:int byref, H:int byref),int
int bitmap

bitmap = LoadImage(FileName,@IMGBITMAP)
GetBitmapSize(bitmap, W, H)
DeleteImage bitmap,@IMGBITMAP
Return 0
EndSub


billhsln

Thanks Barry.  Some of my graphics files were not coming up with numbers.  So maybe this code will fix it.

Thanks again,
Bill
When all else fails, get a bigger hammer.