Ejemplo n.º 1
0
/**
Test loading from a buffer attached to a memory stream
*/
void testLoadMemIO(const char *lpszPathName) {
	struct stat buf;
	int result;

	// get data associated with lpszPathName
	result = stat(lpszPathName, &buf);
	if(result == 0) {
		// allocate a memory buffer and load temporary data
		BYTE *mem_buffer = (BYTE*)malloc(buf.st_size * sizeof(BYTE));
		if(mem_buffer) {
			FILE *stream = fopen(lpszPathName, "rb");
			if(stream) {
				fread(mem_buffer, sizeof(BYTE), buf.st_size, stream);
				fclose(stream);

				// attach the binary data to a memory stream
				fipMemoryIO memIO(mem_buffer, buf.st_size);

				// get the file type
				FREE_IMAGE_FORMAT fif = memIO.getFileType();

				// load an image from the memory stream
				FIBITMAP *check = memIO.read(fif, PNG_DEFAULT);

				// save as a regular file
				FreeImage_Save(FIF_PNG, check, "blob.png", PNG_DEFAULT);
				
				// close the stream (memIO is destroyed)
			}

			// user is responsible for freeing the data
			free(mem_buffer);
		}
	}
}
/*
 * this method is not currently being used, but it may be useful in the future...
 */
status_t
DefaultCatalog::ReadFromAttribute(const entry_ref &appOrAddOnRef)
{
	BNode node;
	status_t res = node.SetTo(&appOrAddOnRef);
	if (res != B_OK)
		return B_ENTRY_NOT_FOUND;

	attr_info attrInfo;
	res = node.GetAttrInfo(BLocaleRoster::kEmbeddedCatAttr, &attrInfo);
	if (res != B_OK)
		return B_NAME_NOT_FOUND;
	if (attrInfo.type != B_MESSAGE_TYPE)
		return B_BAD_TYPE;

	size_t size = attrInfo.size;
	auto_ptr<char> buf(new(std::nothrow) char [size]);
	if (buf.get() == NULL)
		return B_NO_MEMORY;
	res = node.ReadAttr(BLocaleRoster::kEmbeddedCatAttr, B_MESSAGE_TYPE, 0,
		buf.get(), size);
	if (res < (ssize_t)size)
		return res < B_OK ? res : B_BAD_DATA;

	BMemoryIO memIO(buf.get(), size);
	res = Unflatten(&memIO);

	return res;
}
status_t
DefaultCatalog::ReadFromFile(const char *path)
{
	if (!path)
		path = fPath.String();

	BFile catalogFile;
	status_t res = catalogFile.SetTo(path, B_READ_ONLY);
	if (res != B_OK)
		return B_ENTRY_NOT_FOUND;

	fPath = path;

	off_t sz = 0;
	res = catalogFile.GetSize(&sz);
	if (res != B_OK) {
		return res;
	}

	auto_ptr<char> buf(new(std::nothrow) char [sz]);
	if (buf.get() == NULL)
		return B_NO_MEMORY;
	res = catalogFile.Read(buf.get(), sz);
	if (res < B_OK)
		return res;
	if (res < sz)
		return res;
	BMemoryIO memIO(buf.get(), sz);
	res = Unflatten(&memIO);

	if (res == B_OK) {
		// some information living in member variables needs to be copied
		// to attributes. Although these attributes should have been written
		// when creating the catalog, we make sure that they exist there:
		UpdateAttributes(catalogFile);
	}

	return res;
}
status_t
DefaultCatalog::ReadFromResource(const entry_ref &appOrAddOnRef)
{
	BFile file;
	status_t res = file.SetTo(&appOrAddOnRef, B_READ_ONLY);
	if (res != B_OK)
		return B_ENTRY_NOT_FOUND;

	BResources rsrc;
	res = rsrc.SetTo(&file);
	if (res != B_OK)
		return res;

	size_t sz;
	const void *buf = rsrc.LoadResource('CADA', fLanguageName, &sz);
	if (!buf)
		return B_NAME_NOT_FOUND;

	BMemoryIO memIO(buf, sz);
	res = Unflatten(&memIO);

	return res;
}
Ejemplo n.º 5
0
void CAboutPage::OnPaintAward(void)
{
	CClientDC dcClient(this);

	fipMemoryIO memIO(reinterpret_cast<BYTE*>(m_resSoftpediaAward.GetData()), m_resSoftpediaAward.GetSize());
	fipWinImage imageSoftpedia;
	imageSoftpedia.loadFromMemory(memIO);
	
	RECT rcVersion = { 0 };
	m_textVersion.GetWindowRect(&rcVersion);
	ScreenToClient(&rcVersion);
	
	RECT rcImage = { 0 };
	GetClientRect(&rcImage);
	rcImage.right -= rcVersion.left - 4;
	rcImage.left = rcImage.right - imageSoftpedia.getWidth();
	rcImage.top = rcVersion.top - 4;
	rcImage.bottom = rcImage.top + imageSoftpedia.getHeight();
	
	COLORREF cr3DFace = ::GetSysColor(COLOR_3DFACE);
	RGBQUAD rgbqBack = { GetBValue(cr3DFace), GetGValue(cr3DFace), GetRValue(cr3DFace), 0 };
	
	imageSoftpedia.drawEx(dcClient, rcImage, FALSE, &rgbqBack);
}