Нужна помощь: графика, звук

Программирование на Visual Basic, главный форум. Обсуждение тем программирования на VB 1—6.
Даже если вы плохо разбираетесь в VB и программировании вообще — тут вам помогут. В разумных пределах, конечно.
Правила форума
Темы, в которых будет сначала написано «что нужно сделать», а затем просьба «помогите», будут закрыты.
Читайте требования к создаваемым темам.
Keen
Обычный пользователь
Обычный пользователь
 
Сообщения: 83
Зарегистрирован: 25.04.2004 (Вс) 10:45
Откуда: Россия => Москва

Нужна помощь: графика, звук

Сообщение Keen » 18.07.2004 (Вс) 12:28

Вот у меня здесь накопилось несколько вопросов, на которые я бы хотел получить ответы:

1. Почему BitBlt не работает:
Код: Выделить всё
retval = BitBlt(Picture2.hdc, 0, 0, Picture1.hdc, 0, 0, 32, 32, SRCCOPY)

Хотя аналогичный код со StretchBlt работает нормально:
Код: Выделить всё
retval = StretchBlt(Picture2.hdc, 0, 0, 32, 32, Picture1.hdc, 0, 0, 32, 32, SRCCOPY)

В чем дело? Первый пример просто рисует черный квадрат 32х32. И почему если у получателя установить autoredraw=true ничего не видно и как этого избежать?!

2. Почему даже StrethcBlt не работает, если вместо picturebox'ов использовать объект stdpicture? Ведь я использую свойство handle...

3. Самый популярный вопрос - как сделать задний фон изображения прозрачым не используя маски (ибо это геморно и долго)?
Знает ли кто синтаксис FastBlt и TransparentBlt и примеры функций? А то в VB такого нет :(...

4. Из той же области популярных вопросов - многоканальный звук без дополнительных компонентов, библиотек и без DX (потому что если ипользуешь DX, то пишешь на нем все).
Можно ли на API и есть где примеры?

5. Документация по DX на русском. Смотрел здесь на vbstreets и понял, что некоторые авторы (не все, конечно) пишут статьи, до конца не понимая то, о чем они пишут :). Такое бывает...

Взываю к помощи добрых людей на форуме vbstreets :). Если у кого-нибудь есть хоть какие-нибудь материалы (желательно примеры), можете отправлять мне на почту: sharkady@mtu-net.ru или оставляйте прямо здесь, на форуме.
заранее премного благодарен.

GSerg
Шаман
Шаман
 
Сообщения: 14286
Зарегистрирован: 14.12.2002 (Сб) 5:25
Откуда: Магадан

Сообщение GSerg » 18.07.2004 (Вс) 12:55

1. Оно работает... Константу, на всякий случай, замени на vbSrcCopy.
2. IPistureDisp.Handle – это HBITMAP, а GDI работает с HDC.
3. Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Long
4. Юзай DX, юзай... Почему всё? Пишешь на нём только ту часть, которая нужна. DirectSound и хватит, остальное без DX.
5. Это не про меня, случаем? Как бы там ни было, ты думаешь, кто-нибудь сподобится перевести 15 метров текста? Это буду точно не я :)
Как только вы переберёте все варианты решения и не найдёте нужного, тут же обнаружится решение, простое и очевидное для всех, кроме вас

A.A.Z.
Член-корреспондент академии VBStreets
Член-корреспондент академии VBStreets
 
Сообщения: 3035
Зарегистрирован: 30.06.2003 (Пн) 13:38

Сообщение A.A.Z. » 18.07.2004 (Вс) 12:58

1)Избежать этого можно, поставив код с BitBlt в событие Paint нужного объекта (куда рисовать будешь)
3) FastBlt? Что-то не слышал о таком... :roll:
TransparentBlt:
Код: Выделить всё
Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
Есть еще MaskBlt
Код: Выделить всё
Declare Function MaskBlt Lib "gdi32.dll" (ByVal hdcDest As Long, ByVal nXDest As Long, ByVal nYDest As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal hbmMask As Long, ByVal xMask As Long, ByVal yMask As Long, ByVal dwRop As Long) As Long
PatBlt
Код: Выделить всё
Declare Function PatBlt Lib "gdi32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal dwRop As Long) As Long
PlgBlt
Код: Выделить всё
Declare Function PlgBlt Lib "gdi32.dll" (ByVal hdcDest As Long, lpPoint As POINTAPI, ByVal hdcSrc As Long, ByVal nXSrc As Long, ByVal nYSrc As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hbmMask As Long, ByVal xMask As Long, ByVal yMask As Long) As Long
ну и BitBlt и StretchBlt.

Keen
Обычный пользователь
Обычный пользователь
 
Сообщения: 83
Зарегистрирован: 25.04.2004 (Вс) 10:45
Откуда: Россия => Москва

