Image zooming using System.Drawing.Image - winforms

I took the following code for rotating an image from this link. To use this code in my test application, first I made a win32 C++ console application. Then I put the following program into my .cpp file.
I downloaded system.drawing.dll and put this dll in the folder where my application is made.
#include "stdafx.h"
#include "stdio.h"
#using <system.drawing.dll>
using namespace System;
using namespace System::Drawing;
int main()
{
Image^ image = Image::FromFile("SampleImage.jpg");
image->RotateFlip( RotateFlipType::Rotate90FlipNone );
image->Save("SampleImage_rotated.jpg");
return 0;
}
When I am building the application (on MSVC 2010 , Windows 7, 32 bit), its working as
intended and I am getting a new 90 degree rotated image.
I liked this code very much, since it is the shortest code I found for rotating an Image.
My questions are:
1- Can I use this same code inside an application which is written in C++ using
winform? Or do I have to do some kind of conversion ?
2- Using the same class i.e System.Drawing.Image how do I implement zooming or scaling of the image?
Many thanks for your precious time replying to my query.

Related

Saving glut draw as PNG/BMP/JPG

I'm creating a simple graphic editor by C/glut. So I just wonder how can I save my draws as PNG, BMP etc. I tried png.h but didn't work for me. I didn't get any errors but it did not save anything.
Any advice?
You can easily save bmp images from your app using libsoil.
http://lonesock.net/soil.html
For example, I used:
int save_result = SOIL_save_screenshot(
filename,
SOIL_SAVE_TYPE_BMP,
0,0,
width, height
);
If you are a debian user, there is a package named libsoil-dev. It should be available in Ubuntu too.

codenameone - how to draw an image with graphics

i need your help very much indeed.
I am new in codenameone and i am trying to implement a basic example like, drawing an image with a graphic. i only find some incomplete example and basic idea about drawing an image and i can not do what i want. I need an example from the scratch
When i run the compiler the image is not drawn. I do not know if i have to do something before with the img variable, if so would u please right the code
//this the class i call painel
static Image img;
public void paint(Graphcs g)
{
try
{
img.createImage("fundo.jpg");
g.drawImage(img, 10, 10);
}
cathc(IOException ex)
{
}
}
It seems catch is misspelled so I'm guessing that the code isn't copied and pasted.
You are opening an image incorrectly (wrong path and ideally you should have gotten it from the resource file) which should throw an exception. Doing it within the paint loop would be really slow to boot.
I suggest going over the developer guide in the website and one or more of the tutorials.

Unable to write data to the control of other from in VC++ winforms

I am trying to show an image on the pictureBox of the second Form from First Form.
But I am not able to see any output....
My Code of Form1.cpp is like this
#include "SecondForm.h"
SecondForm^ obj=gcnew SecondForm();
System::Drawing::Bitmap ^bmp = gcnew System::Drawing::Bitmap(grf->width,grf->height,grf->widthStep,System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)grf->imageData);
obj->pictureBox1->Image=obj->pictureBox1->Image->FromHbitmap(bmp->GetHbitmap());
I don't know what is the problem.....
Can anybody please help me sort our this problem...
Thanks in Advance
Have you tried this simple code -
obj.pictureBox1.Image = bmp; // [You may write the C++ equivalent]
Instead of this -
obj->pictureBox1->Image=obj->pictureBox1->Image->FromHbitmap(bmp->GetHbitmap());

TeleUSE window not resizing

We're porting an application from Tru64 to SLES11 and the part that I'm working on right now is a GUI written with TeleUSE.
The problem that I'm encountering is that one of my XmBulletinBoardDialogs has only half the size on LINUX compared to Tru64. I've tried to change the height in the pcd file and the generated c code looks alright but has no effect:
XtSetArg(args[n], XmNheight, 800); n++;
Any appearance changes that I've tried had no effect also..
Are there known problems or changes in functionality between the platforms or should I search for constraints from parent windows (then how would they look like?)? I'm new to TeleUSE so any hint on a probable source for the problem would help.
The size of the window was set by the input string "\n\n\n\n TEXT \n\n\n"
The problem was that apparently the parsing of the string is working differently with the function "XmStringCreateLtoR". I had to add spaces between the \n's for the line breaks to have an effect

Using Windows Forms and VC++ with Unmanaged Static Libraries

I am currently trying to write a UI for a Data Acquistion System in Visual Studio C++ 2010, and I am having a lot of trouble dealing with the interfacing of the third party libraries I am using and Windows Forms. The two libraries I am using are DAQX, a C library for a Data Acqustion System, and VITCam, a C++ library for a 1394 High Speed Camera. It's extremely frustrating trying to work with these libraries and any UI library that VS has to offer, as none of the function arguments ever get along.
DAQX uses windows types like WORD and DWORD, in normal C fashion, and when I'm writing a normal program, no UI involved, it works fine, but Windows Forms seems to hate anytime I want to make a simple DWORD Array inside the class.
VITCam is even worse. I can open the camera fine, but I am completely lost when it comes to trying to put the image on the screen somehow. I haven't uncovered an equivalanet, easy to follow way for putting it to the screen as to how the documentation puts it:
CDC* pDC=GetDC(); // obtain the device context for your window...
// move the image data
::SetDIBitsToDevice(pDC->m_hDC,0,0,
(int) (MyCam.GetDispBuf()->bmiHeader.biWidth),
(int) (MyCam.GetDispBuf()->bmiHeader.biHeight),
0,0,0,(WORD) (WORD) MyCam.GetDispBuf()->bmiHeader.biHeight,
MyCam.GetDispPixels(),MyCam.GetDispBuf(),
DIB_RGB_COLORS);
I can barely follow it as is. So, without doing to much blathering, How do most people work with static unmanaged libraries that were not developed with Windows Forms in mind? I've tried MFC as the VITCam documentations mentioned it, but it makes very little sense and isn't as intuitive as Windows Forms feels.
Edit:
This is the error message I get when trying to use a normal (at least to me) array.
Error 1 error C4368: cannot define 'buffer' as a member of managed 'WirelessHeadImpact::Form1': mixed types are not supported
And it points to this line:
private:
WORD buffer[BUFFSIZE*CHANCOUNT];
What I had before was this:
static array<WORD>^ _buffer;
And within a function I create the former array, pass it to the function, then return the latter after looping through and updating the array.
WORD buffer[BUFFSIZE*CHANCOUNT];
DWORD scansCollected = 0;
while (total_scans < SCANS) {
daqAdcTransferBufData(_handle, buffer, BUFFSIZE, DabtmWait, &scansCollected);
if (scansCollected > 0) {
for (WORD i=0;i<scansCollected;i++) {
_buffer[i] = buffer[i];
}
mixed type support is removed in Visual C++ 2005. If you want to associate a DWORD array to a managed class, use new (not gcnew) to allocate the array itself on the native heap and save the pointer of the array in the class.
by the way, you cannot pass addresses of objects on the managed heap to a native function without pinning the object, otherwise the GC is free to move the object at any time. If you want to pass a managed value to a native function, make sure your pass by value or the object is pinned.
It helps the readers if you post the actual error message you are getting, instead of having to guess out from your question.

Resources