Click here to Skip to main content
15,894,410 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Any other option Except memcpy Pin
CPallini29-Dec-10 22:13
mveCPallini29-Dec-10 22:13 
GeneralRe: Any other option Except memcpy Pin
Stevefigo229-Dec-10 23:13
Stevefigo229-Dec-10 23:13 
GeneralRe: Any other option Except memcpy Pin
CPallini30-Dec-10 3:11
mveCPallini30-Dec-10 3:11 
GeneralRe: Any other option Except memcpy Pin
002comp30-Dec-10 0:24
002comp30-Dec-10 0:24 
GeneralRe: Any other option Except memcpy Pin
jk chan30-Dec-10 0:57
jk chan30-Dec-10 0:57 
GeneralRe: Any other option Except memcpy Pin
002comp30-Dec-10 1:51
002comp30-Dec-10 1:51 
GeneralRe: Any other option Except memcpy Pin
jk chan30-Dec-10 19:45
jk chan30-Dec-10 19:45 
GeneralRe: Any other option Except memcpy Pin
002comp30-Dec-10 21:46
002comp30-Dec-10 21:46 
Hello
here is the full code in which I m applying transparency to images.
void applyTransparencyToLayers(CString& fullName)
{
        CString tempTiff = "c:\\sample.TIF";
	LPCSTR cstr=tempTiff;
	int maxlen=tempTiff.GetLength()*2; 
	WCHAR *str=new WCHAR[maxlen];
	MultiByteToWideChar(CP_ACP,0,cstr,-1,str,maxlen);
	
	Bitmap bmp(str);//Loaded Image

	//---Create32bppImageAndClearAlpha--//
	Bitmap loadedImage(bmp.GetWidth(),bmp.GetHeight(),PixelFormat32bppARGB);
	Rect rect(0, 0, loadedImage.GetWidth(),loadedImage.GetHeight());
    Graphics g(&loadedImage);

	ImageAttributes attr;
	Gdiplus::ColorMatrix cm =
	 {
	  1.0f, 0.0f, 0.0f, 0, 0,
	  0.0f, 1.0f, 0.0f, 0, 0,
	  0.0f, 0.0f, 1.0f, 0, 0,
	  0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
	  0.0f, 0.0f, 0.0f, 1.0f, 1.0f
	 }; 
	 attr.SetColorMatrix(&cm, Gdiplus::ColorMatrixFlagsDefault,Gdiplus::ColorAdjustTypeBitmap);
	 g.DrawImage(&loadedImage,rect, 0,0, loadedImage.GetWidth(), loadedImage.GetHeight(),UnitPixel,&attr);
	//--Alpha Clearing is Finish for loaded image--//

	 //--Creating Mask IMage--//
	 Bitmap originalMaskImage(bmp.GetWidth(),bmp.GetHeight(),PixelFormat32bppARGB);
	//Now Clearing Alpha for mask iMage
	Rect rect1(0, 0, originalMaskImage.GetWidth(),originalMaskImage.GetHeight());
    Graphics g1(&originalMaskImage);

	
	 g1.DrawImage(&originalMaskImage,rect1, 0,0, originalMaskImage.GetWidth(), originalMaskImage.GetHeight(),UnitPixel,&attr);

	 //Prepare Mask Image Data
	 BitmapData bmpData;
	 originalMaskImage.LockBits(rect1, ImageLockModeRead,          PixelFormat32bppARGB,&bmpData);
	 int dataLen = bmpData.Stride * bmpData.Height;
	 UINT* pixels = (UINT*)bmpData.Scan0;
	 BYTE* maskImageRGBData;
	 maskImageRGBData = new BYTE[dataLen];
	 memcpy(maskImageRGBData,pixels,dataLen);

	 byte greyLevel;
     bool opaque = true;
     int OpacityThreshold = 255;
     bool invertedMask = true;
	 for (int i = 0; i + 2 < dataLen; i += 4)
		{
			//convert to gray scale R:0.30 G=0.59 B 0.11
			greyLevel = (byte)(0.3 * maskImageRGBData[i + 2] + 0.59 * maskImageRGBData[i + 1] + 0.11 * maskImageRGBData[i]);

			if (opaque)
			{
				greyLevel = (greyLevel < OpacityThreshold) ? 0 : 255;
			}
			if (invertedMask)
			{
				greyLevel = (byte)(255 - (int)greyLevel);
			}

			maskImageRGBData[i] = greyLevel;
			maskImageRGBData[i + 1] = greyLevel;
			maskImageRGBData[i + 2] = greyLevel;

		}
	 memcpy(bmpData.Scan0,maskImageRGBData,dataLen);
	 originalMaskImage.UnlockBits(&bmpData);

	 //Mask Image Ends


	 //---Create Masked Image-------------//
	 //----------------------------------//
	Bitmap maskedImage(bmp.GetWidth(),bmp.GetHeight(),PixelFormat32bppARGB);
	//Now Clearing Alpha for mask iMage
	Rect rect2(0, 0, maskedImage.GetWidth(),maskedImage.GetHeight());
    Graphics g2(&maskedImage);

	g2.DrawImage(&maskedImage,rect2, 0,0, maskedImage.GetWidth(), maskedImage.GetHeight(),UnitPixel,&attr);
	
	//--Masked Image Data--//
	BitmapData bmpData1;
	maskedImage.LockBits(rect2, ImageLockModeRead, PixelFormat32bppARGB,&bmpData1);
	int dataLen1 = bmpData1.Stride * bmpData1.Height;
	byte* maskedImageRGBAData;
	maskedImageRGBAData = new byte[dataLen1];
	memcpy(maskedImageRGBAData,bmpData1.Scan0,dataLen1);


	//--OriginalMaskImage Data--//
	BitmapData bmpData2;
	originalMaskImage.LockBits(rect1, ImageLockModeRead, PixelFormat32bppARGB,&bmpData2);
	int dataLen2 = bmpData2.Stride * bmpData2.Height;
	byte* maskImageRGBAData;
	maskImageRGBAData = new byte[dataLen2];
	memcpy(maskImageRGBAData,bmpData2.Scan0,dataLen2);
	

	//copy the mask to the Alpha layer
    for (int j = 0; j + 2 < dataLen1; j += 4)
    {
        maskedImageRGBAData[j + 3] = maskImageRGBAData[j];

    }
	memcpy(bmpData1.Scan0,maskedImageRGBAData,dataLen1);
	maskedImage.UnlockBits(&bmpData1);
	originalMaskImage.UnlockBits(&bmpData2);

	//--Saving A File--//
	CLSID* pClsid = new CLSID;
	UINT num;
	UINT size;
	ImageCodecInfo* pImageCodecInfo=NULL;
	GetImageEncodersSize(&num,&size);
	pImageCodecInfo=(ImageCodecInfo*)(malloc(size));

	GetImageEncoders(num,size,pImageCodecInfo);

	for(UINT k=0;k<num;k++)
	{
		if(wcscmp(pImageCodecInfo[k].MimeType,L"image/tiff")==0)
		{
			*pClsid = pImageCodecInfo[k].Clsid;
			break;
		}
	}
	LPCSTR lName=fullName;
	int maxlen1=fullName.GetLength()*2; 
	WCHAR *str1=new WCHAR[maxlen1];
	MultiByteToWideChar(CP_ACP,0,lName,-1,str1,maxlen1);
	maskedImage.Save(str1,pClsid,NULL);
}


