Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
kenberkun  
#1 Posted : Wednesday, January 5, 2005 7:44:00 AM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

Ok, I'm not the most experience C++ programmer, so promise not to laugh! There are no C++ examples in the docs, so how does one get started? I've created a project, inserted a FileDialog ActiveX control and a Bitmapviewer ActiveX control - but how do I create a Bitmap object? Shouldn't there be a .tlh file or something like that? Or shouldn't I have to run CoInitialize on the DLL?

Any help from anyone who as done this would be greatly appreciated.

Thanks,

Ken

Fedor  
#2 Posted : Wednesday, January 5, 2005 10:38:00 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
You should create wrappers from the Graphics Mill type library. To do it use #import directive (if you are using Visual Studio). You can read about it more detailed in MSDN:

http://msdn.microsoft.com/library/en-us/vclang/html/_predir_The_.23.import_Directive.asp

As for CoInitialize, it depends on the project type you use. If you create MFC project with ActiveX components usage, it is generated by wizard.

I have attached sample MFC project (requires Visual Studio 2003 .NET). Hope it helps.

File Attachment(s):
GraphicsMill_CppSample.zip (175kb) downloaded 78 time(s).
Best regards,

Fedor Skvortsov

kenberkun  
#3 Posted : Friday, January 7, 2005 7:23:00 AM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

Thanks, things are moving along for me, but now I have another problem. I have added the following lines to the OnBnClickedBrightcontrast() method to convert to black and white:

Code:
CComPtr<IBitmapData> piBitmapData;
hr = piBitmap->get_Data(&piBitmapData);
if (FAILED(hr))
	DisplayErrorMessage(hr);
CComPtr<IBitmap> piTempBitmap;
piTempBitmap = NULL;

hr = piBitmapData->ConvertTo1bppIndexedDitheringTypeOrdered ,1,OrderedDitheringTypeSpiral,2,&piTempBitmap);
if (FAILED(hr))
 DisplayErrorMessage(hr);

This works (eg it looks good on the screen), but when I save the file, the program dies (the file is successfully saved, but the SaveToFile method does not return). The error is "unhandled exception". As an experiment I tried using the ConvertTo16bppAlphaGrayscale method and this works fine. It looks like a file format conversion error going from color to b&w, but happening in the SaveToFile method.

Thanks,

Ken

Edited by user Monday, December 24, 2007 4:17:05 PM(UTC)  | Reason: Not specified

Andrew  
#4 Posted : Friday, January 7, 2005 11:02:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Did you modify the code which saves the image to the file? Could you post it? Also, what file format are you saving to?
Andrew  
#5 Posted : Friday, January 7, 2005 11:14:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
By the way, if you do not use ApplyInPlace property, there is no need to use piTempBitmap variable. You can just specify NULL instead:

Code:
hr = piBitmapData->ConvertTo1bppIndexed(DitheringTypeOrdered, 100,OrderedDitheringTypeSpiral,2,NULL);

Edited by user Monday, December 24, 2007 4:17:24 PM(UTC)  | Reason: Not specified

kenberkun  
#6 Posted : Saturday, January 8, 2005 6:40:00 AM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

Here is the entire procedure that I changed. Note that I did not change the Save procedure, just added the conversion to b&w. I am trying to save to .bmp file, either 1 bit or 8 bits. Note that if I convert to 1 bit and then to 8 bits grayscale the (per the example below, see comments) then it works fine! Probably something to do with saving a 1 bit deep bitmap.

thanks,

ken

Code:
void CGraphicsMillCppSampleDlg::OnBnClickedBrightnesscontrastbutton()
{
	// Get access to the BitmapViewer control and retrieve an IBitmap, associated with
	// this control.
	CComQIPtr<IBitmapViewer, &IID_IBitmapViewer> piBitmapViewer;
	piBitmapViewer = GetDlgItem(IDC_BITMAPVIEWER)->GetControlUnknown();

	CComPtr<IBitmap> piBitmap;
	HRESULT hr = piBitmapViewer->get_Bitmap(&piBitmap);
	if (FAILED(hr))
		return DisplayErrorMessage(hr);

	// Create a brightness/contrast dialog. To be able to show a preview,
	// we pass the bitmap into this dialog.
	CBrightnessContrastDialog brightnessDlg;
	brightnessDlg.InitPreview(piBitmap);

	// Open the dialog and if necessary, apply brightness/contrast adjustment.
	INT_PTR res = brightnessDlg.DoModal();
	if (res == IDOK)
	{
		// To change brightness/contrast, we should get IColorAdjustment interface
		// and call BrightnessContrast method. 
		CComPtr<IColorAdjustment> piColorAdjustment;
		hr = piBitmap->get_ColorAdjustment(&piColorAdjustment);
		if (FAILED(hr))
			DisplayErrorMessage(hr);

		// Get brightness and contrast modifiers from the control. 
		hr = piColorAdjustment->BrightnessContrast(brightnessDlg.GetBrightnessAmount(), brightnessDlg.GetContrastAmount(), NULL);
		if (FAILED(hr))
			DisplayErrorMessage(hr);


	// arbitrarily reduce it to 1 bit (in this case no dithering)
		CComPtr<IBitmap> piBitmap;
		hr = piBitmapViewer->get_Bitmap(&piBitmap);
		CComPtr<IBitmapData> piBitmapData;
		hr = piBitmap->get_Data(&piBitmapData);
		if (FAILED(hr))
			DisplayErrorMessage(hr);
		CComPtr<IBitmap> piTempBitmap;
		piTempBitmap = NULL;

		// The following line causes the SaveToFile operation to cause an exception, but the Save is actually done
		hr = piBitmapData->ConvertTo1bppIndexed(DitheringTypeNone,1,OrderedDitheringTypeSpiral,2,&piTempBitmap);
		if (FAILED(hr))
			DisplayErrorMessage(hr);

		// NOTE: if you uncomment the following lines and convert to 8 bit grayscale it works fine!
		//hr = piBitmapData->ConvertTo8bppGrayscale(0,0,&piTempBitmap);
		//if (FAILED(hr))
		//	DisplayErrorMessage(hr);
	}
}

