[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.drawing

Can't create a metafile from existing image

Garann Means

11/23/2004 4:56:00 PM

Hi,

I'm trying to turn a series of images into metafiles for use as PowerPoint
AutoShapes. I've tried doing this with a simple ASP.NET application that
takes an uploaded image and spits out a .WMF file, but the files it creates
can only be opened by certain image viewers, and not by PowerPoint. Is there
some property I need to set, or something I need to add? My code is below:

Dim fileName As String = getFilename(Request.Files(0).FileName)
Request.Files(0).SaveAs(Server.MapPath(fileName))
Dim img As Image = Image.FromFile(Server.MapPath(fileName))

Dim g As Graphics = Graphics.FromImage(img)
Dim hdc As IntPtr = g.GetHdc()
Dim m As Metafile = New Metafile(Server.MapPath("newFile.wmf"),
hdc, EmfType.EmfOnly)
g.ReleaseHdc(hdc)
g.Dispose()
g = Graphics.FromImage(m)
g.DrawImage(img, 0, 0)
g.Dispose()
m.Dispose()

Thanks for any help,
Garann
4 Answers

Bob Powell

11/23/2004 5:49:00 PM

0

I don't know about the powerpoint aspect of this too well. I suspect that
you could use metafiles that only had simple graphics commands but maybe the
addition of raster images upsets the equation.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Garann Means" <Garann Means@discussions.microsoft.com> wrote in message
news:D89FBE00-9288-4622-BB62-21E1B08F8A17@microsoft.com...
> Hi,
>
> I'm trying to turn a series of images into metafiles for use as PowerPoint
> AutoShapes. I've tried doing this with a simple ASP.NET application that
> takes an uploaded image and spits out a .WMF file, but the files it
creates
> can only be opened by certain image viewers, and not by PowerPoint. Is
there
> some property I need to set, or something I need to add? My code is below:
>
> Dim fileName As String =
getFilename(Request.Files(0).FileName)
> Request.Files(0).SaveAs(Server.MapPath(fileName))
> Dim img As Image = Image.FromFile(Server.MapPath(fileName))
>
> Dim g As Graphics = Graphics.FromImage(img)
> Dim hdc As IntPtr = g.GetHdc()
> Dim m As Metafile = New
Metafile(Server.MapPath("newFile.wmf"),
> hdc, EmfType.EmfOnly)
> g.ReleaseHdc(hdc)
> g.Dispose()
> g = Graphics.FromImage(m)
> g.DrawImage(img, 0, 0)
> g.Dispose()
> m.Dispose()
>
> Thanks for any help,
> Garann


Garann Means

11/23/2004 6:27:00 PM

0

Thanks for the response.

The AutoShapes that come with PowerPoint are much more sophisticated than
what I'm trying to make. But you're right, when I've tried just drawing a
shape onto the new Metafile, it opens correctly. Is there any way to load a
vector image into it programmatically, rather than having to use a JPG?

Thanks,
Garann

"Bob Powell [MVP]" wrote:

> I don't know about the powerpoint aspect of this too well. I suspect that
> you could use metafiles that only had simple graphics commands but maybe the
> addition of raster images upsets the equation.
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tips...
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/f...
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Garann Means" <Garann Means@discussions.microsoft.com> wrote in message
> news:D89FBE00-9288-4622-BB62-21E1B08F8A17@microsoft.com...
> > Hi,
> >
> > I'm trying to turn a series of images into metafiles for use as PowerPoint
> > AutoShapes. I've tried doing this with a simple ASP.NET application that
> > takes an uploaded image and spits out a .WMF file, but the files it
> creates
> > can only be opened by certain image viewers, and not by PowerPoint. Is
> there
> > some property I need to set, or something I need to add? My code is below:
> >
> > Dim fileName As String =
> getFilename(Request.Files(0).FileName)
> > Request.Files(0).SaveAs(Server.MapPath(fileName))
> > Dim img As Image = Image.FromFile(Server.MapPath(fileName))
> >
> > Dim g As Graphics = Graphics.FromImage(img)
> > Dim hdc As IntPtr = g.GetHdc()
> > Dim m As Metafile = New
> Metafile(Server.MapPath("newFile.wmf"),
> > hdc, EmfType.EmfOnly)
> > g.ReleaseHdc(hdc)
> > g.Dispose()
> > g = Graphics.FromImage(m)
> > g.DrawImage(img, 0, 0)
> > g.Dispose()
> > m.Dispose()
> >
> > Thanks for any help,
> > Garann
>
>
>

Bob Powell

11/23/2004 7:52:00 PM

0

I guess the big question is "Whats on the jpeg?"

I suspect that you really need pure vector graphics and analysing say a
line-drawing in a jpeg would be difficult for all cases.

Some sorts of scan-line analysis might work similar to my method for
extracting a rgion from a bitmap but the object would be very chunky when
blown up large.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tips...

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/f...

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Garann Means" <GarannMeans@discussions.microsoft.com> wrote in message
news:01C9A37F-75BD-44DB-BAB0-9E07BA4D64FB@microsoft.com...
> Thanks for the response.
>
> The AutoShapes that come with PowerPoint are much more sophisticated than
> what I'm trying to make. But you're right, when I've tried just drawing a
> shape onto the new Metafile, it opens correctly. Is there any way to load
a
> vector image into it programmatically, rather than having to use a JPG?
>
> Thanks,
> Garann
>
> "Bob Powell [MVP]" wrote:
>
> > I don't know about the powerpoint aspect of this too well. I suspect
that
> > you could use metafiles that only had simple graphics commands but maybe
the
> > addition of raster images upsets the equation.
> >
> > --
> > Bob Powell [MVP]
> > Visual C#, System.Drawing
> >
> > Find great Windows Forms articles in Windows Forms Tips and Tricks
> > http://www.bobpowell.net/tips...
> >
> > Answer those GDI+ questions with the GDI+ FAQ
> > http://www.bobpowell.net/f...
> >
> > All new articles provide code in C# and VB.NET.
> > Subscribe to the RSS feeds provided and never miss a new article.
> >
> >
> >
> >
> >
> > "Garann Means" <Garann Means@discussions.microsoft.com> wrote in message
> > news:D89FBE00-9288-4622-BB62-21E1B08F8A17@microsoft.com...
> > > Hi,
> > >
> > > I'm trying to turn a series of images into metafiles for use as
PowerPoint
> > > AutoShapes. I've tried doing this with a simple ASP.NET application
that
> > > takes an uploaded image and spits out a .WMF file, but the files it
> > creates
> > > can only be opened by certain image viewers, and not by PowerPoint. Is
> > there
> > > some property I need to set, or something I need to add? My code is
below:
> > >
> > > Dim fileName As String =
> > getFilename(Request.Files(0).FileName)
> > > Request.Files(0).SaveAs(Server.MapPath(fileName))
> > > Dim img As Image =
Image.FromFile(Server.MapPath(fileName))
> > >
> > > Dim g As Graphics = Graphics.FromImage(img)
> > > Dim hdc As IntPtr = g.GetHdc()
> > > Dim m As Metafile = New
> > Metafile(Server.MapPath("newFile.wmf"),
> > > hdc, EmfType.EmfOnly)
> > > g.ReleaseHdc(hdc)
> > > g.Dispose()
> > > g = Graphics.FromImage(m)
> > > g.DrawImage(img, 0, 0)
> > > g.Dispose()
> > > m.Dispose()
> > >
> > > Thanks for any help,
> > > Garann
> >
> >
> >


(Max Christian)

11/24/2004 6:23:00 PM

0

Garann Means wrote:

> I'm trying to turn a series of images into metafiles for use as PowerPoint
> AutoShapes. I've tried doing this with a simple ASP.NET application that
> takes an uploaded image and spits out a .WMF file, but the files it creates
> can only be opened by certain image viewers, and not by PowerPoint. Is there
> some property I need to set, or something I need to add? My code is below:


I'm no expert on this but have also been playing around with ASP.NET and
metafiles this week. I'm surprised to see you're using the .WMF
extension, as it's my understanding that .NET cannot generate .WMF's,
only .EMF (Enhancled Metafiles containing EMF or EMF+ records, or both).

Might be worth trying to using a .EMF extension and see if that helps
more image viewers open your files. I found that using the
EmfType.EmfOnly option in the constructor was also helpful.
(Alternatively if there is a way of generating real .WMF's in .NET
please do let me know how.)

Max Christian