yashsingh1/xdaforums huggingface dataset:
[Windows Mobile Development and Hacking General] evilc:
Thanks for that, it now seems to compile fine...

However, I just get a blank white screen when I run it.

Here is my code:

case WM_PAINT:
IImagingFactory* m_pImgFactory;
IImage* m_pImage;
HDC m_hDC;

int m_nWidth, m_nHeight, m_nPosX, m_nPosY;
m_nPosX = 0;
m_nPosY = 0;

hdc = BeginPaint(hWnd, &ps);
m_hDC = CreateCompatibleDC (hdc);

// init it
CoInitializeEx(NULL, COINIT_MULTITHREADED);

if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void **) & m_pImgFactory)))
{
}
else
{
//err(( TEXT("CoCreateInstance failed!") ));
return false;
}

// load it
if( SUCCEEDED(m_pImgFactory->CreateImageFromFile( TEXT("\\Storage Card\\shared\\test.png"), &m_pImage )) )
{
ImageInfo info = {0};

m_pImage->GetImageInfo( &info );

m_nWidth = info.Width;
m_nHeight = info.Height;

log(( TEXT("Image loaded <%d> <%d>"), m_nWidth, m_nHeight ));
}
else
{
//err(( TEXT("CreateImageFromFile failed!") ));
return false;
}

// draw it
RECT rc;

rc.left = m_nPosX;
rc.top = m_nPosY;
rc.right = m_nWidth + m_nPosX;
rc.bottom = m_nHeight + m_nPosY;

m_pImage->Draw( m_hDC, &rc, NULL );

// release
if( m_pImage ) m_pImage->Release();
if( m_pImgFactory ) m_pImgFactory->Release();
CoUninitialize();
break;

Attached is the PNG I am using.

I only get one warning when I compile:

1>LIBCMTD.lib(gshandler.obj) : warning LNK4099: PDB 'libbmtd.pdb' was not found with 'C:\Program Files\Microsoft Visual Studio 8\VC\ce\lib\ARMV4I\LIBCMTD.lib' or at 's:\Prj\test1\test1\Windows Mobile 5.0 Pocket PC SDK (ARMV4I)\Debug\libbmtd.pdb'; linking object as if no debug info

I set breakpoints and it is definately loading the image OK and getting as far as the drawing code, it's just that I see nothing but a blank white background...
[Windows Mobile Development and Hacking General] Houser:
You can delete this line: m_hDC = CreateCompatibleDC (hdc);

Change m_pImage->Draw( m_hDC, &rc, NULL ); to m_pImage->Draw( hdc, &rc, NULL );

You must call EndPaint() after m_pImage->Draw( hdc, &rc, NULL );

Houser
[Windows Mobile Development and Hacking General] evilc:
Thank You Houser, it all works now!!

Final code:

case WM_PAINT:
IImagingFactory* m_pImgFactory;
IImage* m_pImage;
HDC m_hDC;

int m_nWidth, m_nHeight, m_nPosX, m_nPosY;
m_nPosX = 0;
m_nPosY = 0;

hdc = BeginPaint(hWnd, &ps);

// init it
CoInitializeEx(NULL, COINIT_MULTITHREADED);

if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void **) & m_pImgFactory)))
{
}
else
{
//err(( TEXT("CoCreateInstance failed!") ));
return false;
}

// load it
if( SUCCEEDED(m_pImgFactory->CreateImageFromFile( TEXT("\\Storage Card\\shared\\test.png"), &m_pImage )) )
{
ImageInfo info = {0};

m_pImage->GetImageInfo( &info );

m_nWidth = info.Width;
m_nHeight = info.Height;

log(( TEXT("Image loaded <%d> <%d>"), m_nWidth, m_nHeight ));
}
else
{
//err(( TEXT("CreateImageFromFile failed!") ));
return false;
}

// draw it
RECT rc;

rc.left = m_nPosX;
rc.top = m_nPosY;
rc.right = m_nWidth + m_nPosX;
rc.bottom = m_nHeight + m_nPosY;

m_pImage->Draw( hdc, &rc, NULL );
EndPaint(hWnd, &ps);