Edited by user Monday, December 24, 2007 4:17:43 PM(UTC)  | Reason: Not specified

kenberkun  
#7 Posted : Saturday, January 8, 2005 6:41:00 AM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

Thanks!

Ken

Andrew  
#8 Posted : Sunday, January 9, 2005 4:44:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Hi Ken,

I still cannot reproduce the problem. Could you submit case with the image you are testing?

Edited by user Friday, May 23, 2008 3:41:44 PM(UTC)  | Reason: Not specified

kenberkun  
#9 Posted : Sunday, January 16, 2005 11:05:00 AM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

Please forgive another beginner's question. Right now I am doing everything with pointers, like this:

Code:
CComPtr<IBitmap> piBitmap;
hr = piBitmapViewer->get_Bitmap(&piBitmap);

I would like to do things as follows (per an example you provided elsewhere):

Code:
GraphicsMill.BitmapClass bmp = new GraphicsMill.BitmapClass();
bmp.LoadFromFile(@"d:\[test files]\pictures\andrew.jpg");

But I don't have a clue about how to get started. How do I initialize things and make these classes known? Sorry for the very basic question.

Yours,

Ken

Edited by user Monday, December 24, 2007 4:18:24 PM(UTC)  | Reason: Not specified

Andrew  
#10 Posted : Sunday, January 16, 2005 4:52:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Hi Ken,

I think you should read more about ATL smart pointer concepts in MSDN...

To create a coclass which implements some interface, the CComPtr class implements CoCreateInstance method. The code should be looking like this:

Code:
CComPtr<IBitmap> piBitmap;
HRESULT hr = piBitmap.CoCreateInstance(CLSID_Bitmap);
if (FAILED(hr))
{
  // ... most likely means that GraphicsMill20.dll is not registered.
}

hr = piBitmap->LoadFromFile(CComBSTR(_T("d:\\test.jpg")));
// ...

In fact this mehtod wraps the CoCreateInstance Win32API function, which is also can be used (but the class method is more convenient).

Edited by user Monday, December 24, 2007 4:18:36 PM(UTC)  | Reason: Not specified

kenberkun  
#11 Posted : Monday, January 17, 2005 2:44:00 AM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

No, the smart pointers are working just fine, this works:

Code:
CComPtr<IBitmap> piBitmap;
HRESULT hr = piBitmap.CoCreateInstance(CLSID_Bitmap);
if (FAILED(hr))
{

  // ... most likely means that GraphicsMill20.dll is not registered.

}

hr = piBitmap->LoadFromFile(CComBSTR(_T("d:\\test.jpg")));

But I like the idea of coding like this, per other examples on your website, so I was wondering how to do it:

Code:
GraphicsMill.BitmapClass bmp = new GraphicsMill.BitmapClass(); 
bmp.LoadFromFile(@"d:\[test files]\pictures\andrew.jpg"); 

It appears you are working with the structures themselves, not pointers. This makes it earier to get to, say, the bitmapdata structure.

Thanks,

Ken

Edited by user Monday, December 24, 2007 4:19:00 PM(UTC)  | Reason: Not specified

Andrew  
#12 Posted : Monday, January 17, 2005 3:01:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
This code sample is not written on C++, but on C#... :) So this syntax cannot be used in C++.
kenberkun  
#13 Posted : Tuesday, January 18, 2005 2:28:00 AM(UTC)
kenberkun

Rank: Member

Groups: Member
Joined: 1/5/2005(UTC)
Posts: 20

Ah, sorry for the misunderstanding.

Ken

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.