Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
BabyPinky
Posts: 29
Registered: ‎04-03-2013
My Device: BB10

Re: Copy current screen image to file

Hi StevenKader,

 

I followed your post to develop on a new cascade project for copy current screen image to file.

I built it with my simulator, and it doesn't work.

And I found the error display on the console.

 

make[2]: *** [o-g/ScreenCapture] Error 1
make[1]: *** [debug] Error 2
make: *** [Simulator-Debug] Error 2

I think there is something that I missed out.

Do you have a full sample project for it ?

 

Thanks

Please use plain text.
Developer
StevenKader
Posts: 644
Registered: ‎02-03-2010
My Device: Z10 LE

Re: Copy current screen image to file

I don't have a sample...but could make one.  Before I do that I'd like to help you understand where the error is in your project.  Can you post more of the console output that shows what the error is?


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
Please use plain text.
Developer
BabyPinky
Posts: 29
Registered: ‎04-03-2013
My Device: BB10

Re: Copy current screen image to file

[ Edited ]

Hi StevenKader,

 

Appreciate on your help.

 

Below here is the console result.

 

**** Build of configuration Simulator-Debug for project ScreenCapture ****

make -j8 Simulator-Debug
make -C .//translations -f Makefile update
make[1]: Entering directory `E:/MobileApps/ndk-10.1.0-workspace/ScreenCapture/translations'
C:/bbndk/host_10_0_10_534/win32/x86/usr/bin/lupdate ScreenCapture.pro
Updating 'ScreenCapture.ts'...
    Found 1 source text(s) (0 new and 1 already existing)
make[1]: Leaving directory `E:/MobileApps/ndk-10.1.0-workspace/ScreenCapture/translations'
make -C .//translations -f Makefile release
make[1]: Entering directory `E:/MobileApps/ndk-10.1.0-workspace/ScreenCapture/translations'
C:/bbndk/host_10_0_10_534/win32/x86/usr/bin/lrelease ScreenCapture.pro
The directory name is invalid.
Updating 'E:/MobileApps/ndk-10.1.0-workspace/ScreenCapture/translations/ScreenCapture.qm'...
    Generated 0 translation(s) (0 finished and 0 unfinished)
    Ignored 1 untranslated source text(s)
make[1]: Leaving directory `E:/MobileApps/ndk-10.1.0-workspace/ScreenCapture/translations'
make -C ./x86 -f Makefile debug
make[1]: Entering directory `E:/MobileApps/ndk-10.1.0-workspace/ScreenCapture/x86'
c:/bbndk/host_10_0_10_534/win32/x86/usr/bin/qmake.exe -spec c:/bbndk/target_10_0_10_261/qnx6/usr/share/qt4/mkspecs/blackberry-x86-qcc CONFIG+=debug_and_release CONFIG+=simulator -o Makefile ../ScreenCapture.pro
make[1]: Leaving directory `E:/MobileApps/ndk-10.1.0-workspace/ScreenCapture/x86'
make[1]: Entering directory `E:/MobileApps/ndk-10.1.0-workspace/ScreenCapture/x86'
make -f Makefile.Debug
make[2]: Entering directory `E:/MobileApps/ndk-10.1.0-workspace/ScreenCapture/x86'
qcc -Vgcc_ntox86 -lang-c++ -Wl,-rpath-link,C:/bbndk/target_10_0_10_261/qnx6/x86/lib -Wl,-rpath-link,C:/bbndk/target_10_0_10_261/qnx6/x86/usr/lib -Wl,-rpath-link,C:/bbndk/target_10_0_10_261/qnx6/x86/usr/lib/qt4/lib -o o-g/ScreenCapture o-g/.obj/GrabScreen.o o-g/.obj/main.o    -LC:/bbndk/target_10_0_10_261/qnx6/x86/lib -LC:/bbndk/target_10_0_10_261/qnx6/x86/usr/lib -LC:/bbndk/target_10_0_10_261/qnx6/x86/usr/lib/qt4/lib -LC:/bbndk/target_10_0_10_261/qnx6//usr/lib/qt4/lib -lbbcascades -lQtDeclarative -lQtScript -lQtSvg -lQtSql -lsqlite3 -lz -lQtXmlPatterns -lQtGui -lQtNetwork -lsocket -lQtCore -lm -lbps
Could not find qmake configuration directoryCould not find qmake configuration fileUsing OS scope before setting MAKEFILE_GENERATORC:\bbndk\host_10_0_10_534\win32\x86\usr\bin\ntox86-ld: o-g/.obj/GrabScreen.o: undefined reference to symbol 'screen_read_window'
make[2]: Leaving directory `E:/MobileApps/ndk-10.1.0-workspace/ScreenCapture/x86'
make[1]: Leaving directory `E:/MobileApps/ndk-10.1.0-workspace/ScreenCapture/x86'
C:\bbndk\host_10_0_10_534\win32\x86\usr\bin\ntox86-ld: note: 'screen_read_window' is defined in DSO C:/bbndk/target_10_0_10_261/qnx6/x86/usr/lib/libscreen.so.1 so try adding it to the linker command line
C:/bbndk/target_10_0_10_261/qnx6/x86/usr/lib/libscreen.so.1: could not read symbols: Invalid operation
cc: C:/bbndk/host_10_0_10_534/win32/x86/usr/bin/ntox86-ld caught signal 1
make[2]: *** [o-g/ScreenCapture] Error 1
make[1]: *** [debug] Error 2
make: *** [Simulator-Debug] Error 2

