Hi
First I want to say sorry for my bad english (I speak and write spanish)

I am working in a program written by me in VB6, which load a image file (JPEG) and looks in every pixel of it to take the RGB component of each one of them, to compare one user given color with the pixels of the image to count them. At the end, I need to save the image in JPEG (which I modify the width and height) with a new name in a new location.

To do that, I need to put the image info (pixel info) in a array like this:

type tRGB       ' Type used to store the RGB components of a pixel
      R as byte
      G as byte
      B as byte
   end type
 
   ' Two dimensional array to store the pixels in RGB components
   dim aImageArray(lImageWidth, lImageHeight) as tRGB

... then I get into the array to compare the color given with every position of the two dimensional array.

The questions are:
- How can I load the color information of the image in such array?
- How can I resize the image (in most cases, the digital images are really big)?
- How can I save the array in a new JPEG image?

Note: I have already take a look at the article in vbAccelerator http://www.vbaccelerator.com/home/VB/Code/vbMedia/Saving_Pictures_to_JPG/Using_Intel_JPG_Library/article.asp where the author explains how to do something like the thing I need. The problem is that he use a DLL from Intel Corp. (IJL.DLL) which I dont want to use. I need something that Windows (9x, 2k or XP) can bring me by itself.
I have a testing working version using this aproach which runs perfect. But again, I dont want to use DLL's from others than Windows.

Sorry for the long of this post and for my bad english.

Thanks for your interest, and please, if you can, help me.

--Martin

Recommended Answers

All 7 Replies

first of all your making it way to hard on your self just open the picture in a different program and save it as a jpeg picture.

Thanks for reply.

I have found a diamond!!! Try this: http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=65964&lngWId=1

He uses a PictureBox to load the JPEG file and then, using API's, put the entire image data in the array. If you are needing something like this, just take a look on that tutorial.

True, it not answer all my questions, but it explains clearly how to put a image in a array and do some process on it. REALLY FAST!!!

:mrgreen: :mrgreen: :mrgreen:

I still need to know how to save the image stored in the array in a JPEG file. :-|

--Martin

first of all your making it way to hard on your self just open the picture in a different program and save it as a jpeg picture.

As a programming forum, using a different program and saving it with that doesn't make much sense.....

You don't need it in array of bytes. Once it's in a picturebox, you can simply call the SavePicture function built into VB. SavePicture picture1.picture, "c:\newfile.jpg" , check here: http://experts.about.com/q/Visual-Basic-1048/Resizing-JPEG-VB6.htm, however, if you are truly hell-bent on doing it the hard way, here is something to look at:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=50065&lngWId=1, and if you know a bit about working with files opened for binary, you can learn about the JPEG headers and file format in these:
http://www.obrador.com/essentialjpeg/headerinfo.htm
http://www.codeproject.com/bitmap/iptc.asp
Let me know how it turns out, and what you decide to do.

Thanks Comatose!

The need to store the pixel data in arrays is to do some processing. Not for the save stuff. Once I have procesed the "input image", I need to save the modified result image in a different location (or the same, it is not the matter here)
I have been trying the SavePicture function, but it stores the file in my disk in .bmp format instead of the JPEG I need (I am not talking about the file extension but the format of the image)

Is it a VB6 limitation? I Say, VB6 (using the SavePicture function) cannot save JPEG files. Is it true?

By now, I am comfortable with the save stuff, but if I could save the file as a real JPEG it would be great! I will read the articles in the locations you give me and then I'll let you know about this.

Thanks again!!!

PS: The JPEG Header Information article is great!!! Now it makes me get into new troubles in VB6 programming!!! (When I finish this project ;) )

:( it seems you are right about the savepicture method. Here is some code I found (however, it requires an external .dll) http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=21298&lngWId=1, that will allow you to convert a .bmp to a .jpg format, but doing this manually is going to be rough. You'll have to open the file for binary access, and then write the appropriate bytes of information to the file. If I can find a better jpeg file format resource, I could cruft up some code on this...

Ok Comatose, but dont put yourself in such trouble. I can live by now with the bmp format file. :)

I will post here about the places where I get some information on this.

Do you want to know about the need to save the file in JPEG format? Because I am using a offline web page to show the results of the image process. Internet Explorer (and I guess other browsers) can load a BMP file. I know, it is not the better way to use an image in a web page. I would like to use JPEG format instead. But really, will the normal end user of my application feel the diference? I guess not.

Thanks!

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.