Saturday, March 31, 2012
System.Drawing: Error when using a .bmp or .gif file but not when .jpg
whenever I use a .jpg file it works perfect.
Why is that? and how to fix it?
I almost have no knowledge about the system.drawing and so I am in the dark
about this.
This is my code
--
<%@dotnet.itags.org. Page Language="vb" %>
<%@dotnet.itags.org. import namespace="system.drawing" %>
<%@dotnet.itags.org. import namespace="system.drawing.imaging" %>
<%@dotnet.itags.org. import namespace="system.drawing.drawing2d" %>
<%
' initialise objects
dim strFilename as string
dim b as New System.Drawing.Bitmap(server.mappath("test.jpg"))
dim g as graphics = graphics.fromimage(b)
g.smoothingMode = smoothingMode.antiAlias
dim stringFormat As New StringFormat()
g.drawString("The Magic Word", New font("arial",3),systembrushes.windowtext,
New pointF(2,2), stringFormat)
' Set the content type
response.contenttype="image/jpeg"
' send the image to the viewer
b.save(response.outputstream, b.rawformat)
' tidy up
b.dispose()
%>Hi Richard,
As for the "A Graphics object cannot be created from an image that has an
indexed pixel format" error, it is caused by the Graphic object can't been
created from some certain image format which contains indexed pixel. I've
done some tests and one means is load the image and convert it into jpeg
format first and then create Graphich object to manipulate it. For example,
here is my test code:
========================================
==========
Private Sub Output_Image(ByVal path As String)
Try
Dim img As Image = Image.FromFile(path)
Dim stream As New System.IO.MemoryStream
img.Save(stream, ImageFormat.Jpeg)
Dim imgNew As Image = Image.FromStream(stream)
Dim g As Graphics = Graphics.FromImage(imgNew)
g.DrawString("MS Test", New Font("Verdana", 20,
FontStyle.Bold), _
New SolidBrush(Color.Beige), 0, 0)
Response.Clear()
Response.ContentType = "Image/jpeg"
imgNew.Save(Response.OutputStream, ImageFormat.Jpeg)
Response.End()
img.Dispose()
stream.Close()
imgNew.Dispose()
Catch ex As Exception
Response.Write("<br>" + ex.Message)
End Try
End Sub
========================================
=========
Please have a try to see whether it works for you. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
thx a lot, this really helped me out.
I got no errors and with some thinking I made sure ppl can't link to my
files. (put a http://www. infront of url to view)
digifan.nl/ShowGalleryImage.aspx? img=Jlz1wB3JMO636rzX3rGMrpOK7mbHBTzFQQ1O
Q%2
fJ5V3Y%3d
and looking at the properties of the image it shows:
digifan.nl/ShowFullImage.aspx? img=Jlz1wB3JMO636rzX3rGMrpOK7mbHBTzFQQ1O
Q%2fJ5
V3Y%3d
which is only the image.
Again thx, i am going to read a bit some more about the system.drawing and
what it al can do but now i have an understanding of
the general thing.
Richard
"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> schreef in bericht
news:VQpV0n2UEHA.3204@.cpmsftngxa10.phx.gbl...
> Hi Richard,
> As for the "A Graphics object cannot be created from an image that has an
> indexed pixel format" error, it is caused by the Graphic object can't been
> created from some certain image format which contains indexed pixel. I've
> done some tests and one means is load the image and convert it into jpeg
> format first and then create Graphich object to manipulate it. For
example,
> here is my test code:
> ========================================
==========
> Private Sub Output_Image(ByVal path As String)
> Try
> Dim img As Image = Image.FromFile(path)
> Dim stream As New System.IO.MemoryStream
> img.Save(stream, ImageFormat.Jpeg)
> Dim imgNew As Image = Image.FromStream(stream)
> Dim g As Graphics = Graphics.FromImage(imgNew)
> g.DrawString("MS Test", New Font("Verdana", 20,
> FontStyle.Bold), _
> New SolidBrush(Color.Beige), 0, 0)
> Response.Clear()
> Response.ContentType = "Image/jpeg"
> imgNew.Save(Response.OutputStream, ImageFormat.Jpeg)
> Response.End()
>
> img.Dispose()
> stream.Close()
> imgNew.Dispose()
> Catch ex As Exception
> Response.Write("<br>" + ex.Message)
> End Try
> End Sub
> ========================================
=========
> Please have a try to see whether it works for you. Thanks.
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
> Get Preview at ASP.NET whidbey
> http://msdn.microsoft.com/asp.net/whidbey/default.aspx
>
System.Drawing: Error when using a .bmp or .gif file but not when .jpg
whenever I use a .jpg file it works perfect.
Why is that? and how to fix it?
I almost have no knowledge about the system.drawing and so I am in the dark
about this.
This is my code
-----------
<%@dotnet.itags.org. Page Language="vb" %>
<%@dotnet.itags.org. import namespace="system.drawing" %>
<%@dotnet.itags.org. import namespace="system.drawing.imaging" %>
<%@dotnet.itags.org. import namespace="system.drawing.drawing2d" %>
<%
' initialise objects
dim strFilename as string
dim b as New System.Drawing.Bitmap(server.mappath("test.jpg"))
dim g as graphics = graphics.fromimage(b)
g.smoothingMode = smoothingMode.antiAlias
dim stringFormat As New StringFormat()
g.drawString("The Magic Word", New font("arial",3),systembrushes.windowtext,
New pointF(2,2), stringFormat)
' Set the content type
response.contenttype="image/jpeg"
' send the image to the viewer
b.save(response.outputstream, b.rawformat)
' tidy up
b.dispose()
%thx a lot, this really helped me out.
I got no errors and with some thinking I made sure ppl can't link to my
files. (put a http://www. infront of url to view)
digifan.nl/ShowGalleryImage.aspx?img=Jlz1wB3JMO636rzX3rGMrpOK 7mbHBTzFQQ1OQ%2
fJ5V3Y%3d
and looking at the properties of the image it shows:
digifan.nl/ShowFullImage.aspx?img=Jlz1wB3JMO636rzX3rGMrpOK7mb HBTzFQQ1OQ%2fJ5
V3Y%3d
which is only the image.
Again thx, i am going to read a bit some more about the system.drawing and
what it al can do but now i have an understanding of
the general thing.
Richard
"Steven Cheng[MSFT]" <v-schang@.online.microsoft.com> schreef in bericht
news:VQpV0n2UEHA.3204@.cpmsftngxa10.phx.gbl...
> Hi Richard,
> As for the "A Graphics object cannot be created from an image that has an
> indexed pixel format" error, it is caused by the Graphic object can't been
> created from some certain image format which contains indexed pixel. I've
> done some tests and one means is load the image and convert it into jpeg
> format first and then create Graphich object to manipulate it. For
example,
> here is my test code:
> ==================================================
> Private Sub Output_Image(ByVal path As String)
> Try
> Dim img As Image = Image.FromFile(path)
> Dim stream As New System.IO.MemoryStream
> img.Save(stream, ImageFormat.Jpeg)
> Dim imgNew As Image = Image.FromStream(stream)
> Dim g As Graphics = Graphics.FromImage(imgNew)
> g.DrawString("MS Test", New Font("Verdana", 20,
> FontStyle.Bold), _
> New SolidBrush(Color.Beige), 0, 0)
> Response.Clear()
> Response.ContentType = "Image/jpeg"
> imgNew.Save(Response.OutputStream, ImageFormat.Jpeg)
> Response.End()
>
> img.Dispose()
> stream.Close()
> imgNew.Dispose()
> Catch ex As Exception
> Response.Write("<br>" + ex.Message)
> End Try
> End Sub
> =================================================
> Please have a try to see whether it works for you. Thanks.
> Regards,
> Steven Cheng
> Microsoft Online Support
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
> Get Preview at ASP.NET whidbey
> http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Richard,
As for the "A Graphics object cannot be created from an image that has an
indexed pixel format" error, it is caused by the Graphic object can't been
created from some certain image format which contains indexed pixel. I've
done some tests and one means is load the image and convert it into jpeg
format first and then create Graphich object to manipulate it. For example,
here is my test code:
==================================================
Private Sub Output_Image(ByVal path As String)
Try
Dim img As Image = Image.FromFile(path)
Dim stream As New System.IO.MemoryStream
img.Save(stream, ImageFormat.Jpeg)
Dim imgNew As Image = Image.FromStream(stream)
Dim g As Graphics = Graphics.FromImage(imgNew)
g.DrawString("MS Test", New Font("Verdana", 20,
FontStyle.Bold), _
New SolidBrush(Color.Beige), 0, 0)
Response.Clear()
Response.ContentType = "Image/jpeg"
imgNew.Save(Response.OutputStream, ImageFormat.Jpeg)
Response.End()
img.Dispose()
stream.Close()
imgNew.Dispose()
Catch ex As Exception
Response.Write("<br>" + ex.Message)
End Try
End Sub
=================================================
Please have a try to see whether it works for you. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Wednesday, March 28, 2012
System.IO.File.Copy not copying and no error
throw a new exception, outputing your source/destination paths along with
the original exception:
Try
System.IO.File.Copy(Source,Dest)
Catch ex as exception
throw new Exception("Source: '" & source & "' - Dest: '" & dest &
"'",ex)
end try
also, put a break point at the Throw, and examine your variables.
"Xander Q." <xander_q@dotnet.itags.org.hotmail.com> wrote in message
news:1958ff15.0307052341.260d3083@dotnet.itags.org.posting.google.c om...
> Something really strange is happening. i'm using the following code to
> copy a file. this worked on my development machine, but when i moved
> it to the server (win2k) it is not copying the file and not generating
> an error. it just merrily goes on.
> ---------------------
> source= Server.MapPath("/TTClaimsForm2/Reports/xxx.doc")
> dest= Server.MapPath("/TTClaimsForm2/Reports/Temp/xxx.doc")
> System.IO.File.Copy(source, dest)
> ---------------------
>
> i checked the value of dest and it's correct. i replaced it with an
> empty string and it gave an error as expected.
> BUT i noticed that if i hard code destination like this:
> System.IO.File.Copy(source,
> "C:\inetpub\wwwroot\ttclaimsform2\Temp\xxx.doc") then the copy works.
> how can this be happening?"David Waz..." <dlw@.pickpro.com> wrote in message news:<bhZNa.1682$Ro2.1449@.newssvr31.news.prodigy.com>...
> I'd suggest wrapping the copy in a Try/Catch block just to be sure. Then
> throw a new exception, outputing your source/destination paths along with
> the original exception:
ah yes i neglected to mention that i already did that, and the value
of 'dest' is correct. it is the same as the hard-coded string and yet
it fails...
damn i hate this stuff!!!
but thx for the input...
System.IO.File class and IP paths?
"\\10.100.100.1\myfolder\test.txt"
When running the aspx file on the server (the server is
also the client) it works, but when using another NT
client it does not work.
The err.description says "Could not find file ..."
System.IO.File.Exists return false here.
But If I manually paste in \\10.100.100.1
\myfolder\test.txt in the IE address field and press "Go"
the file is found.
Strange or not?Hi,
I don't think that the default asp.net user got rights to access network
resources.
Natty Gur[MVP]
Phone Numbers:
Office: +972-(0)9-7740261
Fax: +972-(0)9-7740261
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!