**** Build Finished ****

 

And I attached my test ScreenCapture project on this link :-

 

http://www.yousendit.com/download/UVJna0ZaY3lrUm5OUjhUQw

 

You can download and do a simple test.

I think the same console result will be displayed.

And I really have no idea where will the mistake be..

 

Thanks in advance for your suggestion.

 

Please use plain text.
Developer
StevenKader
Posts: 644
Registered: ‎02-03-2010
My Device: Z10 LE

Re: Copy current screen image to file

These lines near the end give the clue :

 

C:\bbndk\host_10_0_10_534\win32\x86\usr\bin\ntox86-ld: note: 'screen_read_window' is defined in DSO C:/bbndk/target_10_0_10_261/qnx6/x86/usr/lib/libscreen.so.1 so try adding it to the linker command line
C:/bbndk/target_10_0_10_261/qnx6/x86/usr/lib/libscreen.so.1: could not read symbols: Invalid operation

 

Once you start using more advanced features there are two things you need to look out for :

 

1) You need add additional libraries yourself, it is not automatic (I wish it was).  In this case you need to add this line to the ScreenCapture.pro file  just inder the CONFIG line:

 

LIBS +=  -lscreen

 

2) The other thing is you need to permissions to allow you to save to the shared folders. 

 

http://developer.blackberry.com/cascades/documentation/getting_started/tools/app_permissions.html

 

In this case you need Shared Folders to be ticked.

 

Make those two changes and the app will work fine.  

 

 

 

 

 


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
Please use plain text.
Developer
BabyPinky
Posts: 29
Registered: ‎04-03-2013
My Device: BB10

Re: Copy current screen image to file

Hi StevenKader,

 

Thank you so much for your suggestion.

It's bugs free now, the LIBS is so important for the custom components.

 

Just curious on whether will it work on simulator?

or it needs a physical device to test on this screen capture app?

As I only  have the simulator, I don't know how it looks like when testing it out.

When I clicked on the button, there is nothing come out or is it because of I haven't apply filepicker for it?

 

Thank you.

 

 

 

 

Please use plain text.
Developer
StevenKader
Posts: 644
Registered: ‎02-03-2010
My Device: Z10 LE

Re: Copy current screen image to file

When you click on the button the picture is stored in the Photos directory.  Take a look a the photos from the Photo app (use the 10.1 simulator)

 

 


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
Please use plain text.
Developer
BabyPinky
Posts: 29
Registered: ‎04-03-2013
My Device: BB10

Re: Copy current screen image to file

Hi StevenKader,

 

Thanks for your reply.

 

It doesn't work, I see nothing from my photo folder from simulator 10.1.

 

Am I missing something? :smileyfrustrated:

 

Below here are my ScreenCapture codes :-

 

main.cpp

 

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>

#include <QLocale>
#include <QTranslator>
#include "GrabScreen.h"

// include JS Debugger / CS Profiler enabler
// this feature is enabled by default in the debug build only