Regards
Yogesh
GeneralRe: Any other option Except memcpy Pin
jk chan31-Dec-10 0:50
jk chan31-Dec-10 0:50 
GeneralRe: Any other option Except memcpy Pin
002comp2-Jan-11 18:09
002comp2-Jan-11 18:09 
AnswerRe: Any other option Except memcpy Pin
trelliot31-Dec-10 0:48
trelliot31-Dec-10 0:48 
GeneralRe: Any other option Except memcpy Pin
002comp2-Jan-11 18:09
002comp2-Jan-11 18:09 
Questionlast data in dde Pin
zon_cpp28-Dec-10 20:34
zon_cpp28-Dec-10 20:34 
AnswerRe: last data in dde Pin
zon_cpp30-Dec-10 0:33
zon_cpp30-Dec-10 0:33 
QuestionCan we use XML in an RTX ( Real Time Operating System) for serialization Pin
pandit8428-Dec-10 20:26
pandit8428-Dec-10 20:26 
AnswerRe: Can we use XML in an RTX ( Real Time Operating System) for serialization Pin
Rajesh R Subramanian28-Dec-10 20:52
professionalRajesh R Subramanian28-Dec-10 20:52 
GeneralRe: Can we use XML in an RTX ( Real Time Operating System) for serialization Pin
pandit8428-Dec-10 21:25
pandit8428-Dec-10 21:25 
GeneralRe: Can we use XML in an RTX ( Real Time Operating System) for serialization Pin
jk chan28-Dec-10 21:42
jk chan28-Dec-10 21:42 
GeneralRe: Can we use XML in an RTX ( Real Time Operating System) for serialization Pin
pandit8428-Dec-10 22:07
pandit8428-Dec-10 22:07 
GeneralRe: Can we use XML in an RTX ( Real Time Operating System) for serialization Pin
jk chan28-Dec-10 22:20
jk chan28-Dec-10 22:20 
QuestionHow to partially disable the slider bar? Pin
DevelopmentNoob28-Dec-10 14:04
DevelopmentNoob28-Dec-10 14:04 
AnswerRe: How to partially disable the slider bar? Pin
shaozg110128-Dec-10 15:13
shaozg110128-Dec-10 15:13 
GeneralRe: How to partially disable the slider bar? Pin
DevelopmentNoob28-Dec-10 15:22
DevelopmentNoob28-Dec-10 15:22 
GeneralRe: How to partially disable the slider bar? Pin
jk chan28-Dec-10 17:20
jk chan28-Dec-10 17:20 
AnswerRe: How to partially disable the slider bar? Pin
Maximilien29-Dec-10 12:35
Maximilien29-Dec-10 12:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.