SRCCOPY removes transparancy from BITBLITTED IMAGE - bitblt

BitBlt(meteor.main, 0, 0, meteor.img_width, meteor.img_height, meteor.image, meteor.mask_x, meteor.mask_y, SRCAND);
BitBlt(meteor.main, 0, 0, meteor.img_width, meteor.img_height, meteor.image, meteor.img_x, meteor.img_y, SRCPAINT);
BitBlt(buffer, 0, 0, 800, 600, meteor.main, 0, 0, SRCCOPY);
I know the first two bitblts make the transparancy, but the third removes it! What am I doing wrong here?

SrcCopy just flat copies everything from source to destination. Whatever was in your destination will now contain everything form your source.
The way I usually do this is
1) BitBlt(dest.hdc, dest.x, dest.y, width, height, srcMask.hdc, srcMask.x, srcMask.y, MergePaint)
This will essentially cut a hole, in the form of the mask, into the destination.
2) BitBlt(dest.hdc, dest.x, dest.y, width, height, src.hdc, src.x, src.y, SrcAnd)
This basically overlays the source on top of the destination.
If your source contains more image than what you want to overlay, you may first want to cut out all that is around your source first (before step 2.) using SrcPaint like this:
1b) BitBlt(src.hdc, src.x, src.y, width, height, srcMask.hdc, srcMask.x, srcMask.y, SrcPaint)

Related

Filter out everything of a certain color using openCV

I have pictures of buildings I want to classify, and I want to get rid of the sky as I think it is messing with my classifier. I know that OpenCV has a function called inRange, that takes in the image and blacks out everything not in the range of the two color bounds that you provide. I was wondering if there was a function that literally did the opposite. Or another way I can accomplish what I want.
Thank you!
cv2.InRange creates a mask, which basically means it creates an image of the same size where the pixel values that are in the range are 255, and the values outside the range are 0.
https://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#void%20inRange(InputArray%20src,%20InputArray%20lowerb,%20InputArray%20upperb,%20OutputArray%20dst)
If you want to have the opposite of that you can take the output of cv2.inRange and perform a bitwise_not:
https://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#bitwise-not
If you want to then use that to black out the pixels in your original image you could do a bitwise_and:
https://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#bitwise-and
So I would do something like:
mask = cv2.inRange(img, (255, 0, 0), (100, 0, 0)) # modify your thresholds
inv_mask = cv2.bitwise_not(mask)
no_sky = cv2.bitwise_and(img, inv_mask)

How to import multiple images as one sprite in Createjs EaselJS?

I have to multiple images merged as one sprite image. These images are not part of some animation, it's just different static images.
I need to load them somehow in Createjs/EaselJS but I don't know the template of json for spritesheet data.
All search results points to how to make sprite animation, but I don't need animation, just static images by id.
Can anyone provide an example how to achieve this?
Here is an example for your json file:
{
"frames": [
[0, 0, 120, 200],
[140, 0, 350, 400]]
}
Every item in 'frames' describe one frame in your spite image. There are 4 values per each frame. First 2 stand for frame's position in the sprite. [0, 0] left-upper corner for frame #1 and [140, 0] for frame #2. Other 2 value describe frame size (120x200 and 350x400 in my case).
Load this json and your image into EaselJS and then instantiate as a Sprite. Like this:
var ssheet = new createjs.SpriteSheet(ss);
var sprite = new createjs.Sprite(ssheet);
Don't use play method as it's not animation in your case. Just call gotoAndStop(0) for the first frame and gotoAndStop(1) for the second frame.
Now add your sprite to the stage.

Fl_Scroll initial scroll values