using namespace bb::cascades;

Q_DECL_EXPORT int main(int argc, char **argv)
{

	qmlRegisterType<GrabScreen>("capture.screen", 1, 0, "GrabScreen");

	// this is where the server is started etc
	Application app(argc, argv);

	// localization support
	QTranslator translator;
	QString locale_string = QLocale().name();
	QString filename = QString( "ScreenCapture_%1" ).arg( locale_string );
	if (translator.load(filename, "app/native/qm")) {
		app.installTranslator( &translator );
	}

	GrabScreen* grabScreen = new GrabScreen(&app);

	QmlDocument *qml = QmlDocument::create("asset:///main.qml");//.parent(this);

	qml->setContextProperty("_captureScreen",grabScreen);

	// create root object for the UI
	AbstractPane *root = qml->createRootObject<AbstractPane>();

	// set created root object as a scene
	Application::instance()->setScene(root);

	// we complete the transaction started in the app constructor and start the client event loop here
	return Application::exec();
	// when loop is exited the Application deletes the scene which deletes all its children (per qt rules for children)
}

 GrabScreen.cpp

#include <bb/cascades/Application>
#include <bb/cascades/Window>
#include "GrabScreen.h"
#include <QByteArray>
#include <screen/screen.h>
#include <QtCore/QObject>


GrabScreen::GrabScreen(QObject* parent)
//GrabScreen::GrabScreen(bb::cascades::Application *app)
: QObject(parent){
	// TODO Auto-generated constructor stub

}

void GrabScreen::write_bitmap_header(int nbytes, QByteArray& ba, const int size[])
	{
		char header[54];

		/* Set standard bitmap header */
		header[0] = 'B';
		header[1] = 'M';
		header[2] = nbytes & 0xff;
		header[3] = (nbytes >> 8) & 0xff;
		header[4] = (nbytes >> 16) & 0xff;
		header[5] = (nbytes >> 24) & 0xff;
		header[6] = 0;
		header[7] = 0;
		header[8] = 0;
		header[9] = 0;
		header[10] = 54;
		header[11] = 0;
		header[12] = 0;
		header[13] = 0;
		header[14] = 40;
		header[15] = 0;
		header[16] = 0;
		header[17] = 0;
		header[18] = size[0] & 0xff;
		header[19] = (size[0] >> 8) & 0xff;
		header[20] = (size[0] >> 16) & 0xff;
		header[21] = (size[0] >> 24) & 0xff;
		header[22] = -size[1] & 0xff;
		header[23] = (-size[1] >> 8) & 0xff;
		header[24] = (-size[1] >> 16) & 0xff;
		header[25] = (-size[1] >> 24) & 0xff;
		header[26] = 1;
		header[27] = 0;
		header[28] = 32;
		header[29] = 0;
		header[30] = 0;
		header[31] = 0;
		header[32] = 0;
		header[33] = 0;
		header[34] = 0; /* image size*/
		header[35] = 0;
		header[36] = 0;
		header[37] = 0;
		header[38] = 0x9;
		header[39] = 0x88;
		header[40] = 0;
		header[41] = 0;
		header[42] = 0x9l;
		header[43] = 0x88;
		header[44] = 0;
		header[45] = 0;
		header[46] = 0;
		header[47] = 0;
		header[48] = 0;
		header[49] = 0;
		header[50] = 0;
		header[51] = 0;
		header[52] = 0;
		header[53] = 0;

		ba.append(header, sizeof(header));
	}


	//void capture(int width, int height, screen_context_t context)
	void GrabScreen::captureFullScreen()
	{
		screen_pixmap_t screen_pix;
			screen_buffer_t screenshot_buf;
			char *screenshot_ptr = NULL;
			int screenshot_stride = 0;
			screen_context_t context;
			screen_create_context(&context, 0);
			int usage, format;
			int size[2];
			screen_create_pixmap(&screen_pix, context);
			usage = SCREEN_USAGE_READ | SCREEN_USAGE_NATIVE;
			screen_set_pixmap_property_iv(screen_pix, SCREEN_PROPERTY_USAGE, &usage);

			format = SCREEN_FORMAT_RGBA8888;
			screen_set_pixmap_property_iv(screen_pix, SCREEN_PROPERTY_FORMAT, &format);

			int width = 720 ;
			int height = 1280;
			size[0] = width;
			size[1] = height;
			screen_set_pixmap_property_iv(screen_pix, SCREEN_PROPERTY_BUFFER_SIZE, size);

			screen_create_pixmap_buffer(screen_pix);
			screen_get_pixmap_property_pv(screen_pix, SCREEN_PROPERTY_RENDER_BUFFERS,
			                              (void**)&screenshot_buf);
			screen_get_buffer_property_pv(screenshot_buf, SCREEN_PROPERTY_POINTER,
			                              (void**)&screenshot_ptr);
			screen_get_buffer_property_iv(screenshot_buf, SCREEN_PROPERTY_STRIDE,
 			                              &screenshot_stride);



			screen_read_window(bb::cascades::Application::instance()->mainWindow()->handle(), screenshot_buf, 0, NULL ,0);

			QByteArray array;

			int nbytes = size[0] * size[1] * 4;
			write_bitmap_header(nbytes, array, size);

			for (int i = 0; i < size[1]; i++)
			{
				array.append(screenshot_ptr + i * screenshot_stride, size[0] * 4);
			}

			QImage image = QImage::fromData(array, "BMP");
			QFile outFile("shared/photos/temp1.jpeg");
			outFile.open(QIODevice::WriteOnly);
			image.save(&outFile, "JPEG");

			screen_destroy_pixmap(screen_pix);
	}

 GrabScreen.h