// release
if( m_pImage ) m_pImage->Release();
if( m_pImgFactory ) m_pImgFactory->Release();
CoUninitialize();
break;
[Windows Mobile Development and Hacking General] Houser:
In your WM_PAINT block it would be the best to only

call m_pImage->Draw( m_hDC, &rc, NULL );

The image API initialization and image loading should only be done once

for performance reasons, because your WM_PAINT block is called every time

your window is repainted.

Call if( m_pImage ) m_pImage->Release();

if( m_pImgFactory ) m_pImgFactory->Release();

CoUninitialize();

when your app is closed.

Houser
[Windows Mobile Development and Hacking General] evilc:
You mean like this?

case WM_PAINT:
HDC m_hDC;

int m_nWidth, m_nHeight, m_nPosX, m_nPosY;
m_nPosX = 0;
m_nPosY = 0;

m_hDC = BeginPaint(hWnd, &ps);

// init it
CoInitializeEx(NULL, COINIT_MULTITHREADED);

if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void **) & m_pImgFactory)))
{
}
else
{
//err(( TEXT("CoCreateInstance failed!") ));
return false;
}

// load it
if( SUCCEEDED(m_pImgFactory->CreateImageFromFile( TEXT("\\Storage Card\\shared\\test.png"), &m_pImage )) )
{
ImageInfo info = {0};

m_pImage->GetImageInfo( &info );

m_nWidth = info.Width;
m_nHeight = info.Height;

log(( TEXT("Image loaded <%d> <%d>"), m_nWidth, m_nHeight ));
}
else
{
//err(( TEXT("CreateImageFromFile failed!") ));
return false;
}

// draw it
RECT rc;

rc.left = m_nPosX;
rc.top = m_nPosY;
rc.right = m_nWidth + m_nPosX;
rc.bottom = m_nHeight + m_nPosY;

m_pImage->Draw( m_hDC, &rc, NULL );
EndPaint(hWnd, &ps);

So I put this code before PostQuitMessage(0); in WM_DESTROY ?

I did this and it appears to work, but I had to move the declaration for m_pImage and m_pImgFactory to the top of the code else the line in WM_DESTROY moaned warning C4700: uninitialized local variable 'm_pImage' used. My limited knowledge thus far tells me that the m_ prefix is denoting scope and it shouldn't be a global, so I guess this is wrong.
[Windows Mobile Development and Hacking General] Houser:
I mean so:

case WM_PAINT:
HDC m_hDC;

int m_nWidth, m_nHeight, m_nPosX, m_nPosY;
m_nPosX = 0;
m_nPosY = 0;

m_hDC = BeginPaint(hWnd, &ps);

// draw it
RECT rc;

rc.left = m_nPosX;
rc.top = m_nPosY;
rc.right = m_nWidth + m_nPosX;
rc.bottom = m_nHeight + m_nPosY;

m_pImage->Draw( m_hDC, &rc, NULL );

EndPaint(hWnd, &ps);

Put the image loading and init in your main function when your app starts.

WM_DESTROY is a good place for the deinit aof imaging API.

Houser
[Windows Mobile Development and Hacking General] evilc:
Thanks for yet another speedy reply, this is really appreciated!

I think I have it now. I had to move the definitions for m_nWidth, m_nHeight, m_nPosX and m_nPosY out to where I put the loading and init code too, as it is needed for that.

So, I have now:

At the top of code in the includes section:

#include <imaging.h>
#include <initguid.h>
#include <imgguids.h>

At the start of WndProc:

PAINTSTRUCT ps;
int m_nWidth, m_nHeight, m_nPosX, m_nPosY;
m_nPosX = 0;
m_nPosY = 0;
IImagingFactory* m_pImgFactory;
IImage* m_pImage;
// init it
CoInitializeEx(NULL, COINIT_MULTITHREADED);

if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory, NULL, CLSCTX_INPROC_SERVER, IID_IImagingFactory, (void **) & m_pImgFactory)))
{
}
else
{
//err(( TEXT("CoCreateInstance failed!") ));
return false;
}

