Help with Uploading BMP file to LCD, please

LK/ELK/VK/PK/OK/MX/GLK/EGLK/GVK/GLT Series

Moderators: Henry, Mods

Post Reply
carllance
LCD?
Posts: 2
Joined: Mon Sep 17, 2007 8:30 am

Help with Uploading BMP file to LCD, please

Post by carllance »

I am trying to upload a BMP file to my LCD module (GLK12232-25-SM, Revision 1.4).

The MODG# program works perfectly, but I can't seem to get things working myself.

It would be IMMENSELY helpful if I could get the source code (or just the methods required) to read and upload a BMP file. I can use .NET, C# or VB.NET.

Can you please provide those files?

Thanks!
Carl

Clark
Matrix Orbital
Matrix Orbital
Posts: 881
Joined: Fri Aug 17, 2007 10:58 am
Location: Matrix Orbital
Contact:

Post by Clark »

Hi Carllance,

Thanks for your question. Good to hear that you have been using MOGD# to get a feel for your GLK12232-25-SM. Unfortunately, I can't give out Matrix Orbital source code to just anyone, but I can give you a pretty good idea of what kind of code is required for this operation. I have previously posted the algorithm for this operation that will allow you to have a good start on this operation in any programming language.

Hopefully this will help you upload those bitmaps in your own application,

Troy
Troy Clark
Design & Development
Matrix Orbital

carllance
LCD?
Posts: 2
Joined: Mon Sep 17, 2007 8:30 am

Post by carllance »

Troy,

> Hopefully this will help you upload those bitmaps in your own application,

It does help a ton, thanks!

However, I don't think the transmission is necessarily the hard part, but converting the data to the proper format first.

I was actually also hoping to get the bits where you read the BMP file and convert it to the proper format. I bet LOTS of people need to do the same thing.

Carl

Clark
Matrix Orbital
Matrix Orbital
Posts: 881
Joined: Fri Aug 17, 2007 10:58 am
Location: Matrix Orbital
Contact:

Post by Clark »

Hi Carl,

Good to hear that you have made some headway with your bitmaps. After taking a closer look at your problem, I think you're right; this is definitely the tricky part. There is a section, 7.4, in your manual detailing the font file upload method, although the bitmap method is not as detailed, it is very similar. As you can see, the manual bitmap upload process is rather difficult, and although I do not know what your application may be, I can tell you that in many cases it is easier to upload bitmaps in MOGD#, and then merely issue the 'Display Saved Bitmap' (254 98 [ID] [X] [Y]) command to draw them. In addition, I see that you are using an older PCB Revision, 1.4, I would recommend that you upgrade to the newer Revision 2.0 or check out our website for the newest displays if you continue development well into the future, as we are phasing out this product.

Thanks for your cooperation, let me know how those bitmaps turn out,

Troy
Troy Clark
Design & Development
Matrix Orbital

Jeroen Vonk
LCD Guru
Posts: 55
Joined: Tue Apr 12, 2005 2:31 am

Re: Help with Uploading BMP file to LCD, please

Post by Jeroen Vonk »

carllance wrote:I am trying to upload a BMP file to my LCD module
It would be IMMENSELY helpful if I could get the source code (or just the methods required) to read and upload a BMP file. I can use .NET, C# or VB.NET.
Here's some code to convert a bitmap to the data type of the MO displays. It is not the most elegant code I've ever written, but it does the job. It can load almost every type of bitmap file (also color) because of the internal conversion to 1bpp. (you van change the 'brightness' of the conversion if the result is not very nice)

If you have any questions please feel free to ask, hope this helps...