#ifndef GRABSCREEN_H_
#define GRABSCREEN_H_

#include <QObject>

namespace bb { namespace cascades { class Application; }}

class GrabScreen: public QObject {
	//Q_OBJECT
public:
	GrabScreen(QObject* parent = 0);
	//GrabScreen(bb::cascades::Application *app);
	//virtual ~GrabScreen();
	//Q_INVOKABLE
	void write_bitmap_header(int nbytes, QByteArray& ba, const int size[]);
//public Q_SLOTS:
	void captureFullScreen();

};


#endif /* GRABSCREEN_H_ */

 main.qml

import bb.cascades 1.0
import capture.screen 1.0

// creates one page with a label
Page {
    Container {
        layout: DockLayout {}
        Label {
            text: qsTr("Hello World")
            textStyle.base: SystemDefaults.TextStyles.BigText
            verticalAlignment: VerticalAlignment.Center
            horizontalAlignment: HorizontalAlignment.Center
        }
        Button {
            onClicked: {
                _captureScreen.capture();
            }
        
        }
    }
}

ScreenCapture.pro

APP_NAME = ScreenCapture

LIBS +=  -lscreen

CONFIG += qt warn_on cascades10

include(config.pri)

device {
    CONFIG(debug, debug|release) {
        # Device-Debug custom configuration
    }

    CONFIG(release, debug|release) {
        # Device-Release custom configuration
    }
}

simulator {
    CONFIG(debug, debug|release) {
        # Simulator-Debug custom configuration
    }
}

 

 

Do I declare it correctly?

 

 

 

Please use plain text.
Developer
StevenKader
Posts: 644
Registered: ‎02-03-2010
My Device: Z10 LE

Re: Copy current screen image to file

Did you do this part also ?

 


2) The other thing is you need to permissions to allow you to save to the shared folders. 

 

http://developer.blackberry.com/cascades/documentation/getting_started/tools/app_permissions.html


Steven Kader at JaredCo
   Follow me on Twitter    |     Mipixi.com :  Web App for Photo Sharing
Please use plain text.
Developer
BabyPinky
Posts: 29
Registered: ‎04-03-2013
My Device: BB10

Re: Copy current screen image to file

Hi StevenKader,

 

Yes, I did all the suggestion that given by you.

My button just cannot be triggered when i clicked it.

Really scratch head question..=\

 

Please use plain text.
Developer
steve8820
Posts: 78
Registered: ‎04-04-2013
My Device: BB10 Dev Alpha Simulator

Re: Copy current screen image to file

Hi Steven,

I followed your code and when i debug, the screen_read_window line returns me this error. "invalid use of incomplete type 'struct bb::cascades::Window'". Just wondering am i doing anything wrong? Please advice.

Thank you.
Regards,

Steve Chan
Please use plain text.