I'm using FLTK for a project (the version distributed with Debian/sid 1.3.2-6+b1) and I'm having some trouble initializing Fl_Scroll's content scroll values.
I create a Fl_Double_Window and on the right side a vertical panel using Fl_Scroll, it is positioned at left x 600 and top y 24.
Then I set Fl_Scroll's type to Fl_Scroll::VERTICAL and place a Fl_Button inside, everything works fine.
The problem? Fl_Scroll initialize already scrolled with xposition() = 600 and yposition() = 24 (X and Y of the Fl_Scroll's constructor?? Is supposed to work so?), instead I want it to initialize with content scrolled at left and top 0, 0, so I tried scroll_to() in different places, before and after window's show(), on FL_SHOW of the subclassed Fl_Scroll (I didn't really need to subclass Fl_Scroll, just trying to get scroll_to() working), also on overridden draw() after
the parent draw(), even creating Fl_Scroll at 0, 0 then position() at 600, 24, but nothing.
The only way I got scroll_to() working is if I call it from an async event after the application initialize (FL_KEYUP).
Here's the overridden Fl_Double_Window window constructor:
group = new Fl_Group(0, 0, WIN_W, WIN_H);
{
menu = new Fl_Menu_Bar(0, 0, WIN_W, MENU_H);
menu->add("File/Quit", FL_CTRL+'q', cbMenuQuit_i);
glview = new CGLView(0, MENU_H, WIN_W-PROPS_W+1, WIN_H-MENU_H);
group->resizable(glview);
scroll = new CScroll(WIN_W-PROPS_W, MENU_H, PROPS_W-1, WIN_H-MENU_H);
scroll->type(Fl_Scroll::VERTICAL);
{
Fl_Pack *pack = new Fl_Pack(0, 0, PROPS_W-1, WIN_H-1);
{
btnAddLayer = new Fl_Button(0, 0, PROPS_W, 32, "##+ Add Layer");
btnAddLayer->callback(btnAddLayerCb_i, (void *)this);
}
pack->end();
}
scroll->end();
}
group->end();
end();
size_range(WIN_MIN_W, WIN_MIN_H); /* Make the window resizable */
show();
Never mind, got it, two altenative:
create Fl_Scroll at 0, 0 then position() it after scroll->end()
create Fl_Scroll at the wanted position then after scroll->end() use negative values scroll_to(-X, -Y)
In both cases is important that the widgets contained are already added (scroll_to() alter cotained widgets coords)
Isn't clear to me why X and Y of Fl_Scroll's constructor are used.

Expand wxStaticLine only horizontally

I have a wxWidget Application. I need to make certain changes to the layout of the application. One of them being adding horizontal lines between vertically stacked slider.
Here is the code I am using:
m_BrightContLine =new wxStaticLine(this,wxID_ANY,wxPoint(-10,10),wxSize(250,1),wxLI_HORIZONTAL,wxStaticLineNameStr);
gridSizer->Add(m_DummyText[16], 0, wxALL);
m_BCLineSizer = new wxBoxSizer(wxHORIZONTAL);
m_BCLineSizer->Add(m_BrightContLine, 1, wxALL|wxALIGN_LEFT|wxEXPAND);
gridSizer->Add(m_BCLineSizer, 0, wxALL|wxEXPAND);
the problem is that the static line expands both in length and in thickness.
How do I make sure that it expands only horizontally(in length).
Take out the wxEXPAND flag.
m_BCLineSizer->Add(m_BrightContLine, 1, wxALL|wxALIGN_LEFT);
If that doesn't work, try the wwxSHAPED flag
m_BCLineSizer->Add(m_BrightContLine, 1, wxALL|wxALIGN_LEFT|wxSHAPED);

Draw string in canvas

I'm having an hard time finding how to draw/print a String in a canvas, rotated 90º, NOT vertical letters. After some different approaches without success I was trying to follow one that would involve printing the Graphics object to an Image object. As the API is reduced it has been a difficult task.
So basically what I'm asking you guys is if you know how to draw a String rotated 90º in a Canvas or if you don't, how can I save the graphics object to an Image one so I can follow my "hint".
Thank you very much!
Guilherme
Finally, one last research in the web and here it is:
//The text that will be displayed
String s="java";
//Create the blank image, specifying its size
Image img=Image.createImage(50,50);
//Create an instance of the image's Graphics class and draw the string to it
Graphics gr=img.getGraphics();
gr.drawString(s, 0, 0, Graphics.TOP|Graphics.LEFT);
//Display the image, specifying the rotation value. For example, 90 degrees
g.drawRegion(img, 0, 0, 50, 50, Sprite.TRANS_ROT90, 0, 0, Graphics.TOP|Graphics.LEFT);
from: http://wiki.forum.nokia.com/index.php/How_to_display_rotated_text_in_Java_ME
Thank you!

Resources