473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problem with indexed pixel format/

I know alot of people have the problem with indexed pixel format. I hope
someone can show me the solution to this.I am have problem with graphics
with the following code giving the error:

"A Graphics object cannot be created from an image that has an indexed pixel
format."

'My code
<%@ Page Language="vb" %>
<%@ import namespace="system.drawing" %>
<%@ import namespace="system.drawing.imaging" %>
<%@ import namespace="system.drawing.drawing2d" %>
<%

' initialise the web object
Dim webC As New System.Net.WebClient()

' set the URL
Dim strFilename as string
strFilename="http://www.domain.com/graph.gif"

' create a bitmap based on the image from the URL
Dim g = New System.Drawing.Bitmap(webC.OpenRead(strFilename))
response.contenttype="image/gif"

dim gr as graphics = graphics.fromimage(g) ' create a New graphic object
from the above bmp

gr.smoothingMode = smoothingMode.antiAlias ' antialias objects

'' draw the number on the image canvas in verdana 10pt font bold
gr.drawString("ABC", New
font("verdana",14,fontstyle.bold),systembrushes.wi ndowtext, New pointF(2,2))
' send the image to the viewer
g.save(response.outputstream, g.rawformat)

' tidy up
g.dispose()
gr.dispose()
webC = Nothing

%>

Nov 21 '05 #1
1 2252
This is intended behaviour. The error "A Graphics object cannot be created
from an image that has an indexed pixel format." says it all.

You need to create an image the same size as the original, get the Graphics
object for it, draw the original onto the new Graphics object, draw your
number and then save the newly created bitmap to the response stream.

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

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

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

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

"jty202" <jt****@gmail.com> wrote in message
news:e1**************@tk2msftngp13.phx.gbl...
I know alot of people have the problem with indexed pixel format. I hope
someone can show me the solution to this.I am have problem with graphics
with the following code giving the error:

"A Graphics object cannot be created from an image that has an indexed
pixel
format."

'My code
<%@ Page Language="vb" %>
<%@ import namespace="system.drawing" %>
<%@ import namespace="system.drawing.imaging" %>
<%@ import namespace="system.drawing.drawing2d" %>
<%

' initialise the web object
Dim webC As New System.Net.WebClient()

' set the URL
Dim strFilename as string
strFilename="http://www.domain.com/graph.gif"

' create a bitmap based on the image from the URL
Dim g = New System.Drawing.Bitmap(webC.OpenRead(strFilename))
response.contenttype="image/gif"

dim gr as graphics = graphics.fromimage(g) ' create a New graphic object
from the above bmp

gr.smoothingMode = smoothingMode.antiAlias ' antialias objects

'' draw the number on the image canvas in verdana 10pt font bold
gr.drawString("ABC", New
font("verdana",14,fontstyle.bold),systembrushes.wi ndowtext, New
pointF(2,2))
' send the image to the viewer
g.save(response.outputstream, g.rawformat)

' tidy up
g.dispose()
gr.dispose()
webC = Nothing

%>

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Raj | last post by:
Hello Members, I wrote a program to convert a greyscale bitmap image in to monochrome bitmap image, a simple thresholding. Input:Greyscale image; Expected Output:Monochrome image Pseudocode:...
1
by: James Dean | last post by:
I have tried a few different methods for scaling an image down but all seem a bit on the slow side. Is there any way i can make this scaling faster....... Here is how i do it now. To display my...
0
by: Webgour | last post by:
Hello, I'm tring to create an indexed image on the fly with the following : Bitmap bcodeBitmap = new Bitmap(50,50,PixelFormat.Format32bppArgb); Graphics objGraphics =...
1
by: jty202 | last post by:
I know alot of people have the problem with indexed pixel format. I hope someone can show me the solution to this.I am have problem with graphics with the following code giving the error: "A...
1
by: Jeff Stewart | last post by:
Is there a procedure for determining whether or not an Image uses any of the indexed pixel formats, short of checking against each one? -- Jeff S.
8
by: **Developer** | last post by:
Seems that Dot.net can not handle files of Indexed Pixel Format as well as other types of formats. Given a file or and Image of type Indexed Pixel Format is there a method to convert it to some...
1
by: Hardy Wang | last post by:
Hi, I found a piece of code to add drop shadow to a photo like below, after I save the image, it is actually a BMP file even though I specify a JPG file extension (see...
0
by: Anil Gupte | last post by:
I am using an Image Button from Microsoft's Power Pack. When I use the ..Enabled=True/False I get the following error "SetPixel is not supported for images with indexed pixel formats" I am...
8
by: Joergen Bech | last post by:
Suppose I have Dim bm As New Bitmap(16, 16,Imaging.PixelFormat.Format8bppIndexed) I cannot use Dim g As Graphics = Graphics.FromImage(bmdest) Dim hdc As IntPtr = g.GetHdc() as the...
1
by: Nathan Sokalski | last post by:
I have created declared a Bitmap using the following statement: Dim bmp As New Bitmap(100, 100, PixelFormat.Format8bppIndexed) Because the SetPixel() method is disabled and a Graphics object...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.