Сообщение Keen » 18.07.2004 (Вс) 14:14

GSerg писал(а):1. Оно работает... Константу, на всякий случай, замени на vbSrcCopy.
2. IPistureDisp.Handle – это HBITMAP, а GDI работает с HDC.
3. Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Long
4. Юзай DX, юзай... Почему всё? Пишешь на нём только ту часть, которая нужна. DirectSound и хватит, остальное без DX.
5. Это не про меня, случаем? Как бы там ни было, ты думаешь, кто-нибудь сподобится перевести 15 метров текста? Это буду точно не я :)

Не держи на меня зла :P , просто когда пишешь статью и объясняешь каждую строчку, то ставь комментарий, а не обычный текст, а то очень проблемно копировать. Тем более код (если это твоя статья) что-то не работает. :roll: Именно эти две проблемы меня немножко вывели из себя. :cry:

Keen
Обычный пользователь
Обычный пользователь
 
Сообщения: 83
Зарегистрирован: 25.04.2004 (Вс) 10:45
Откуда: Россия => Москва

Сообщение Keen » 18.07.2004 (Вс) 14:18

И еще...

GSerg писал(а):2. IPistureDisp.Handle – это HBITMAP, а GDI работает с HDC.


Но VB говорит:
The Handle property is useful when you need to pass a handle to a graphic as part of a call to a function in a dynamic-link library (DLL) or the Windows API.


Или что-то не понимаю? Но все равно, как это сделать - рисовать изображение в памяти без конролов?! :cry: :cry:

GSerg
Шаман
Шаман
 
Сообщения: 14286
Зарегистрирован: 14.12.2002 (Сб) 5:25
Откуда: Магадан

Сообщение GSerg » 18.07.2004 (Вс) 15:13

VB прав...
CreateCompatibleDC
CreateCompatibleBitmap
SelectObject
...
DeleteDC
DeleteObject
Как только вы переберёте все варианты решения и не найдёте нужного, тут же обнаружится решение, простое и очевидное для всех, кроме вас

Keen
Обычный пользователь
Обычный пользователь
 
Сообщения: 83
Зарегистрирован: 25.04.2004 (Вс) 10:45
Откуда: Россия => Москва

Сообщение Keen » 18.07.2004 (Вс) 19:01

GSerg писал(а):VB прав...
CreateCompatibleDC
CreateCompatibleBitmap
SelectObject
...
DeleteDC
DeleteObject

Извини за мою нескромность, но объясни, что это? :oops: :?

Keen
Обычный пользователь
Обычный пользователь
 
Сообщения: 83
Зарегистрирован: 25.04.2004 (Вс) 10:45
Откуда: Россия => Москва

Сообщение Keen » 19.07.2004 (Пн) 18:53

Все уснули, что ли :(?
Кстати, (1) так и не работает - говорит что ошибка (retval=0).
2 A.Z.Z.: какая из этих функций - самая быстрая? И для чего нужны две последние (Pat/Plg -Blt)?
2 GSerg: так что ты написал :)?!

GM
programador
programador
 
Сообщения: 1427
Зарегистрирован: 24.06.2003 (Вт) 15:56
Откуда: 194.67.52.100

Сообщение GM » 20.07.2004 (Вт) 1:10

Так порядок у них другой:
Код: Выделить всё
retval = BitBlt(Picture2.hDC, 0, 0, Picture1.hDC <-Здесь должно быть Width, 0 <-А здесь Height, 0, 32, 32, SRCCOPY)

Вот так должно быть:
Код: Выделить всё
retval = BitBlt(Picture2.hDC, 0, 0, 32, 32, Picture1.hDC, 0, 0, vbSrcCopy)
الفيجوال بيسك الرابح

A.A.Z.
Член-корреспондент академии VBStreets
Член-корреспондент академии VBStreets
 
Сообщения: 3035
Зарегистрирован: 30.06.2003 (Пн) 13:38

Сообщение A.A.Z. » 20.07.2004 (Вт) 18:17

Я A.A.Z.... :roll:
Насчет Pat/PglBlt - RTFM!!! Ну MSDN на что???
MSDN писал(а):CDC::PatBlt
BOOL PatBlt( int x, int y, int nWidth, int nHeight, DWORDdwRop );

Return Value

Nonzero if the function is successful; otherwise 0.

Parameters

x

Specifies the logical x-coordinate of the upper-left corner of the rectangle that is to receive the pattern.

y

Specifies the logical y-coordinate of the upper-left corner of the rectangle that is to receive the pattern.

nWidth

Specifies the width (in logical units) of the rectangle that is to receive the pattern.

nHeight

Specifies the height (in logical units) of the rectangle that is to receive the pattern.

dwRop

Specifies the raster-operation code. Raster-operation codes (ROPs) define how GDI combines colors in output operations that involve a current brush, a possible source bitmap, and a destination bitmap. This parameter can be one of the following values:

