Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #1664 > unrolled thread
| Started by | "Fred Killet" <killet-nospam@killetsoft.de> |
|---|---|
| First post | 2011-07-13 09:33 +0200 |
| Last post | 2011-08-05 09:45 +0200 |
| Articles | 9 — 5 participants |
Back to article view | Back to comp.lang.clipper.visual-objects
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
| From | "Fred Killet" <killet-nospam@killetsoft.de> |
|---|---|
| Date | 2011-07-13 09:33 +0200 |
| Subject | Bitmap or DC to JPG or GIF |
| Message-ID | <4e1d4a43$0$7628$9b4e6d93@newsspool1.arcor-online.net> |
Hello, I need a piece of source to create a GIF and/or JPG file from a memory bitmap or from a DC. The source should refer to API functions. I can not use FabPaint and FabTools, because the conversion must be implemented into a separate DLL. Thanks for your suggestions and help! Fred Killet killet-nospam@killetsoft.de
[toc] | [next] | [standalone]
| From | "richard.townsendrose" <richard.townsendrose@gmail.com> |
|---|---|
| Date | 2011-07-13 01:48 -0700 |
| Message-ID | <a1800e72-f546-4e5c-8527-51d56d329420@u26g2000vby.googlegroups.com> |
| In reply to | #1664 |
Fred I think you will have to take fabpaint or even CA-Paint to pieces and see whats what. Richard
[toc] | [prev] | [next] | [standalone]
| From | "Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it> |
|---|---|
| Date | 2011-07-14 11:19 +0200 |
| Message-ID | <ivmcbo$edt$1@dont-email.me> |
| In reply to | #1664 |
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
[toc] | [prev] | [next] | [standalone]
| From | "Willie Moore" <williem@wmconsulting.com> |
|---|---|
| Date | 2011-07-14 07:38 -0500 |
| Message-ID | <ivmnvi$q8s$1@speranza.aioe.org> |
| In reply to | #1672 |
Arne,
Thanks for sharing.
Regards,
Willie
"Arne Ortlinghaus" wrote in message news:ivmcbo$edt$1@dont-email.me...
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
[toc] | [prev] | [next] | [standalone]
| From | "Fred Killet" <killet-nospam@killetsoft.de> |
|---|---|
| Date | 2011-07-18 10:34 +0200 |
| Message-ID | <4e23f029$0$6635$9b4e6d93@newsspool2.arcor-online.net> |
| In reply to | #1673 |
Hi Arne, thank you for the code. But what I need is to save a memory bitmap to a .gif file or/and to a .jpg file. Any ideas? Fred
[toc] | [prev] | [next] | [standalone]
| From | "Arne Ortlinghaus" <Arne.Ortlinghaus@acs.it> |
|---|---|
| Date | 2011-07-27 18:46 +0200 |
| Message-ID | <j0pfc9$sjt$1@dont-email.me> |
| In reply to | #1693 |
Hi Fred,
saving to Gif should also work using GetEncoderInfo("image/gif") instead of
GetEncoderInfo("image/jpeg").
It is at least a valuable idea using the Dotnet possibilities as it is
oriented to the future. Impressing who few code is needed.
Since the Dotnet classes seems to use GDI+ there should be also dlls that
access to the GDI+. Unfortunately the original GDI+ from Microsoft should be
written in C++ classes so that a direct access from VO should not work.
Arne Ortlinghaus
"Fred Killet" <killet-nospam@killetsoft.de> schrieb im Newsbeitrag
news:4e23f029$0$6635$9b4e6d93@newsspool2.arcor-online.net...
> Hi Arne,
>
> thank you for the code. But what I need is to save a memory bitmap to a
> .gif file or/and to a .jpg file.
>
> Any ideas?
>
> Fred
>
[toc] | [prev] | [next] | [standalone]
| From | Gustavo Biasone <rosario.soft@gmail.com> |
|---|---|
| Date | 2011-07-19 21:23 -0700 |
| Message-ID | <ce1df3e5-22e0-4725-86f1-595ef147cd8a@s2g2000vbw.googlegroups.com> |
| In reply to | #1664 |
Hi Fred, You can use OLE* functions to create a Picture object. With this object you can render to a DC or create a HBitmap if you want to use BitBlt, for instance. Thats what I do to show images from files or from resources using only API calls. Not tested, but I think you can save a Picture object to a gif, jpj, bmp or png by using OleSavePictureFile function. HTH Gustavo Biasone On 13 jul, 04:33, "Fred Killet" <killet-nos...@killetsoft.de> wrote: > Hello, > > I need a piece of source to create a GIF and/or JPG file from a memory > bitmap or from a DC. The source should refer to API functions. I can not use > FabPaint and FabTools, because the conversion must be implemented into a > separate DLL. > > Thanks for your suggestions and help! > > Fred Killet > killet-nos...@killetsoft.de
[toc] | [prev] | [next] | [standalone]
| From | "Fred Killet" <killet-nospam@killetsoft.de> |
|---|---|
| Date | 2011-07-20 12:11 +0200 |
| Message-ID | <4e26a9ee$0$6571$9b4e6d93@newsspool3.arcor-online.net> |
| In reply to | #1709 |
Hi, Gustavo yes I think OleSavePictureFile is the best way to save JPGs and GIFs to files. Now I need some code. Can somebody help me? Fred killet-nospam@killetsoft.de "Gustavo Biasone" <rosario.soft@gmail.com> schrieb im Newsbeitrag news:ce1df3e5-22e0-4725-86f1-595ef147cd8a@s2g2000vbw.googlegroups.com... > Hi Fred, > > You can use OLE* functions to create a Picture object. With this > object you can render to a DC or create a HBitmap if you want to use > BitBlt, for instance. > Thats what I do to show images from files or from resources using only > API calls. > > Not tested, but I think you can save a Picture object to a gif, jpj, > bmp or png by using OleSavePictureFile function. > > HTH > > Gustavo Biasone > > > On 13 jul, 04:33, "Fred Killet" <killet-nos...@killetsoft.de> wrote: >> Hello, >> >> I need a piece of source to create a GIF and/or JPG file from a memory >> bitmap or from a DC. The source should refer to API functions. I can not >> use >> FabPaint and FabTools, because the conversion must be implemented into a >> separate DLL. >> >> Thanks for your suggestions and help! >> >> Fred Killet >> killet-nos...@killetsoft.de >
[toc] | [prev] | [next] | [standalone]
| From | "Fred Killet" <killet-nospam@killetsoft.de> |
|---|---|
| Date | 2011-08-05 09:45 +0200 |
| Message-ID | <4e3b9f98$0$6543$9b4e6d93@newsspool4.arcor-online.net> |
| In reply to | #1664 |
Hello, Thanks for your help and for suggestions. I have it realized now. I read the bitmap and the palette from the device and then I compress the data with the LZW algorithm and at least I write it to a file in GIF format. The function is included in Graphics4VO now. Graphics4VO now can write graphical content to BMP, EMF and GIF files. Fred
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.clipper.visual-objects
csiph-web