.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Bitmap casting

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :Windows Application
Hi, I'm working on a project that manipulate images. I put a Open Dialog Box to load images to the program. After the user choose an especific image my program does something like this: pictureBox1.Image = (Bitmap)image; It works fine with all image format I've tested. Will it work for all image formats? Thanks.

View Complete Post

More Related Resource Links

Bitmap FromFile space "file not found"


I am using aspose.slides to create PPTx's. Some of the process involves loading jpg's from another server and including them in the presentation. This works fine in my development environment. When I upload the site to its server, the jpg loading fails.

I am trying to access jpg's on the other server by:

   oFS = New FileStream(sFile, FileMode.Open, FileAccess.Read)

This causes an access violation error when run from the server.

I also boiled the code down to reading the file directly:

   oImg = System.Drawing.Bitmap.FromFile(sFilePath)

This causes a file not found error.

We have narrowed the problem down to the fact that the File Path has a space in it. How does one solve this problem (while still keeping the space, there is a lot of legacy data)? I have tried replacing the space with %20 or +. I have tried using Server.UrlEncode. The error message always comes back with the encoding in place (like no decoding

Bitmap to Image Control - ImageUrl


 This is my first attempt at using the drawing features of asp.net.  I just want to start simple, and create a single color bar based on a value for a single graph.  I wrote this so far, but I can't figure out how to take the bitmap I just created, and apply it to the Image Control. Do I have to save the file first, and then reload it.

Plus, my box keeps coming out pure black, I trying to fill the box with a color. 

This is part of a web custom control, in which I dynamically created an Image Control. I want to apply the bitmap I made to the image control. 


Dim imgGoogle As Image
imgGoogle = New Image
imgGoogle.ImageAlign = ImageAlign.AbsMiddle
imgGoogle.ImageUrl = cs.GetWebResourceUrl(rsType, "ice5software.BotCatcher.Google.gif")
Private Sub DrawBarGraph_Google(ByVal BarValue As Integer)

	Dim objBitmap As System.Drawing.Bitmap
	Dim objGraphics As S

encoding/decoding a string to/from bitmap


I have two methods:

Encode - takes a string, converts it to array of bytes, uses bytes to specify colors, creates a color and sets a pixel based on bytes

Decode - takes a pixel, retrieves color (R,G,B) bytes and converts them to characters, that produces a string which was previously encoded

I'm using two for loops (img height/width) to specify position and access pixels

The issue is that once display (Control Panel\Appearance and Personalization\Display) changes to anything other then "Smaller - 100%",
bytes have different values during decoding, thus different string is produced (corrupted).

If the setting is set to "Smaller - 100%" the results are normal.

What can I do to avoid that problem?

Thanks in advance

Writing Bitmap to Response.OutputStream - Generic Error Occured in GDI+



This is what I'm trying to do when I get the error on the server (it works on my local machine):

System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image); 

Response.ContentType = "image/bmp";
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);

I don't think it can be a permissions problem because this works on the server:

System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image);

Response.ContentType = "image/jpeg";
bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

So how do I get this to work for a bitmap?


how to create a Bitmap with size(20000,30000) in c#

hi how to create a BitMap with size (20000,30000) using C#

Displaying a System.Drawing.Bitmap in a WPF Image control

How would I convert a System.Drawing.Btimap into a comparable WPF image control so I can display in on my WPF window? Thanks

Problem casting date

I'm developing a Windows Forms app using VS 2008 with a SQL Server 2005 database. I've got search form where users can search for data by entering one or two criteria. One of these is a date which corresponds to a date field in my database. The user clicks on a button, which feeds the criteria into a stored procedure. The results are displayed in a datagridview control. While the functionality works well with the non-date criteria, whenever a date criteria is used on it's own a cast error is raised ('Conversion failed when converting datetime from character string.') I've tried lots of ways of casting the date (formatting using left, right and mid finctions, using the substring function etc) but still can't get it to work. Code and SQL are shown below. Does someone know where I've gone wrong? 'DateAssayRequested' is the date in question. <vb> 'set up and initialise connection conn = New SqlConnection(etc) comm = New SqlCommand comm.Connection = conn comm.CommandText = "SPSearch" comm.CommandType = CommandType.StoredProcedure 'create input parameters, set types and values param = comm.CreateParameter param.ParameterName = "@assayid" param.Direction = ParameterDirection.Input param.Value = txtLabNo.Text

Change Bitmap Resolution and Turn Black & White

i use this method to resize bitmaps. Bitmap OriginalBM = (Bitmap)Bitmap.FromStream(fileUploader.PostedFile.InputStream); Size newSize = new Size(300, 500); Bitmap Resizebm = new Bitmap(OriginalBM, newSize); Resizebm.Save(HttpContext.Current.Server.MapPath(yourPath) + yourImage, ImageFormat.Jpeg); OriginalBM.Dispose(); My question is how can i Change Bitmap Resolution and Turn Black & White?

Bitmap drawing

I am trying to draw objects (line, etc) on a Bitmap. However, I have run into some problems: the origin of the bitmap coordinate system is at the top-left corner of the bitmap. How can I have it set to the bottom-left corner? Also, I need to draw some real world objects on this bitmap: how can I transform or map the real world coordinates on the bitmap coordinate space? Any help is really appreciated as I am totally lost on this one.

