i have my images stored in database in image data type. i wish to retrieve it out and perform image merging. is there any solution that can make it binary file editable ?

thank you

Recommended Answers

All 7 Replies

What format are the files in? You will likely have to convert them to a bitmap (easiest to work with development wise) then convert them back to their original type (probably jpeg or something compressed for web use). Without knowing the filetype you don't know the file headers (important) or the actual structure of the image data.

are you saying the file format for image? if yes, it is in PNG format
thank you for replying =D

Try

Bitmap b = Bitmap.FromFile("myImage.png");

Now you can play around with the Bitmap members, which will allow you to rescale the image, set/get pixels, and eventually do exactly what you are trying to do :)

alright. i have another question which is.. for retrieving the image from db, i use handler. then for converting the image into bitmap use ?

Post the code that shows how you are getting the data from the DB. Bitmap has a few static members that allow you to build one from a file, a stream, or another image. We'll need to figuire out the best way to construct it for you.

this is the handler:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Configuration;
using System.Data.SqlClient;

namespace WebApplication1
{
    /// <summary>
    /// Summary description for ImageHandler3
    /// </summary>
    public class ImageHandler3 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string customizationID;
            if (context.Request.QueryString["id"] != null)
            {
                customizationID = context.Request.QueryString["id"];
            }
            else
            {
                throw new ArgumentException("No parameter specified");
            }

            context.Response.ContentType = "image/jpeg";
            context.Response.ContentType = "image/bmp";
            Stream strm = ShowImage(customizationID);
            byte[] buffer = new byte[4096];
            int byteSeq = strm.Read(buffer, 0, 4096);

            while (byteSeq > 0)
            {
                context.Response.OutputStream.Write(buffer, 0, byteSeq);
                byteSeq = strm.Read(buffer, 0, 4096);
            }


        }
        public Stream ShowImage(string id)
        {
            object img;

            String connection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(connection);
            con.Open();

            SqlCommand cmd = new SqlCommand("Select clientImage From Customization Where customizationID='" + id + "'", con);
            img = cmd.ExecuteScalar();

            try
            {

                return new MemoryStream((byte[])img);
            }

            catch
            {
                return null;
            }

            finally
            {
                con.Close();
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

for displaying image

productImg.ImageUrl = "ImageHandler2.ashx?ID=" + pID.Text;

im not sure how to get the image after using the handler..

thank you

Use the stream constructor of a Bitmap.

Bitmap myBitmap = Bitmap.FromStream(ShowImage(myStringID));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.