// load it
if( SUCCEEDED(m_pImgFactory->CreateImageFromFile( TEXT("\\Storage Card\\shared\\test.png"), &m_pImage )) )
{
ImageInfo info = {0};

m_pImage->GetImageInfo( &info );

m_nWidth = info.Width;
m_nHeight = info.Height;

log(( TEXT("Image loaded <%d> <%d>"), m_nWidth, m_nHeight ));
}
else
{
//err(( TEXT("CreateImageFromFile failed!") ));
return false;
}

Contents of WM_PAINT:

HDC m_hDC;
m_hDC = BeginPaint(hWnd, &ps);

// draw it
RECT rc;

rc.left = m_nPosX;
rc.top = m_nPosY;
rc.right = m_nWidth + m_nPosX;
rc.bottom = m_nHeight + m_nPosY;

m_pImage->Draw( m_hDC, &rc, NULL );
EndPaint(hWnd, &ps);
break;

Contents of WM_DESTROY:

if( m_pImage ) m_pImage->Release();
if( m_pImgFactory ) m_pImgFactory->Release();
CoUninitialize();
PostQuitMessage(0);
break;
[Windows Mobile Development and Hacking General] evilc:
I had been using VS2005 prior to now. I tried to go back and do this in eVC++ 4.0, as I wanted to use free tools if poss, but it refused to build:

AlphaPNGDemo.obj : error LNK2019: unresolved external symbol CoUninitialize referenced in function "long __cdecl WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YAJPAUHWND__@@IIJ@Z)
AlphaPNGDemo.obj : error LNK2019: unresolved external symbol CoCreateInstance referenced in function "long __cdecl WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YAJPAUHWND__@@IIJ@Z)
AlphaPNGDemo.obj : error LNK2019: unresolved external symbol CoInitializeEx referenced in function "long __cdecl WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YAJPAUHWND__@@IIJ@Z)
ARMV4Dbg/AlphaPNGDemo.exe : fatal error LNK1120: 3 unresolved externals

Is this code compatible with eVC++ 4.0 and the PPC 2003 SDK, or do I need the WM5 SDK ? (And so VS2005)
[Windows Mobile Development and Hacking General] Houser:
Add Ole32.lib to your linker settings.

Houser
[Windows Mobile Development and Hacking General] evilc:
That allows it to build, but when I run it, the app does nothing. I see "AlphaPNGDemo" in the status bar, as if the app is running, but it is still on the today screen - it doesn't even blank the screen out white or anything.

Obviously I neglected to sacrifice a chicken over the keyboard to appease the gods of MicroSoft.
[Windows Mobile Development and Hacking General] evilc:
Here is a .cpp file giving a full demonstration of Per-Pixel Alpha PNGs.

Plus it detects screen orientation and loads a different PNG for portrait or landscape, thought I would post it up for anyone else who should follow.

The code is very clear as to where I have modified the base file, so you can see which code is mine and which is just normal WM stuff.

Also included are the sample semitransparent PNGs, one 240x40 and one 320x40. Put them on your hard disk and set the "Shared Folder" for the emulator to that disk so that the PNGs appear as \Storage Card\shared\<file>.png on the device.

[Please note, code may be really crappy, it's literally my first cpp prog, and my book still hasn't arrived yet...]
[Windows Mobile Development and Hacking General] evilc:
I would still like to know how to do this without using IImageFactory.

I have some code using AlphaBlend that will display a PNG but transparency does not work.

I can display a PNG that has transparency, but only in constant alpha mode (AlphaFormat = 0) - as soon as I enable per-pixel alpha (AlphaFormat = AC_SRC_ALPHA) then I get nothing - no error, no pixels drawn, nada.

PAINTSTRUCT ps;
HDC hdc;
HBITMAP hBitmap;
BITMAP bm;
HGDIOBJ hOldSel;
BLENDFUNCTION bf;

bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 0xff;
bf.AlphaFormat = AC_SRC_ALPHA;	// Per-Pixel Source Alpha - NOTHING DISPLAYED
//bf.AlphaFormat = 0;	// Constant Alpha - WORKS

