473,480 Members | 4,827 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 16 '05 #1
1 7118
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 16 '05 #2

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

Similar topics

9
4419
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
2412
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
1510
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
1173
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
1123
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
12574
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
4154
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
3022
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
4287
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...
0
7040
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
7080
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
6908
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...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4478
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2994
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.