PATCOPY Copies pattern to destination bitmap.


PATINVERT Combines destination bitmap with pattern using the Boolean XOR operator.


DSTINVERT Inverts the destination bitmap.


BLACKNESS Turns all output black.


WHITENESS Turns all output white.
Remarks

Creates a bit pattern on the device. The pattern is a combination of the selected brush and the pattern already on the device. The raster-operation code specified by dwRop defines how the patterns are to be combined. The raster operations listed for this function are a limited subset of the full 256 ternary raster-operation codes; in particular, a raster-operation code that refers to a source cannot be used.

Not all device contexts support the PatBlt function. To determine whether a device context supports PatBlt, call the GetDeviceCaps member function with the RASTERCAPS index and check the return value for the RC_BITBLT flag.



PlgBlt
The PlgBlt function performs a bit-block transfer of the bits of color data from the specified rectangle in the source device context to the specified parallelogram in the destination device context. If the given bitmask handle identifies a valid monochrome bitmap, the function uses this bitmap to mask the bits of color data from the source rectangle.

BOOL PlgBlt(
HDC hdcDest, // handle to destination device context
CONST POINT *lpPoint,
// vertices of destination parallelogram
HDC hdcSrc, // handle to source device context
int nXSrc, // x-coord. of upper-left corner of source rect.
int nYSrc, // y-coord. of upper-left corner of source rect.
int nWidth, // width of source rectangle
int nHeight, // height of source rectangle
HBITMAP hbmMask, // handle to bitmask
int xMask, // x-coord. of upper-left corner of bitmask rect.
int yMask // y-coord. of upper-left corner of bitmask rect.
);

Parameters
hdcDest
Handle to the destination device context.
lpPoint
Pointer to an array of three points in logical space that identify three corners of the destination parallelogram. The upper-left corner of the source rectangle is mapped to the first point in this array, the upper-right corner to the second point in this array, and the lower-left corner to the third point. The lower-right corner of the source rectangle is mapped to the implicit fourth point in the parallelogram.
hdcSrc
Handle to the source device context.
nXSrc
Specifies the x-coordinate, in logical units, of the upper-left corner of the source rectangle.
nYSrc
Specifies the y-coordinate, in logical units, of the upper-left corner of the source rectangle.
nWidth
Specifies the width, in logical units, of the source rectangle.
nHeight
Specifies the height, in logical units, of the source rectangle.
hbmMask
Handle to an optional monochrome bitmap that is used to mask the colors of the source rectangle.
xMask
Specifies the x-coordinate of the upper-left corner of the the monochrome bitmap.
yMask
Specifies the y-coordinate of the upper-left corner of the the monochrome bitmap.
Return Values
If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero.

Windows NT: To get extended error information, callGetLastError.

Remarks
The fourth vertex of the parallelogram (D) is defined by treating the first three points (A, B, and C) as vectors and computing D = B + C – A.

If the bitmask exists, a value of 1 in the mask indicates that the source pixel color should be copied to the destination. A value of 0 in the mask indicates that the destination pixel color is not to be changed.

If the mask rectangle is smaller than the source and destination rectangles, the function replicates the mask pattern.

Scaling, translation, and reflection transformations are allowed in the source device context; however, rotation and shear transformations are not.

If the mask bitmap is not a monochrome bitmap, an error occurs.

The stretching mode for the destination device context is used to determine how to stretch or compress the pixels, if that is necessary.

When an enhanced metafile is being recorded, an error occurs if the source device context identifies an enhanced-metafile device context.

The destination coordinates are transformed according to the destination device context; the source coordinates are transformed according to the source device context. If the source transformation has a rotation or shear, an error is returned.

If the destination and source rectangles do not have the same color format, PlgBlt converts the source rectangle to match the destination rectangle.

Not all devices support the PlgBlt function. For more information, see the description of the RC_BITBLT raster capability in the GetDeviceCaps function.

If the source and destination device contexts represent incompatible devices, PlgBlt returns an error.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Unsupported.
Windows CE: Unsupported.
Header: Declared in wingdi.h.
Import Library: Use gdi32.lib.

GM прав, я хотел об этом сначала написать, но не стал - подумал, что уж не в этом проблема... :roll:

Keen
Обычный пользователь
Обычный пользователь
 
Сообщения: 83
Зарегистрирован: 25.04.2004 (Вс) 10:45
Откуда: Россия => Москва

Сообщение Keen » 21.07.2004 (Ср) 11:52

Да нет A.A.Z., когда я писал тему, просто перепутал порядок. Действительно, не в этом уж дело.
Может я уже надоел, однако почему BLT'ы не рисуют на picturebox, если autoredraw=true? Как этого избежать (само собой, чтобы autoredraw было как true)?


Вернуться в Visual Basic 1–6

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 17

    TopList