Mombu the Programming Forum sponsored links

Go Back   Mombu the Programming Forum > Programming > Display a .tif/.tiff image and make alterations in the image
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 11th October 18:20
vishal khandelwal
External User
 
Posts: 1
Default Display a .tif/.tiff image and make alterations in the image


Hi,

I want to show a .tif (or .tiff) image in any way (on a TImage or some
other component ). Is there anyway i can show this image?. I may need to
convert .tif to .jpg (or any other format) and then load it (how to do this
conversion??). Also i want to make a few alterations in the image (eg put a
few spots) and for that i may need to access the image pixels as an array
(1D or 2D) Is it possible? If yes, how?

Thanks in advance,
Vishal
  Reply With Quote


  sponsored links


2 11th October 18:20
vishal khandelwal
External User
 
Posts: 1
Default Display a .tif/.tiff image and make alterations in the image


Can i just convert a TIFF image to a bitmap (or a jpeg etc) and then do rest
of the processing on the converted image.. if yes, how? Are there any free
tools available for the same?

-Vishal
  Reply With Quote
3 26th October 19:31
michel leunen
External User
 
Posts: 1
Default Display a .tif/.tiff image and make alterations in the image


Have a look at GDI+. It allows you to convert to/from several image
format and show the result on a canvas (HDC). A TImage has a Cnavas
property and GDI+ is able to draw an image to this canvas.
http://www.leunen.com/cbuilder/gdiplus.html

Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, C++BuilderX, BCC5.5.1 Web site:
http://www.leunen.com/
----------------------------------------
  Reply With Quote
4 26th October 19:31
jim dodd
External User
 
Posts: 1
Default Display a .tif/.tiff image and make alterations in the image


You could try the free GraphicEx component. It adds TIFF and many other
image formats to Builder and Delphi so you can use a TImage just as
you normally would. I believe that once you've read your image into
the TImage (or at least the Picture member of TImage) you then have a
bitmap (TCanvas) to write on and do anything you want. I don't think
you can save in TIFF format, though. I may be wrong about a LOT of this
but it's a free component to try and it lets you work with familiar
components.

http://www.soft-gems.net/Graphics.php#GraphicEx

Good luck,

Jim Dodd
Onset Computer Corp.
  Reply With Quote
5 26th October 19:31
vishal khandelwal
External User
 
Posts: 1
Default Display a .tif/.tiff image and make alterations in the image


Hey Michel,

Much thanks for ur reply, i did exactly as the procedure says....but somehow
just a blank image appeared (with dimension exactly equal to that of the
image i tried to show).
//--------------------
Gdiplus::Graphics graphics(ImageWithSpots->Canvas->Handle); // here
"ImageWithSpots" is the name of the TImage component

//Load the image from a file
Gdiplus::Image image(L"C:\\Do***ents and
Settings\\vishal_khandelwal\\Desktop\\do***ents\\m yPicture.tif");
graphics.DrawImage(&image, 0, 0, image.GetWidth(), image.GetHeight());

ImageWithSpots->Width = image.GetWidth();
ImageWithSpots->Height = image.GetHeight();
//--------------------

Am I doing something incorrect??

-Vishal
  Reply With Quote
6 26th October 19:31
michel leunen
External User
 
Posts: 1
Default Display a .tif/.tiff image and make alterations in the image


No sorry, I don't see anything wrong with your code.
Did you test if image is not NULL and if it's the case what is the error
(status) of GDI+?

Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, C++BuilderX, BCC5.5.1 Web site:
http://www.leunen.com/
----------------------------------------
  Reply With Quote
7 26th October 19:31
vishal khandelwal
External User
 
Posts: 1
Default Display a .tif/.tiff image and make alterations in the image


Hi Michel,

No the image is not NULL. Had it been NULL i would have got an error on the
line where i access the height and width of the image.
I noticed a few thing though: // here "ImageWithSpots" is the name of the
TImage component

1. if I try " HDC hdc = GetDC(ImageWithSpots->Canvas->Handle); " i get a
compilation errors:

[C++ Error] ShowImage.cpp(16): E2034 Cannot convert 'HDC__ *' to 'HWND__ *'
[C++ Error] ShowImage.cpp(16): E2342 Type mismatch in parameter 'hWnd'
(wanted 'HWND__ *', got 'HDC__ *')

Why is that so? (i m new to BCB so excuse me if its a stupid question)

2. I also get warnings:

[C++ Warning] GdiplusHeaders.h(582): W8022 'Bitmap::Clone(const Rect &,int)'
hides virtual function 'Image::Clone()'

3. Instead of trying to show the image i also tried to just draw a line etc
on the TImage object but was unable to do the same:

// Create a Pen object.
Gdiplus::Pen blackPen(Gdiplus::Color(255, 0, 0, 0), 3);

// Create an array of Point objects that define the lines to draw.
Gdiplus::Point point1(10, 10);
Gdiplus::Point point2(10, 100);
Gdiplus::Point point3(200, 50);
Gdiplus::Point point4(250, 300);

Gdiplus::Point points[4] = {point1, point2, point3, point4};
Gdiplus::Point* pPoints = points;

// Draw the lines.
graphics.DrawLines(&blackPen, pPoints, 4);

I still dont get what could be the reason for this abnormal behaviour . are
some flags are not switched properly??
The thing is that i get the metadata abt the image.. i.e.image.GetWidth(),
image.GetHeight(), image.GetPaletteSize(), image.GetPixelFormat()... all
these return different values for different images.. the height and width
are exactly as they are of the actual image.

Thanks and Regards,
Vishal
  Reply With Quote
8 26th October 19:31
vishal khandelwal
External User
 
Posts: 1
Default Display a .tif/.tiff image and make alterations in the image


Hi Jim,

It seems that the GraphicEx is just for the Delphi. They have not mentioned
anything about its Use with Borland. ( i m not sure abt this.. being a
newbie)
the solution given by Michel almost works (just one problem of image not
being shown).. I'll still keep looking in that link.. hope i find somethin
useful.

thanks and Regards,
Vishal
  Reply With Quote
9 26th October 19:31
vishal khandelwal
External User
 
Posts: 1
Default Display a .tif/.tiff image and make alterations in the image


Hi Michel,

Thanks for ur help.. It worked. What I was doing wrong was that the initial
size of my TImage was 0,0. which i was changing to the size of the image
after drawing the image and so i was getting a blank gray window. i changed
the order and it worked. (perhaps a newbie error :-) ) I'll now work on
manipulation of whatever is shown on the TImage. (and will get back to u
incase i have problems)

Much thanks again.
-Vishal
  Reply With Quote
10 26th October 19:31
michel leunen
External User
 
Posts: 1
Default Display a .tif/.tiff image and make alterations in the image


GetDC requires a window handle and you give it a handle to a devive context instead. Try:
HDC hdc = GetDC(ImageWithSpots->Handle);
but you already have a handle to the TImage device context.

I don't get this warning but I use GDI+ mainly with the free commandline
compiler which is the same compiler as BCB5. Are you using BCB6? Some
people reported to me that some GDI+ functions only works in release
mode. They got weird errors in debug mode. It also appears to be
important to #define SRICT in the conditionnal defines of the project
instead of directly in your code.

Michel
--
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, C++BuilderX, BCC5.5.1 Web site:
http://www.leunen.com/
----------------------------------------
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666