hdc = BeginPaint (hWnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
hBitmap = SHLoadImageFile(L"\\Storage Card\\shared\\bgport.png");
hOldSel = SelectObject(hdcMem, hBitmap);
GetObject (hBitmap, sizeof (bm), &bm);

AlphaBlend (hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, bm.bmWidth, bm.bmHeight, bf);

SelectObject (hdcMem, hOldSel);
DeleteDC(hdcMem);

EndPaint (hWnd, &ps);

If you use a 32-bit BMP with alpha (Sample one here - bottom image) in place of the PNG, per-pixel alpha works, so I gotta be close! Anyone know why it works with the BMP but not the PNG?
[Windows Mobile Development and Hacking General] thenext1:
Honestly I didn't know of 32 bit BMP's ..... in fact, IE7 doesn't event display it correctly.

Anyway, once you've got your linear 32-bit RGBA data, you can copy it to the raw bitmap, created with CreateDIBSection ...
[Windows Mobile Development and Hacking General] evilc:
So you are sying that the issue is that AlphaBlend only works on 32bit data and the PNGs are not 32 bit? I want to support all kinds of PNG - is there a library to convert the data structure internally?

I had never heard of 32bit RGBA BMPs too, but they do exist. It looks a little different to a PNG when you open it in photoshop - alpha represented by greyscale - but it does provide per-pixel alpha in a BMP.
[Windows Mobile Development and Hacking General] thenext1:
No, the problem is that SHLoadImageblahblah most probably doens't support alpha transparency in PNG's, and loads it without transparency.... then AlphaBlend fails for some reason.

To obtain the raw data for all PNG's you may use pnglib for windows ce, but it's not the easiest of things...
[Windows Mobile Development and Hacking General] robp:
AlphaBlend only supports constant alpha under Windows Mobile. Need to use another method for per pixel alpha.
[Windows Mobile Development and Hacking General] thenext1:
Not true. I'm actually using it in my programs and it works...

BLENDFUNCTION bf = { AC_SRC_OVER, 0, n, AC_SRC_ALPHA };

where N is the constant alpha to be added to the per-pixel alpha already defined in the image. To use only per-pixel alpha, n = 255 (as per MSDN).

If AlphaBlend fails for any reason, there must be a problem with the per-pixel alpha.
[Windows Mobile Development and Hacking General] evilc:
As I said, use the code snippet provided and the 32bit per-pixel alpha BMP, and it works, so your comment is proven to be false.

So much misinformation about this on the net :(
[Windows Mobile Development and Hacking General] evilc:
Just thought I would flag this as incorrect also. Trying to cut down on the misinformation.

Your help and comments are still appreciated though, so please don't take this as a flame!
[Windows Mobile Development and Hacking General] evilc:
Sounds like a good avenue to persue, thanks!

I know there are alternatives - IImageFactory, libpng, DirectX, etc, etc, but I just would rather not go down that route. I mean an alphablend is not really very complicated, it could probably be done in about 20 lines of code, so I fail to see why adding some big ole library is worth it. I am working on an open source rlToday-like app and would rather not bloat it with needless dependancies - I just need to be able to display alpha PNG buttons.
[Windows Mobile Development and Hacking General] robp:
Yeah I did a little research and it turns out that my problem was the the .NET Image class strips the alpha channel. AlphaBlend supports per-pixel alpha just fine.

Perhaps the problem is with whatever image loader you're using.
[Windows Mobile Development and Hacking General] evilc:
Yeppers. The finger is currently pointing in the direction of SHLoadImageFile
[Windows Mobile Development and Hacking General] tene:
Anyway, AlphaBlend is slow, as is IImage::Draw. I would advise you to look at DIBSection and do it yourself, you can even cut the alpha precision a bit, it's 16bpp anyway, and get a perf boost.
[Windows Mobile Development and Hacking General] evilc:
Well it's one thing I was maybe looking at doing at some point, but I would still need something that can load an alpha PNG into an HBITMAP anyway, so I may as well try and solve that hurdle first.
[Windows Mobile Development and Hacking General] tene:
why you would need a HBITMAP? Through DIBSection you would have to do the alpha blending yourself, but with decent speed.
[Windows Mobile Development and Hacking General] evilc:
Hmm, well my line of thinking was if I could load it as an HBITMAP, I could use alphablend for now, then when I had time, code a quicker version of alphablend.

I just want to get per-pixel alpha working one way or another for the moment so I can get the program reasonably functional, I will think about optimising later. I may even go back to IImageFactory for now.

I will take a look at DIBSection though
[Windows Mobile Development and Hacking General] shikhakhandelwal:
Hi I am using IImagingFactory to load a "png" image on a button. But my

CreateImageFromFile() function always fails i dont know what is the problem, my png image file is in the same folder in which my worksapce is.

strFileName = _T("\\exp.png");

if (SUCCEEDED(pImgFactory->CreateImageFromFile(strFileName, &pImage)) )

I am using EvC 4.0
[Windows Mobile Development and Hacking General] Houser:
Have you called:

CoInitializeEx(NULL, COINIT_MULTITHREADED);

and CoCreateInstance (...)

If your filename is "\\pngfile.png" then the CreateImageFromFile() function will

search the file in the root directory of your device.

Houser
[Windows Mobile Development and Hacking General] evilc:
In this code, exp.png should be stored in the ROOT directory of the PPC, not the same folder as the .exe (because you started with a backslash, which means "start from the root".) Try strFileName = _T("exp.png"), although I think the PPC doesn't have a concept of "current directory"...
[Windows Mobile Development and Hacking General] thenext1:
As I'm aware, Windows Mobile doesn't support the "current dir" location. You always have to provide a full path. You can get the full path by calling GetModuleFileName (IIRC) with your EXE handle (GetModuleHandle or similar), do a bit of string editing to extrapolate your exe path, and append your file name.

Other users' comments are also valid: that slash causes the function to search in the root directory.
[Windows Mobile Development and Hacking General] shikhakhandelwal:
Actually I am not working on device, I am working on emulator.

Through GteLastError i got error no 2 that means file not found.

I have tried placing my ".png" file in "d:" drive,

my project is in

D:\shikha\project\embeded vc\final_test

I have placed my png file in final_test folder,

tried in emulatorDbg folder

D:\shikha\project\embeded vc\final_test\emulatorDbg

but nothing seems to work.

Should I add it in my resource file (which appears in the left side of the project in resourceview)

I have tried with bmp file also to check, but GetLastError gives me 2 only (file not found).

plz help me...

Thanks...
[Windows Mobile Development and Hacking General] Houser:
This will not work. You must copy your png file to the emulator with the remote

file explorer. You cannot access a file on your desktop!

Houser
[Windows Mobile Development and Hacking General] evilc:
This is incorrect / ambiguous

In the emulator, set the "Shared dir" to a folder on your hard disk.

It then mounts that as "\Storage Card"

So, set the shared dir to

D:\shikha\project\embeded vc

and in the code, reference "D:\shikha\project\embeded vc\final_test\image.png" as "\\Storage Card\\final_test\\image.png"
[Windows Mobile Development and Hacking General] shikhakhandelwal:
My png file is not on the desktop.

The png file is in the folder where the workspace is, and the worspace is in D drive in a folder.

CoInitializeEx(NULL, COINIT_MULTITHREADED);

if (SUCCEEDED(CoCreateInstance (CLSID_ImagingFactory,

NULL,

CLSCTX_INPROC_SERVER,

IID_IImagingFactory,

(void **)&pImgFactory)))

{

ImageInfo imageInfo;

if (SUCCEEDED(pImgFactory->CreateImageFromFile(_T("exp.png"), &pImage)))

&& SUCCEEDED(pImage->GetImageInfo(&imageInfo)))

{

pImage->GetImageInfo(&imageInfo);

CWindowDC dc(0);

CDC dcBitmap;

dcBitmap.CreateCompatibleDC(&dc);

hResult = CreateCompatibleBitmap(dc.GetSafeHdc(), imageInfo.Width, imageInfo.Height);

if (hResult)

{

HGDIOBJ hOldBitmap = dcBitmap.SelectObject(hResult);

pImage->Draw(dcBitmap.GetSafeHdc(), CRect(0, 0, imageInfo.Width, imageInfo.Height), NULL);

dcBitmap.SelectObject(hOldBitmap);

}

pImage->Release();

} //end of CreateImageFromFile

else

{

MessageBox(NULL,_T("create image form file fails"),_T("Message box"),0);

}

pImgFactory->Release();

}

CoUninitialize();
[Windows Mobile Development and Hacking General] evilc:
by "Desktop" I think he meant "Desktop PC" not the Desktop folder (C:\Documents and Settings\<user name>\Desktop")

Irrelivant anyway, read post #42, I tell you exactly what you need to do.
[Windows Mobile Development and Hacking General] shikhakhandelwal:
ok ... but in my emulator (StandardSDK_500 emulator ) the FolderSharing (Emulator->FolderSharing) option is disable.
[Windows Mobile Development and Hacking General] evilc:
Try downloading the more recent emulators? Failing that, ask on MSDN why it is disabled...
[Windows Mobile Development and Hacking General] shikhakhandelwal:
Is there any other way for this...... to display a png image on button
[Windows Mobile Development and Hacking General] Houser:
No. The ImageFactory is the only API I know which can load png files.

Houser
[Windows Mobile Development and Hacking General] evilc:
CImage works too I think. Stefanux was using something else for XIAMultiTheme at one point, and IIRC thinks ImageFactory may have a memory leak.
[Windows Mobile Development and Hacking General] 1&only:
Here is my path from file to HBITMAP:

HBITMAP LoadTransparent( std::wstring const& name )
{
IImage* pImage;
IImagingFactory pImgFactory->CreateImageFromFile( name.c_str(), &pImage );
IBitmapImage* pBitmapImage = NULL;
pImgFactory->CreateBitmapFromImage( pImage, 0, 0, PixelFormat32bppPARGB, InterpolationHintNearestNeighbor , &pBitmapImage );
ImageInfo imageInfo;
pImage->GetImageInfo( &imageInfo );
RECT rect={ 0, 0, imageInfo.Width, imageInfo.Height };
BitmapData bitmapData;
pBitmapImage->LockBits(&rect, ImageLockModeRead, PixelFormat32bppPARGB, &bitmapData );
return CreateBitmap( imageInfo.Width, imageInfo.Height, 1, GetPixelFormatSize( imageInfo.PixelFormat ), bitmapData.Scan0 ) );
}

Do not forget to do error check:D
[Galaxy A3, A5, A7, A8, A9 Q&A, Help & Troubleshoot] RodrigoSkywalker:
Check here

https://www.sammobile.com/firmwares/galaxy-a8-/SM-A810S/SKC/download/A810SKSU2CRG3/226018/
[Galaxy A3, A5, A7, A8, A9 Q&A, Help & Troubleshoot] 007ace:
I have it now. So far so good.
[Xperia Tablet Z Q&A, Help & Troubleshooting] nowisek:
Hi

Xperia Tablet Z LTE version

Android version : 5.1.1 / kernel version : 3.4.0-perf-gbccb33a / Platform : 32bits / Build number : 10.7.A.0.228

I've still have stock firmware so I don't have option to boot to recovery mode. I've installed flashtool, bootloader is unlocked, device is rooted with kingrot. I've tried to install TWRP with offical app but without success I've tried to install TWRP manually, but also without success.

I don't know what do do next. I don't want do do something stupid and brick device. I want to install custom rom from here:

https://xdaforums.com/xperia-tablet-z/orig-development/rom-resurrection-remix-n-6-0-0-t3748092

I'm thinking about flashing kernel with TWRP but don't know where to find correct one, old topics are with old firmware . Any advice?

EDITED:

I wasn't understanding the instructions. Firmware kernel doesn't block the TWRP. If someone has similiar problem to mine with TWRP. Just follow steps from this topic:

https://xdaforums.com/xperia-tablet-z/help/guide-tutorial-sony-xperia-tablet-z-lte-t3392831

Solution works with different roms and versions of TWRP. TWRP for me booted after installation so there was no need to use buttons. I'm now happy user of android 8.1 on Xperia tablet Z. Thread can be deleted or closed now.