Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #1672

Re: Bitmap or DC to JPG or GIF

From "Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it>
Newsgroups comp.lang.clipper.visual-objects
Subject Re: Bitmap or DC to JPG or GIF
Date 2011-07-14 11:19 +0200
Organization A noiseless patient Spider
Message-ID <ivmcbo$edt$1@dont-email.me> (permalink)
References <4e1d4a43$0$7628$9b4e6d93@newsspool1.arcor-online.net>

Show all headers | View raw


Hi Fred,

I have nearly the same task: Conversion from BMP/JPGs to JPG with reduction 
of the resolution and the file size.
I have written a program with Vulcan that I call from my VO program with 
parameters and an additional control file. It seems to work good.

Arne Ortlinghaus
ACS Data Systems



o := createinstance(#clsImageConverter)
o:lNoerrormessage := true
cdir := "C:\daten\"
cfile := "ACS_Hintergrund_800.bmp"
//cfile := "clowns.gif"
o:load(cdir +cfile)
nw := o:width
nh := o:height
nmax := 500 // Maximal erlaubte Breite/Höhe
if nw > nmax .or. nh > nmax
   if nw > nh
      nf :=(1.0 *nmax) /(1.0 *nw)
   else
      nf :=(1.0 *nmax) /(1.0 *nh)
   endif
   nw := nf *nw
   nh := nf *nw
   o:resize(nw, nh)
endif
cfile := "output.jpg"
// Save as JPG, max. 50000Byte
o:SaveJPGMaxfilesize(cdir +cfile, 50000)
if o:lerror
    msginfo(o:cerror)
endif





#using System.Drawing
#using System.Drawing.Imaging


   CLASS clsImageConverter
protect _obmp as bitmap
protect _lerror as logic
protect _lNoerrormessage as logic
protect _cerror as string
      CONSTRUCTOR()
         RETURN
      METHOD ReSetError() as void
_lerror := false
return

access cerror as string
return _cerror

access lerror as logic
return _lerror

assign lNoerrormessage (l) as void
_lNoerrormessage := l

METHOD SetError(cerror) as void
if !_lerror
   _lerror := true
   _cerror := cerror
   if !_lNoerrormessage
      Msgerror (cerror)
   endif
endif
return

      METHOD Load(csource as string) AS logic
Try
   _obmp := bitmap{csource}
   Catch oError  as Exception
   self:setError ("Error load picture"  + CRLF + csource + CRLF +
ErrorObject2String(oError))
END TRY
         RETURN !_lerror

access Width AS int
local n as int
n := -1
if _obmp <> Null_Object .and. !_lerror
   n := _obmp:Width
endif
return n

access obmp as bitmap
return _obmp

access height AS int
local n as int
n := -1
if _obmp <> Null_Object .and. !_lerror
   n := _obmp:height
endif
return n

METHOD GetEncoderInfo(mimeType as string) as ImageCodecInfo
local j as int
local encoders as system.array
local o as ImageCodecInfo
encoders := ImageCodecInfo.GetImageEncoders()
for j := 0 upto encoders:Length-1
   o := (ImageCodecInfo)encoders:getvalue(j)
   if o:MimeType == mimeType
      return o
   endif
next

return null_object





method GetRectangle  (nwidth as int, nheight as int) as rectangle
local rect as rectangle
rect := Rectangle{0, 0, nWidth, nHeight}
return rect

METHOD Resize(nwidth as int, nheight as int) AS logic
local grphDestination as Graphics
local obmpDest as bitmap
local rectSource, rectDest as rectangle
Try
   obmpDest := Bitmap{nwidth, nheight}
   grphDestination := Graphics.FromImage(obmpDest)
   rectSource := self:GetRectangle(self:Width, self:height)
   rectdest := self:GetRectangle(nWidth, nheight)
   grphDestination:DrawImage(_obmp, rectdest, rectSource,
GraphicsUnit.Pixel)
_obmp := obmpdest
Catch oError  as Exception
   self:setError ("Error resize picture"  + CRLF +
ErrorObject2String(oError))
END TRY
RETURN !_lerror

METHOD SaveJPG(cdest as string, m_Quality as int) AS logic
local myImageCodecInfo as ImageCodecInfo
local myEncoder as Encoder
local myEncoderParameter as EncoderParameter
local myEncoderParameters as EncoderParameters

Try

myImageCodecInfo := GetEncoderInfo("image/jpeg")

myEncoder := Encoder.Quality;

myEncoderParameters := EncoderParameters{1};

// Save the bitmap file with quality level 25.
myEncoderParameter := EncoderParameter {myEncoder, m_Quality}
myEncoderParameters:Param[1] := myEncoderParameter
_obmp:Save(cdest, myImageCodecInfo, myEncoderParameters)

Catch oError  as Exception
   self:setError ("Error save picture"  + CRLF + ErrorObject2String(oError))
END TRY

return !_lerror

METHOD SaveJPGMaxfilesize(cdest as string, nfilesizebyte as int) AS logic
local lgoon as logic
lgoon := true
local nsize, m_Quality as int
m_quality := 100
do while lgoon .and. !_lerror
   lgoon := false
   SaveJPG(cdest, m_Quality)
   nsize := fgetfileinfo (cdest, #filesize)
   if nsize > nfilesizebyte .and. m_quality > 15
      m_quality -= 10
      lgoon := true
   endif
enddo
return !_lerror

   END CLASS


Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Bitmap or DC to JPG or GIF "Fred Killet" <killet-nospam@killetsoft.de> - 2011-07-13 09:33 +0200
  Re: Bitmap or DC to JPG or GIF "richard.townsendrose" <richard.townsendrose@gmail.com> - 2011-07-13 01:48 -0700
  Re: Bitmap or DC to JPG or GIF "Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it> - 2011-07-14 11:19 +0200
    Re: Bitmap or DC to JPG or GIF "Willie Moore" <williem@wmconsulting.com> - 2011-07-14 07:38 -0500
      Re: Bitmap or DC to JPG or GIF "Fred Killet" <killet-nospam@killetsoft.de> - 2011-07-18 10:34 +0200
        Re: Bitmap or DC to JPG or GIF "Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it> - 2011-07-27 18:46 +0200
  Re: Bitmap or DC to JPG or GIF Gustavo Biasone <rosario.soft@gmail.com> - 2011-07-19 21:23 -0700
    Re: Bitmap or DC to JPG or GIF "Fred Killet" <killet-nospam@killetsoft.de> - 2011-07-20 12:11 +0200
  Re: Bitmap or DC to JPG or GIF "Fred Killet" <killet-nospam@killetsoft.de> - 2011-08-05 09:45 +0200

csiph-web