Need an EMFPlus sample file - aspose

Currently all the EMF files which I generated through Aspose engine are in EMF dual mode.
It would be very nice if someone could enlighten me on how to generate an EMFPlus file through Aspose. If you can provide me a sample EMFPlus file, which is not in Dual mode, that will be great.
Or, please let me know from where I can download it from internet.

I believe you have posted a similar question in Aspose.Words Support forum therefore I will address your concerns from Aspose.Words prespective first. Please note, Aspose.Words APIs allow you to render the documents in EmfOnly, EmfPlus & EmfPlusWithFallback formats. Please check the following piece of code that converts the input document to EmfPlus format using Aspose.Words for .NET API.
var doc = new Aspose.Words.Document("D:/sample.docx");
var saveOptions = new Aspose.Words.Saving.ImageSaveOptions(Aspose.Words.SaveFormat.Emf);
saveOptions.MetafileRenderingOptions.EmfPlusDualRenderingMode = Aspose.Words.Saving.EmfPlusDualRenderingMode.EmfPlusWithFallback;
doc.Save("D:/output.emf", saveOptions);
If you intend to convert existing EmfPlusDual images to EmfPlus, you can use the GDI+ routines for this purpose. Please check the following method that accepts the image data in the form of System.IO.Stream and converts it to EmfPlus before saving it back on disc.
void ReSaveEmfToEmfPlus(Stream srcStream, String destPath)
{
Bitmap dummyBitmap = null;
Graphics dummyGfx = null;
IntPtr hdc = IntPtr.Zero;
System.Drawing.Imaging.Metafile metafile = null;
try
{
dummyBitmap = new Bitmap(1, 1);
dummyGfx = Graphics.FromImage(dummyBitmap);
hdc = dummyGfx.GetHdc();
Image srcImage = Image.FromStream(srcStream);
Rectangle rect = new Rectangle(0, 0, srcImage.Width, srcImage.Height);
metafile = new System.Drawing.Imaging.Metafile(destPath, hdc, rect, System.Drawing.Imaging.MetafileFrameUnit.Pixel, EmfType.EmfPlusOnly);
Graphics graphic = Graphics.FromImage(metafile);
graphic.DrawImage(srcImage, rect);
srcImage.Dispose();
graphic.Dispose();
}
finally
{
if (metafile != null)
{
metafile.Dispose();
}
if (hdc != IntPtr.Zero)
{
dummyGfx.ReleaseHdc(hdc);
}
if (dummyGfx != null)
{
dummyGfx.Dispose();
}
if (dummyBitmap != null)
{
dummyBitmap.Dispose();
}
}
}
If you are looking for EmfPlus samples, you can search them over the internet with appropriate keywords, and hopefully you will be able to find the desired files.
I work with Aspose as Developer Evangelist.

Related

Aspose.Barcode cannot read DecodeType.Code128 barcode