Twain tiff to bitmap

I get tiff image handle frm twain. Now how should I convert it to Bitmap? static FromHbitmap doesnt workstatic internal FromGdiPlus also doesnt work .NET guy

How to: Deal with UniqueIdentifiers, casting it to Guid in DAL

HelloMy users table has a column which is a unique identifier (basically this has FK relationship with aspnet_users table, of membership) Now I have an AppUser class which maps to my users tableuserid        intuser_aspnet_id  guid In my DAL, I am retreiving a user from the db an want to populate my appUser obj. How do i Convert value retreived to GuidappUsr.UserID = Convert.ToInt32(reader["user_id"]);appUsr.AspNetUserID =  reader["aspnet_user_id"];(There is no convert.ToGuid)How can this be done?appUsr.UserID = Convert.ToInt32(reader["user_id"]);                 appUsr.AspNetUserID = (Guid)reader["aspnet_user_id"];

How convert bitmap to Image.source ?

I hold some bitmap object in the memory  ( simple System.Drawing.Bitmap ). I want to make some wpf image control to show this bitmap. I dont want to save the bitmap to the disk and then load it as URI to the wpf image control So, How can i do this simple action ?   Thanks.

How to determine the transparency color in a Bitmap

I think I found out how to set the transparent color in a bitmap. Bitmap.MakeTransparent(Color) But how can I get the transparent color from a bitmap. BTW. I read the term "Alpha Transparency" I'm guessing that that means the alpha values of the pixel colors are not all 255. Is that correct and is that all there is to it? Are there two features in a bitmap? The transparent color and Alpha Transparency. Or are they the same? Thanks in advance  

IEnumerable Type Casting

Hello Everyone,  The following line is giving me an InvalidCastException when trying to convert to IEnumerable type, even though I have implemented IEnumerable interface.  Return New CountryInfo(CountryCodes(i), CountryNames(i)) (also in bold below)Imports System Imports Gaia.WebWidgets.HtmlFormatting Imports System.Collections.Generic Imports System.Globalization Public Class CountryInfo Implements IEnumerable Property Name As String Property Code As String Public Sub New(ByVal code As String, ByVal name As String) _Code = code _Name = name End Sub Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator Return CType(Me, IEnumerator) End Function Public Class SearchResult Private ReadOnly _countries As List(Of CountryInfo) Private ReadOnly _query As String Friend Sub New(ByVal countries As List(Of CountryInfo), ByVal query As String) _countries = countries _query = query End Sub Public ReadOnly Property IsEmpty As Boolean Get Return _countries.Count = 0 End Get End Property Public ReadOnly Property Countries As List(Of CountryInfo) Get Return _countries End Get End Property Public Function Bui

Casting issues when using WHERE and uniqueidentifier

Hello all, I am getting the same error when trying to build the queries below by using 2 diffferent methods: DECLARE @stepIds varchar(8000), @instance uniqueidentifier, @instance_binary binary(16) SET @stepIds = '' SET @instance = '28B2D4FB-67F6-40CA-84A2-839BF3CC4B91' SET @instance_binary = CAST(@instance AS binary(16)) SELECT @stepIds = @stepIds + ',''' + stepID + '''' from Uds.RealtimeLogging WHERE instanceID = @instance_binary --Conversion failed when converting the varchar value ''' to data type int. --OR DECLARE @stepIds varchar(8000), @instance uniqueidentifier SET @stepIds = '' SET @instance = '28B2D4FB-67F6-40CA-84A2-839BF3CC4B91' SELECT @stepIds = @stepIds + ',''' + stepID + '''' from Uds.RealtimeLogging WHERE instanceID = convert(uniqueidentifier, @instance) --Conversion failed when converting the varchar value ''' to data type int. Thank you  JCD

Dithering problem with Bitmap class

I have a scanned document(black and white in color), which is typed through a word processor. So, I each letter is very crisp in the image and is not overlapping with any other character. But once I load that into Bitmap class I see that because of dithering the words get connected by gray color.   How can i make sure, that when we are loading the image in Image or Bitmap class we can avoid dithering at all. It means that if the system can find the exact color then map it otherwise leave the pixel untouched and dont fill any color(let's say leave it as white).  suneeelid2000@gmail.co

Mouse Drawing in Bitmap and repositioning bitmap

Dear Friends,                  I have made an application similar to this: http://www.bobpowell.net/simpledraw.aspx. But I have made few changes like I have used only the mouse draw option where the drawing is zoomed to specific level with Matrix transformation and I have snapped the mouse to the current mouse coordinates. The programe is working fine. Problem arises when I try to place the same bitmap in X and Y axis many time. After placing bitmap in both the axis once again repositioned the mouse like whenever the mouse is clicked on repositioned bitmaps it draws into the original bitmap and displays the image in all positioned bitmaps. I have solved the mouse back tracking issues.                   The major problem I face here is that when the mouse crosses one bitmap to another bitmap it ticks a continuous line. That is whenever mouse crosses 0th pixel to the last pixel of previous positioned bitmap or from last pixel to 0th pixel of next positoned bitmap. Whereas I need smooth mouse drawing programme with bitmaps positioned many time so that the drawn image should look continuous. I couldnt give code because it is huge.               &n
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend