For any of you that have been following my post regarding storing images into MYSQL on a mono based platform. I found a solution to my problem, and it was a simple as anything.
Just to recap. My problem involved Mono's buggy System.Drawing class. I am running Mono 1.1.12.1 on Fedora 2 (I know pretty old, but works a treat). My task was to create a new bitmap from an existing Jpeg, edit it and then save it to an absolute path on
my server. The first problem I encountered was with the Bitmap.Save function
System.Drawing.Bitmap newBit = new System.Drawing.Bitmap.FromFile("image.jpg");
newBit.Save("newFilename", ImageFormat.Jpeg);
//The above code results in a GDI error.
Faced with this problem, i decided to look for an alternative solution to my problem. Mono isnt perfect, but amazing enough to still use it despite its bugs. My attention turned to MYSQL. I was browing some articles a few days ago and saw an article on saving
and reading images to and from a MYSQL database using asp.net. I read the tutorial, and although it wasnt the clearest article in the world, i got the Jist.
I started building some functions to add the image to the database and to read the bytes from an image to input into my SQL statement. Low and behold, another error arose, my linux box came to a screaming halt and gurgelled another error: Something about
cannot write to stream. I figured that the output was too large, since the image i was dealing with was pretty hefty, 50KB +, mono didnt allow it. I searched high and low for a solution.
My main aim was to edit a bitmap and return it was a jpeg to create an image map out of. I started programming with PHP some time ago, so whilst browsing PHPbuilder i came across and article about displaying images from a DB. The PHP code was pretty simple
and simply involved accessing the database, setting the header content type and that was it. Using PHPMYADMIN to upload an image to my LONGBLOB field in my images DB, i uploaded a 30KB jpeg to test with. I ran the script and there was the JPEG in pristine
condition.
With this script in tact and working in PHP, i decided on translating it to ASP.NET using the same methodology hoping this would solve my problem of using the image as an image map. I looked towards creating the bitmap and just outputing it whenever i needed
it without saving it anywhere.
I guess this is just information for those using Mono, i hope someone can save the countless hours i lost fixing this dilema. Its an alternative to saving to a DB or an absolute path, even if you have to lose a few miliseconds in processing time.
Member
1 Points
36 Posts
System.Drawing Bug in Mono 1.1.12.1 resolution.
Jan 11, 2006 01:12 AM|martin2dabo|LINK
Hello all,
For any of you that have been following my post regarding storing images into MYSQL on a mono based platform. I found a solution to my problem, and it was a simple as anything.
Just to recap. My problem involved Mono's buggy System.Drawing class. I am running Mono 1.1.12.1 on Fedora 2 (I know pretty old, but works a treat). My task was to create a new bitmap from an existing Jpeg, edit it and then save it to an absolute path on my server. The first problem I encountered was with the Bitmap.Save function
System.Drawing.Bitmap newBit = new System.Drawing.Bitmap.FromFile("image.jpg");
newBit.Save("newFilename", ImageFormat.Jpeg);
//The above code results in a GDI error.
Faced with this problem, i decided to look for an alternative solution to my problem. Mono isnt perfect, but amazing enough to still use it despite its bugs. My attention turned to MYSQL. I was browing some articles a few days ago and saw an article on saving and reading images to and from a MYSQL database using asp.net. I read the tutorial, and although it wasnt the clearest article in the world, i got the Jist.
I started building some functions to add the image to the database and to read the bytes from an image to input into my SQL statement. Low and behold, another error arose, my linux box came to a screaming halt and gurgelled another error: Something about cannot write to stream. I figured that the output was too large, since the image i was dealing with was pretty hefty, 50KB +, mono didnt allow it. I searched high and low for a solution.
My main aim was to edit a bitmap and return it was a jpeg to create an image map out of. I started programming with PHP some time ago, so whilst browsing PHPbuilder i came across and article about displaying images from a DB. The PHP code was pretty simple and simply involved accessing the database, setting the header content type and that was it. Using PHPMYADMIN to upload an image to my LONGBLOB field in my images DB, i uploaded a 30KB jpeg to test with. I ran the script and there was the JPEG in pristine condition.
With this script in tact and working in PHP, i decided on translating it to ASP.NET using the same methodology hoping this would solve my problem of using the image as an image map. I looked towards creating the bitmap and just outputing it whenever i needed it without saving it anywhere.
<%
@ Page Language="C#" AutoEventWireup="true" Src="treePlot.cs" Inherits="TreePlot" %><%
@ Import Namespace="System.Drawing.Drawing2D" %><%
@ Import Namespace="System.Drawing.Imaging" %><%
@ Import Namespace="System" %><%
@ Import Namespace="System.IO" %><%
//Below calls one of my classes that simply returns a bmp.
TreePlot newImage = new TreePlot();System.Drawing.
Bitmap newBit = newImage.plotZipcodes();Response.ContentType =
"image/jpeg";newBit.Save(Response.OutputStream,
ImageFormat.Jpeg);%>
I saved this script as imageGen.aspx. With this script you can now call the image from your HTML or ASP image control
e.g. <img src=http://www.blahblah.com/imageGen.aspx border=0 />
I guess this is just information for those using Mono, i hope someone can save the countless hours i lost fixing this dilema. Its an alternative to saving to a DB or an absolute path, even if you have to lose a few miliseconds in processing time.
peace out
martin