The aspose.barcode reader is unable to read the barcode of type DecodeType.Code128
Workflow Steps
1>Using Aspose.Barcode we have created a barcode using DecodeType.Code128 and put on PDF page ( our clients use this page as separator sheet)
2>Our client then insert this barcode page between several physical documents and scanned them all, which creates big single PDF
3>Our splitting process then, loop through all pages and check if any page is barcode page, and splits the big PDF into individual small PDF
Issue is some times the scanned quality of the barcode is not that great, and in such case ASPOSE.Barcode unable to read the barcode.
I have attached couple of barcode PDF with low scanned quality, and aspose is not able to read these barcodes. I have tried different combinations of RecognitionMode and ManualHints options without any luck
Below is my code to identity barcode page
using (var fs = new FileStream(file, FileMode.Open))
{
var pdfDocument = new Document(fs);
foreach (Page page in pdfDocument.Pages)
{
var isSeparator = splitter.IsSeparator(page);
Assert.IsTrue(isSeparator);
}
}
public bool IsSeparator(Page page)
{
if (page.Resources.Images != null && page.Resources.Images.Count >= 1)
{
var img = page.Resources.Images[1];
using (MemoryStream barcodeImage = new MemoryStream())
{
img.Save(barcodeImage, ImageFormat.Jpeg);
barcodeImage.Seek(0L, SeekOrigin.Begin);
using (BarCodeReader barcodeReader = new BarCodeReader(barcodeImage, _barcodeDecodeType))
{
barcodeReader.RecognitionMode = RecognitionMode.MaxQuality;
while (barcodeReader.Read())
{
var barcodeText = barcodeReader.GetCodeText();
if (barcodeText.ToLower() == "eof")
{
return true;
}
}
}
}
}
return false;
}
Unable to reproduce the issue at my end. I used the following sample code snippet to recognize the barcode along with latest version of the API. It is always recommended to use the latest version of the API as it contains new features and improvements.
CODE:
Aspose.Pdf.License licensePdf = new Aspose.Pdf.License();
licensePdf.SetLicense(#"Aspose.Total.lic");
// bind the pdf document
Aspose.Pdf.Facades.PdfExtractor pdfExtractor = new Aspose.Pdf.Facades.PdfExtractor();
pdfExtractor.BindPdf(#"173483_2.pdf");
// extract the images
pdfExtractor.ExtractImage();
// save images to stream in a loop
while (pdfExtractor.HasNextImage())
{
// save image to stream
System.IO.MemoryStream imageStream = new System.IO.MemoryStream();
pdfExtractor.GetNextImage(imageStream);
imageStream.Position = 0;
Aspose.BarCode.BarCodeRecognition.BarCodeReader barcodeReader =
new Aspose.BarCode.BarCodeRecognition.BarCodeReader(imageStream);
while (barcodeReader.Read())
{
Console.WriteLine("Codetext found: " + barcodeReader.GetCodeText() + ", Symbology: " + barcodeReader.GetCodeType().ToString());
}
// close the reader
barcodeReader.Close();
}
Further to update you that the same query has been post on Aspose.BarCode support forum. You may please visit the link for details.
I work as developer evangelist at Aspose.

How do I switch an image in "XAML for Windows Embedded (Compact 2013)"

I have a project for Windows CE that uses XAML for Windows Embedded (Compact 2013) (also known as "Silverlight for Windows Embedded") for the GUI.
I defined an image in xaml and now I want to switch this image in the c++ code behind part.
How do I do this?
I found this solution:
m_pBatteryStateImageis the image, defined in Xaml.
The URIs for the images can be found in the auto generated file PROJECTNAMEGenerated.rc2
void MainPage::SetBatteryState(BatteryStateFlags batteryState)
{
BSTR src = GetImageSourceUri(batteryState);
SetImage(src);
}
void MainPage::SetImage(BSTR src)
{
IXRApplication* application;
App::GetApplication(&application);
//Check which uri is currently used:
BSTR originalSrc;
IXRImageSource* iSource;
m_pBatteryStateImage->GetSource(&iSource);
IXRBitmapImagePtr bmpSrc = (IXRBitmapImagePtr)iSource;
bmpSrc->GetUriSource(&originalSrc);
//Set new image if source uri is different
if (wcscmp(originalSrc,src)!=0)
{
IXRBitmapImagePtr bitmapImage;
application->CreateObject(IID_IXRBitmapImage, &bitmapImage);
bitmapImage->SetUriSource(src);
m_pBatteryStateImage->SetSource(bitmapImage);
}
}
BSTR MainPage::GetImageSourceUri(BatteryStateFlags batteryState)
{
BSTR src;
//see PROJECTNAMEGenerated.rc2 - the numbers will change if images are added (they are alphabetically sorted).
//TODO make it robust against changes
if(batteryState & BatteryChargerError)
src = TEXT("#105");
else if(batteryState & BatteryHigh)
src = TEXT("#106");
else if(batteryState & BatteryLow)
src = TEXT("#109");
else
//Show error if nothing else matches (Should not happen)
src = TEXT("#105");
return src;
}

How create a DICOM image from byte (DCMTK)

I want to use the DCMTK 3.6.1 library in an existing project that can create DICOM image. I want to use this library because I want to make the compression of the DICOM images. In a new solution (Visual Studio 2013/C++) Following the example in the DCMTK official documentation, I have this code, that works properly.
using namespace std;
int main()
{
DJEncoderRegistration::registerCodecs();
DcmFileFormat fileformat;
/**** MONO FILE ******/
if (fileformat.loadFile("Files/test.dcm").good())
{
DcmDataset *dataset = fileformat.getDataset();
DcmItem *metaInfo = fileformat.getMetaInfo();
DJ_RPLossless params; // codec parameters, we use the defaults
// this causes the lossless JPEG version of the dataset
//to be created EXS_JPEGProcess14SV1
dataset->chooseRepresentation(EXS_JPEGProcess14SV1, &params);
// check if everything went well
if (dataset->canWriteXfer(EXS_JPEGProcess14SV1))
{
// force the meta-header UIDs to be re-generated when storing the file
// since the UIDs in the data set may have changed
delete metaInfo->remove(DCM_MediaStorageSOPClassUID);
delete metaInfo->remove(DCM_MediaStorageSOPInstanceUID);
metaInfo->putAndInsertString(DCM_ImplementationVersionName, "New Implementation Version Name");
//delete metaInfo->remove(DCM_ImplementationVersionName);
//dataset->remove(DCM_ImplementationVersionName);
// store in lossless JPEG format
fileformat.saveFile("Files/carrellata_esami_compresso.dcm", EXS_JPEGProcess14SV1);
}
}
DJEncoderRegistration::cleanup();
return 0;
}
Now I want to use the same code in an existing C++ application where
if (infoDicom.arrayImgDicom.GetSize() != 0) //Things of existing previous code
{
//I have added here the registration
DJEncoderRegistration::registerCodecs(); // register JPEG codecs
DcmFileFormat fileformat;
DcmDataset *dataset = fileformat.getDataset();
DJ_RPLossless params;
dataset->putAndInsertUint16(DCM_Rows, infoDicom.rows);
dataset->putAndInsertUint16(DCM_Columns, infoDicom.columns,);
dataset->putAndInsertUint16(DCM_BitsStored, infoDicom.m_bitstor);
dataset->putAndInsertUint16(DCM_HighBit, infoDicom.highbit);
dataset->putAndInsertUint16(DCM_PixelRepresentation, infoDicom.pixelrapresentation);
dataset->putAndInsertUint16(DCM_RescaleIntercept, infoDicom.rescaleintercept);
dataset->putAndInsertString(DCM_PhotometricInterpretation,"MONOCHROME2");
dataset->putAndInsertString(DCM_PixelSpacing, "0.086\\0.086");
dataset->putAndInsertString(DCM_ImagerPixelSpacing, "0.096\\0.096");
BYTE* pData = new BYTE[sizeBuffer];
LPBYTE pSorg;
for (int nf=0; nf<iNumberFrames; nf++)
{
//this contains all the PixelData and I put it into the dataset
pSorg = (BYTE*)infoDicom.arrayImgDicom.GetAt(nf);
dataset->putAndInsertUint8Array(DCM_PixelData, pSorg, sizeBuffer);
dataset->chooseRepresentation(EXS_JPEGProcess14SV1, &params);
//and I put it in my data set
//but this IF return false so che canWriteXfer fails...
if (dataset->canWriteXfer(EXS_JPEGProcess14SV1))
{
dataset->remove(DCM_MediaStorageSOPClassUID);
dataset->remove(DCM_MediaStorageSOPInstanceUID);
}
//the saveFile fails too, and the error is "Pixel
//rappresentation non found" but I have set the Pixel rep with
//dataset->putAndInsertUint16(DCM_PixelRepresentation, infoDicom.pixelrapresentation);
OFCondition status = fileformat.saveFile("test1.dcm", EXS_JPEGProcess14SV1);
DJEncoderRegistration::cleanup();
if (status.bad())
{
int error = 0; //only for test
}
thefile.Write(pSorg, sizeBuffer); //previous code
}
Actually I made test with image that have on one frame, so the for cycle is done only one time. I don't understand why if I choose dataset->chooseRepresentation(EXS_LittleEndianImplicit, &params); or dataset->chooseRepresentation(EXS_LittleEndianEXplicit, &params); works perfectly but not when I choose dataset->chooseRepresentation(EXS_JPEGProcess14SV1, &params);
If I use the same image in the first application, I can compress the image without problems...
EDIT: I think the main problem to solve is the status = dataset->chooseRepresentation(EXS_JPEGProcess14SV1, &rp_lossless) that return "Tag not found". How can I know wich tag is missed?
EDIT2: As suggest in the DCMTK forum I have added the tag about the Bits Allocated and now works for few images, but non for all. For some images I have again "Tag not found": how can I know wich one of tags is missing? As a rule it's better insert all the tags?
I solve the problem adding the tags DCM_BitsAllocated and DCM_PlanarConfiguration. This are the tags that are missed. I hope that is useful for someone.
At least you should call the function chooseRepresentation, after you have applied the data.
**dataset->putAndInsertUint8Array(DCM_PixelData, pSorg, sizeBuffer);**
dataset->chooseRepresentation(EXS_JPEGProcess14SV1, &params);

Convert Image to base64 in GDK

I am currently working on passing image as Base64 to a rest service. But I am not able to read the file. Here is my code:
if (requestCode == iPictureCode && resultCode == RESULT_OK) {
String picturePath = data.getStringExtra(Intents.EXTRA_PICTURE_FILE_PATH);
String image = processPictureWhenReady(picturePath);
}
`private String processPictureWhenReady(final String picturePath) {
final File pictureFile = new File(picturePath);
if (pictureFile.exists()) {
// The picture is ready; process it.
Bitmap bitmap = BitmapFactory.decodeFile(pictureFile.getAbsolutePath());
bitmap = CameraUtils.resizeImageToHalf(bitmap);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 85, stream);
String base64Image = Base64.encodeToString(stream.toByteArray(), Base64.DEFAULT);
return base64Image;
}
}`
it never enters the if block for 'pictureFile.exists()'
What could be the problem?
It looks like you adapted your code from the example in the developer docs, but you removed the else clause where a FileObserver is used to detect when the image is actually available. You need that part as well because the full-sized image may not be ready immediately when the activity returns.

How do I load and save an image from an SQL Server database using GDI+ and C++?

I need specifically to load a JPG image that was saved as a blob. GDI+ makes it very easy to retrieve images from files but not from databases...
Take a look at Image::Image(IStream *, BOOL). This takes a pointer to a COM object implementing the IStream interface. You can get one of these by allocating some global memory with GlobalAlloc and then calling CreateStreamOnHGlobal on the returned handle. It'll look something like this:
shared_ptr<Image> CreateImage(BYTE *blob, size_t blobSize)
{
HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE,blobSize);
BYTE *pImage = (BYTE*)::GlobalLock(hMem);
for (size_t iBlob = 0; iBlob < blobSize; ++iBlob)
pImage[iBlob] = blob[iBlob];
::GlobalUnlock(hMem);
CComPtr<IStream> spStream;
HRESULT hr = ::CreateStreamOnHGlobal(hMem,TRUE,&spStream);
shared_ptr<Image> image = new Image(spStream);
return image;
}
But with error checking and such (omitted here to make things clearer)
First fetch your blog into a byte array then use something like this:
public static Image CreateImage(byte[] pict)
{
System.Drawing.Image img = null;
using (System.IO.MemoryStream stream = new System.IO.MemoryStream(pict)) {
img = System.Drawing.Image.FromStream(stream);
}
return img;
}