Code: Select all

	#region Bitmap

	/// <summary>
	/// MatrixOrbital Graphic Bitmap
	/// </summary>
	[ClassInterface(ClassInterfaceType.AutoDual)]
	[Guid("845B33C8-92CC-4926-8F4D-8CB257A86F45")]
	[ProgId("MatrixOrbital.MatrixOrbitalBitmap")]
	public class MatrixOrbitalBitmap
	{
		#region Private members

		private const byte cmoPlaceHolder = 0xFF;
		private Bitmap bitmap;

		#endregion

		#region Constructors

		/// <summary>
		/// Default Constructor
		/// </summary>
		public MatrixOrbitalBitmap()
		{
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="filename">Filename to load bitmap</param>
		public MatrixOrbitalBitmap(string filename)
		{
			LoadFromFile(filename);
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="stream">Stream to load bitmap</param>
		public MatrixOrbitalBitmap(Stream stream)
		{
			LoadFromStream(stream);
		}
		
		#endregion

		#region Public Members

		/// <summary>
		/// Loads bitmap from file
		/// </summary>
		/// <remarks>Format should be 1bppIndexed</remarks>
		/// <param name="filename">Filename</param>
		public void LoadFromFile(string filename)
		{
			Bitmap tmpBmp = new Bitmap(filename);
			Picture = tmpBmp;
		}

		/// <summary>
		/// Loads bitmap from file
		/// </summary>
		/// <param name="filename">Filename</param>
		/// <param name="brightness">Level to determine if a pixel is white or black</param>
		public void LoadFromFile(string filename, int brightness)
		{
			Bitmap tmpBmp = new Bitmap(filename);
			Picture = ConvertBitmap(tmpBmp,brightness);
		}

		/// <summary>
		/// Loads bitmap from stream
		/// </summary>
		/// <param name="stream">stream</param>
		public void LoadFromStream(Stream stream)
		{
			Bitmap tmpBmp = new Bitmap(stream);
			Picture = tmpBmp;
		}

		/// <summary>
		/// Loads bitmap from stream
		/// </summary>
		/// <param name="stream">stream</param>
		/// <param name="brightness">Level to determine if a pixel is white or black</param>
		public void LoadFromStream(Stream stream, int brightness)
		{
			Bitmap tmpBmp = new Bitmap(stream);
			Picture = ConvertBitmap(tmpBmp,brightness);
		}

		/// <summary>
		/// Converts a picture to a black-and-white bitmap
		/// </summary>
		/// <param name="img">Image</param>
		/// <param name="brightness">Level to determine if a pixel is white or black</param>
		/// <returns>Converted bitmap</returns>
		public static Bitmap ConvertBitmap(System.Drawing.Image img, int brightness)
		{
			System.Drawing.Bitmap img1 = (Bitmap)img; 

			// first convert to grayscale
			Bitmap bitmapGrayScale = new Bitmap(img1.Width,img1.Height);
			for(int y=0;y<bitmapGrayScale.Height;y++)
			{
				for(int x=0;x<bitmapGrayScale.Width;x++)
				{
					Color c=img1.GetPixel(x,y);
					int luma = (int)(c.R*0.3 + c.G*0.59+ c.B*0.11);
					bitmapGrayScale.SetPixel(x,y,Color.FromArgb(luma,luma,luma));
				}
			}

			System.Drawing.Bitmap bm = new  System.Drawing.Bitmap(
				img1.Width,
				img1.Height);

			// convert to 1bpp
			for(int y=0;y<bitmapGrayScale.Height;y++)
			{
				for(int x=0;x<bitmapGrayScale.Width;x++)
				{
					if(bitmapGrayScale.GetPixel(x,y).GetBrightness()>(((double)brightness)/100))
					{
						bm.SetPixel(x,y,Color.Black);
					}
					else
					{
						bm.SetPixel(x,y,Color.White);
					}
				}
			}

			return bm;
		}

		#endregion

		#region Properties

		/// <summary>
		/// Bitmap (1 bpp)
		/// </summary>
		[Category("Image"),Description("Bitmap for MatrixOrbital GraphicDisplay")]
		public Bitmap Picture
		{
			get { return bitmap; }
			set 
			{ 
				if ((value.Width>255) || (value.Height>255))
				{
					throw new Exception("Image too large");
				}

				bitmap = ConvertBitmap(value,20); 
			}
		}
		
		/// <summary>
		/// The actual data of the MatrixOrbital Bitmap (based on the loaded bitmap)
		/// </summary>
		public byte[] Data
		{
			get
			{
				int ix;
				int count;
				byte[] tmpArr = new byte[this.Size];
                
				if (bitmap==null)
				{
					throw new Exception("Bitmap not set");
				}

				tmpArr[0] = cmoPlaceHolder;
				tmpArr[1] = cmoPlaceHolder;
				tmpArr[2] = (byte)bitmap.Width;
				tmpArr[3] = (byte)bitmap.Height;

				count = 0;
				for (int j=0;j<bitmap.Width;j++) // X
				{
					for (int i=0;i<bitmap.Height;i++) // Y
					{
						ix = (int)(count/8);

						if(bitmap.GetPixel(j,i).GetBrightness()>(20/100))
						{
							tmpArr[ix+4] = (byte)(tmpArr[ix+4] + ((byte)(Math.Pow(2,(count % 8)))));
						}

						count++;
					}
				}
												
				return tmpArr;
			}
		}

		/// <summary>
		/// Size of MatrixOrbital Bitmap
		/// </summary>
		public int Size
		{
			get
			{
				if (bitmap==null)
				{
					throw new Exception("Bitmap not set");
				}
				
				return (int)Math.Ceiling(((double)(bitmap.Width*bitmap.Height))/8)+4;
			}
		}

		#endregion
	}

	#endregion

cipher_nemo
LCD Geek
Posts: 41
Joined: Tue Aug 07, 2007 12:20 pm
Contact:

Post by cipher_nemo »

Also, the fastbitmap.dll binary for .NET that is supplied with the GX series SDK should be able to do this too. I don't use it, but I'm aware it does exist.

Post Reply