wxWidgets 3.1.4 - Transparency Problem with XPM images - image

After upgrading to version 3.1.4 on Windows 10 (using VS 2017), I see that XPM images with transparency don't show correctly on wxRibbonButtonBar. As an example, the comparison of 3.1.3 and 3.1.4 is shown below:
The code adding image is briefly as follows:
auto ButtonBar_BoxandWhisker = new wxRibbonButtonBar(PanelBoxandWhisker);
ButtonBar_BoxandWhisker->AddButton(ID_PLOT_BOXWHISKER_HOR, "Horizontal", wxBitmap(plot_boxwhiskerchart_xpm), "hor");
I generate XPM images using GIMP. Part of the above-shown XPM image is:
static char * plot_boxwhiskerchart_xpm[] = {
"32 32 4 1",
" c None",
". c #000000",
"+ c #FF7F27",
"# c #880015",
". ",
". ",
Any ideas welcomed.

Related

Emoji support in imagick

I want to print the captions imported from facebook/instagram in an image and save it. I want to do this using imagick library with php as I am creating the base image using imagick. The normal text prints properly but the emojis that are imported do not get printed as emoji's. Can anyone suggest how emojis can be printed using imagick.
What I have tried:
$eachpageimg = new Imagick ();
$eachpageimg->setResolution ( 300 , 300 );
$eachpageimg->newImage (1050, 1260 , 'rgb(255,255,255)');
$eachpageimg->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$eachpageimg->setImageFormat ('jpeg');
$eachpageimg->setImageCompressionQuality(100);
$draw = new ImagickDraw();
$pixel = new ImagickPixel( 'rgb(255, 255, 255)' );
$pixel->setColorValue(Imagick::COLOR_ALPHA, .8);
$draw->setStrokeColor('rgb(0,0,0)');
$draw->setFillColor ('rgb(0,0,0)');
$draw->setFont ("ROBOTO-REGULAR");
$draw->setFontSize (70);
$xpos = 10;
$ypos = 200;
$eachpageimg->annotateImage($draw, $xpos, $ypos, 0, "Gshdh😚😎😑😚🤠");
$filename = 'saved.jpg';
// SAVE FINAL page image
file_put_contents ($filename, $eachpageimg);
The font you are using needs to have the emojis in them. This can be checked by just editing a word or web page with that font set.
However:
"Gshdh😚😎😑😚🤠"
Those look very much like a mucked up character set rather than emoji. I strongly suspect that you are saving some data in a character set that doesn't support emoji (i.e. most non-UTF) character sets.
Exactly where that has happened will need to be something you discover yourself.

Imagick: Issues reading file on Windows 64bit EasyPHP

I'm having a lot of difficulty working with PHP's Imagick class, it doesn't seem to want to read images regardless to the method I use.
Method 1
$handle = fopen('http://ima.gs/Placeholder-400x200.png', 'rb'); // Sample image
$img = new Imagick();
$img->readImageFile($handle);
$img->resizeImage(128, 128, 0, 0);
$img->writeImage(ROOT . DS . 'foo.png');
This gives me the Internal Error "Unable to read image from the filehandle"
Method 2 (Ideal Method)
$img = new Imagick(ROOT . DS . '00053141.jpg'); // Image does exist
$img->resizeImage(128, 128, 0, 0);
$img->writeImage(ROOT . DS . 'foo.jpg');
This gives me the Internal Error "no decode delegate for this image format `D:\Work\DittoCake\00053141.jpg' # error/constitute.c/ReadImage/550"
Configure List Results
You can see my delegates and configuration details here: http://cl.ly/image/1j2z1H072K41/Image%202014-10-22%20at%209.35.28%20AM.png
Command line convert results
convert 00053141.jpg -set colorspace RGB 00053141_rgb.jpg
This worked successfully and can confirm that the image mode was changed from CMKY to RGB when checking in Photoshop. (My last resort is to use shell_exec but I'd prefer not to)
I have a feeling this may be because I'm running it on Windows, my main goal in using this is just to convert any image from CMKY to RGB, resizing / changing image type is already covered in my application.

How to print image in TSC printer

I'm printing labels using a TSC ME240 printer.
The label design has a company logo, text part and a barcode.
The barcode and text are printed just fine but not the logo, which is a .bmp image stored in the printer's memory.
Everytime I print the labels, I get a pop up message "Could not open the File".
Here's part of my code:
openport("printerName");
setup("80 mm", "51 mm", "4", "15", "0", "3 mm", "0");
clearbuffer();
// LOGO
downloadpcx("logo-bmp.PCX", "logo-bmp.PCX");
sendcommand("PUTPCX 19,15,\"logo-bmp.PCX\"");
printlabel("1", "1");
closeport();
I also tried storing the image within the application but I still get the same message. I'm wondering if maybe I need to change the print speed? Is it possible that the printer couldn't print the image because the printer is printing too fast? But if the print speed is set too low, the sticker paper might burn.
Edit:
I configured the printer to a lower print speed but that didn't solve my problem.
And then I tried using their sample image and it printed just fine. My image is 5kb and their image is 6kb so I know that size doesn't have anything to do with it.
Any input on this matter will be highly appreciated. Running out of ideas here.
I changed from pcx to bmp. I also made the image 1kb small. Then I uploaded the new image to the printer using diagtool.
My code didn't change aside from removing the downloadpcx line and changing PUTPCX to PUTBMP.
openport("printerName");
setup("80 mm", "51 mm", "4", "15", "0", "3 mm", "0");
clearbuffer();
// LOGO
sendcommand("PUTBMP 19,15,\"logo-bmp.BMP\"");
printlabel("1", "1");
closeport();
And then it worked.
Your code should look like this:
PrintTSClabel.openport("PrinterName as in Windows"); //Driver name of the printer as in Windows
PrintTSClabel.setup("80", "38", "4", "15", "0", "3", "0"); //Setup the media size and sensor type info
PrintTSClabel.clearbuffer(); //Clear image buffer
PrintTSClabel.downloadpcx(#"C:\USERS\USER\DOWNLOADS\LOGO-BMP.PCX", "LOGO-BMP.PCX"); //Download PCX file into printer
PrintTSClabel.sendcommand("PUTPCX 10,30,\"LOGO-BMP.PCX\""); //Drawing PCX graphic
PrintTSClabel.sendcommand("PRINT 1"); //Print labels
PrintTSClabel.closeport(); //Close specified printer driver
This is because the image is not in BMP format supported by the TSC printer (1 bit or 256 bit).
Open the image in Paint as save as BMP with the format as either 1 bit or 256 bit.
I solved the issue with below code:
TSCActivity tscDll = new TSCActivity();
tscDll.openport("00:19:0E:A2:23:DE");
tscDll.setup(100, 60, 4, 15, 0, 3, 0);
tscDll.clearbuffer();
String filePath = Environment.getExternalStorageDirectory().toString() + "/Download";
String fileName = "PrintImg2.bmp";
File mFile = new File(filePath, fileName);
tscDll.sendpicture(200, 200, mFile.getAbsolutePath());
tscDll.printlabel(1, 1);
tscDll.closeport();
Install the sample app on your android phone, and connect the printer with your phone using Bluetooth.
'TSCActivity' is the activity class in 'tscsdk'.
'00:19:0E:A2:23:DE' replace it with your Printer's MAC address (You will get it on your Phone's BT setting, after pairing with the printer)
Here I kept the image in Download folder of the Phone (adb push path_of_img/PrintImg2.bmp /mnt/sdcard/Download).
Image size depends on the resolution of the image, you can change setup()'s 1st two arguments(width, height......) to get the maximum size possible.
I had the same problem, below code solved the Issue.
mydll = cdll.LoadLibrary('k:\Work\SCANNER\Printer\TSCLIB_V0201_x64\TSCLIB.dll')
print 'Start Printing.'
mydll.openport("TSC TA300")
mydll.setup("32","25","2","10","0","0","0")
mydll.clearbuffer()
# LABEL TEMPLATE
mydll.sendcommand("SIZE 50.8 mm,25.4 mm")
mydll.sendcommand('GAP 3 mm,0 mm')
mydll.sendcommand('DIRECTION 0')
mydll.sendcommand('CLS')
# Draw Label Image
mydll.sendcommand('BOX 12,12,584.4,282,4,19.2')
mydll.sendcommand("QRCODE 417.6,160,H,4,A,0,\"ABCabc123\"")
mydll.sendcommand("TEXT 48,56,\"2\",0,1,1,\"I'm Testing\"")
# Print
mydll.sendcommand('PRINT 1,1')
mydll.closeport()
print 'Finished Printing.'

XNA 4.0 InvalidOperationException was unhandeled

I am using this tutorial to learn a little XNA, and i keep running into problems. I've had to convert alot of the code, since it seems the tutorial do not use XNA 4.0.
But lets cut to the chase!
float aXPosition = (float)(-mCarWidth / 2 + mCarPosition.X + aMove * Math.Cos(mCarRotation));
float aYPosition = (float)(-mCarHeight / 2 + mCarPosition.Y + aMove * Math.Sin(mCarRotation));
Texture2D aCollisionCheck = CreateCollisionTexture(aXPosition, aYPosition);
//Bruke GetData til å fylle en array med fargen på pixlene ved collisons texturen
int aPixels = mCarWidth * mCarHeight;
Color[] myColors = new Color[aPixels];
aCollisionCheck.GetData<Color>(0, new Rectangle((int)(aCollisionCheck.Width / 2 - mCarWidth / 2),
(int)(aCollisionCheck.Height / 2 - mCarHeight / 2), mCarWidth, mCarHeight), myColors, 0, aPixels);
The error i get when i try to debug the code says: InvalidOperationException was unhandeled, The render Target must not be set on the device when it is used as a texture.
I have no clue what to do.
This basically means exactly what it says.
You have to unset the render target from the device by calling GraphicsDevice.SetRenderTarget(null) (or setting it to a different render target). Because you can't use it as both a source texture and a destination buffer at the same time.
Keep in mind that, in this version of XNA, there is no ResolveRenderTarget. Render targets simply are textures.
Note that the tutorial that you are using is pretty terrible. Reading back from a render target like this is extremely slow. Especially seeing as the operations that it is using the render target for (selecting pixels in a transformed region) could easily be done efficiently on the CPU. Consider using this better, official example.

Text wrapping with dot (graphviz)

I used the code below to create a graphic using dot (graphviz).
digraph
{
node [color=Blue,shape=box]
1.1 [label="Frequency of t exceeds upper threshold"]
2.1 [label="t has d-mutant tiles"]
2.2 [label="Valid"]
3.1 [label="Frequency of t exceeds lower threshold"]
3.2 [label="Frequency of t exceeds lower threshold"]
4.1 [label="Insufficient evidence"]
4.2 [label="Valid"]
4.3 [label="t has only one d-mutant that exceeds lower threshold"]
4.4 [label="Are there any d-mutant tiles with significantly higher frequencies?"]
5.1 [label="Insufficient evidence"]
node [color=Green] 5.2 [label="Correct t to t'"] node [color=Blue]
5.3 [label="t has a d-mutant tile t' that is closer than all other d-mutant tiles and for which a corrected base has a higher quality score"]
5.4 [label="Valid"]
6.1 [label="Insufficient evidence"]
6.2 [label="t' is unique"]
7.1 [label="Insufficient evidence"]
node [color=Green] 7.2 [label="Correct t to t'"] node [color=Blue]
1.1 -> 2.1 [label="no"]
1.1 -> 2.2 [label="yes"]
2.1 -> 3.1 [label="no"]
2.1 -> 3.2 [label="yes"]
3.1 -> 4.1 [label="no"]
3.1 -> 4.2 [label="yes"]
3.2 -> 4.3 [label="no"]
3.2 -> 4.4 [label="yes"]
4.3 -> 5.1 [label="no"]
4.3 -> 5.2 [label="yes"]
4.4 -> 5.3 [label="no"]
4.4 -> 5.4 [label="yes"]
5.3 -> 6.1 [label="no"]
5.3 -> 6.2 [label="yes"]
6.2 -> 7.1 [label="no"]
6.2 -> 7.2 [label="yes"]
}
As you can see, some of the boxes in the graphic have a lot of text in the label. I can insert \n characters to make sure the boxes aren't too wide, but I'm wondering if there is a way I can set the width of the boxes and then have the box labels do a hard wrap. Is this possible?
graphviz doesn't support automatic line breaks. You have to put the \n in manually.
you can set a width and a height to a node and define it as fixedsized - this will
limit the size of the node and draw only as much text as fits into the node
Although graphviz does not support text wrapping by itself,
dot2tex (latex+graphviz) does.
The dot2texi latex package gives an all-in-one solution,
with (from the users point of view) a single call to a single tool to build the graph.
A short example:
\documentclass{standalone}
\usepackage{dot2texi}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\begin{dot2tex}[dot]
digraph G {
d2toptions ="--autosize"
node [lblstyle="text width=10em,align=center"]
a [texlbl="This text will be automatically wrapped, for example at a fixed width."]
b [texlbl="Manual linebreaks from past century can be avoided!"]
a -> b
}
\end{dot2tex}
\end{document}
This can be compiled invoking for example: pdflatex --shell-escape myFile.tex, the text will be automatically wrapped at the prescribed fixed width.
As a side note, this tool seems a handy workaround for graphviz' limited typesetting control of the nodes contents.
The OP wrote a whole Perl script to achieve this. I found it in his blog: Text wrapping with dot (graphviz).
⚠ Note
This only works if the labels are in the format node [ label=”node label” ]. If the nodes are declared directly (e.g. ”node label”) then it doesn’t work
Perl script:
#!/usr/bin/perl
use strict;
my $usage = "setdotlabelwidth [char-width] < [dotfile]";
my $width = shift() or die("Usage: $usage $!");
while(<STDIN>)
{
if(m/label="(.*?)"/)
{
my $labeltext = $1;
my #words = split(/ /, $labeltext);
my #newtext = ();
my $newline = "";
foreach my $word(#words)
{
if( length($newline) > 0 and
length($newline) + length($word) > $width )
{
push(#newtext, $newline);
$newline = "";
}
$newline .= " " if( length($newline) > 0 );
$newline .= $word;
}
push(#newtext, $newline) if( length($newline) > 0 );
my $newlabel = join("\\n", #newtext);
s/label=".*?"/label="$newlabel"/;
}
print;
}
Save this program as setdotlabelwidth, then simply pipe the output into GraphViz. If for example you want to set the width to 35 characters, then the command is:
./setdotlabelwidth 35 < tile-error-correction.dot | dot -Tpng -o tile-error-correction.png
Before:
After:

Resources